@langchain/google 包提供了与 Google AI Studio 和 Google Cloud Vertex AI 的集成。
还在使用较旧的
@langchain/google-genai 或 @langchain/google-vertexai 包?它们仍处于长期支持维护状态,但不推荐用于新项目。聊天模型
ChatGoogle 类是访问 Gemini 模型(如 gemini-2.5-pro、gemini-2.5-flash 和 gemini-3.1-pro-preview)以及 Gemma 等开放模型的推荐方式。它通过一个统一接口同时支持 Google AI Studio 和 Vertex AI。
ChatGoogle 支持工具调用、结构化输出、多模态输入(图像、音频、视频)、推理/思考、图像生成、文本转语音,以及 Gemini 专属的原生工具,如 Google 搜索基础验证和代码执行。
ChatGoogle
完整的聊天模型文档,包括设置、调用、流式传输、结构化输出等。
Gemini 原生工具
Google 搜索、代码执行、URL 上下文、Google 地图、文件搜索、计算机使用以及 MCP 服务器。
Vertex AI 上的第三方模型
Anthropic Claude 模型也可通过 Vertex AI 平台使用。有关启用模型访问权限及所需模型名称的更多信息,请参阅在 Vertex AI 上使用 Claude。Postgres 向量存储 (Cloud SQL)
@langchain/google-cloud-sql-pg 包中的 PostgresVectorStore 模块提供了一种使用 Cloud SQL for PostgreSQL 存储向量嵌入的方法。
旧版包
以下包为现有用户提供长期支持。新项目应改用@langchain/google。
@langchain/google-genai
@langchain/google-genai 包提供了 ChatGoogleGenerativeAI 和 GoogleGenerativeAIEmbeddings,用于通过 Google AI Studio 访问 Gemini 模型。此包基于已弃用的 Google SDK,不会获得新功能。
@langchain/google-vertexai
@langchain/google-vertexai 包为 Node.js 上的 Vertex AI 提供了 ChatVertexAI、VertexAIEmbeddings 和 VertexAI。它依赖 @langchain/google-gauth 进行身份验证。对于聊天功能,此包已被 @langchain/google 内置的 Vertex AI 支持所取代。
@langchain/google-vertexai-web
@langchain/google-vertexai-web 包为浏览器和 Edge 运行时提供了相同的 Vertex AI 聊天、嵌入和 LLM 类。在 Web 环境中运行时,请安装此包(而不是 @langchain/google-vertexai)。它依赖 @langchain/google-webauth。
GOOGLE_WEB_CREDENTIALS 和 Web 导入路径,请参阅 Vertex AI 聊天 页面。
@langchain/google-webauth
@langchain/google-webauth 包为旧版 Vertex AI 集成提供了浏览器和 Edge 身份验证。它会随 @langchain/google-vertexai-web 自动安装——请勿将其与 @langchain/google-gauth 一起安装。
在 GOOGLE_WEB_CREDENTIALS(或已弃用的 GOOGLE_VERTEX_AI_WEB_CREDENTIALS)中设置服务账号 JSON。你也可以将 apiKey 或 authOptions 传递给模型构造函数,或设置 API_KEY 环境变量。
@langchain/google-gauth
@langchain/google-gauth 包为基于 @langchain/google-common 构建的旧版 Google 集成提供了 Node.js 身份验证。当你添加 @langchain/google-vertexai 时,它会自动安装——通常你不需要直接安装或导入 @langchain/google-gauth。
在 Node.js 上,凭据按以下顺序解析:
- 传递给模型构造函数的
apiKey - 传递给模型构造函数的
authOptions API_KEY环境变量- 位于
GOOGLE_APPLICATION_CREDENTIALS路径下的服务账号 JSON - 应用程序默认凭据(例如,执行
gcloud auth application-default login后,或在 Google Cloud 上)
@langchain/google-gauth 和 @langchain/google-webauth。
统一的 @langchain/google 包直接使用 google-auth-library,不需要 @langchain/google-gauth 或 @langchain/google-webauth。
@langchain/google-cloud-sql-pg
@langchain/google-cloud-sql-pg 包为 Cloud SQL for PostgreSQL 提供了 PostgresVectorStore 和 PostgresLoader。它与上述 Gemini 聊天包是独立的。
@langchain/google-common
@langchain/google-common 包为诸如 @langchain/google-vertexai 之类的旧版集成提供了共享的 Gemini 客户端抽象。它不包含授权代码,也不是一个独立的包——请勿直接安装或导入。
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

