本页涵盖 LangChain 与 Google GeminiGoogle Cloud 以及其他 Google 产品(例如 Google Maps、YouTube 和更多)的所有集成。
统一 SDK 与软件包整合langchain-google-genai 4.0.0 开始,此软件包使用整合后的 google-genai SDK,并且现在同时支持 Gemini Developer API 和 Vertex AI 后端。langchain-google-vertexai 软件包仍然支持 Vertex AI 平台特定功能(Model Garden、Vector Search、评估服务等)。阅读完整公告和迁移指南
不确定该使用哪个软件包?
通过 Gemini Developer APIVertex AI 访问 Google Gemini 模型。后端会根据你的配置自动选择。
  • Gemini Developer API:使用 API 密钥即可快速设置,非常适合个人开发者和快速原型开发
  • Vertex AI:提供与 Google Cloud 集成的企业级功能(需要 GCP 项目)
使用 langchain-google-genai 软件包来处理聊天模型、LLM 和嵌入。查看集成。
访问 Gemini 模型之外的 Vertex AI 平台特定服务:Model Garden(Llama、Mistral、Anthropic)、评估服务以及专用视觉模型。使用 langchain-google-vertexai 软件包来访问平台服务,并使用特定软件包(例如 langchain-google-communitylangchain-google-cloud-sql-pg)来访问数据库和存储等其他云服务。查看集成。
有关差异的更多详细信息,请参阅 Google 关于从 Gemini API 迁移到 Vertex AI 的指南。

Google 生成式 AI

使用统一的 langchain-google-genai 软件包,通过 Gemini Developer APIVertex AI 访问 Google Gemini 模型。

聊天模型

ChatGoogleGenerativeAI

通过 Gemini Developer APIVertex AI 使用 Google Gemini 聊天模型。

LLM

GoogleGenerativeAI

使用(旧版)LLM 文本补全接口的 Gemini 模型。

嵌入模型

GoogleGenerativeAIEmbeddings

通过 Gemini Developer APIVertex AI 使用 Gemini 嵌入模型。

Google Cloud

访问 Vertex AI 平台特定服务,包括 Model Garden(Llama、Mistral、Anthropic)、Vector Search、评估服务和专用视觉模型。
对于 Gemini 模型,请使用 langchain-google-genai 中的 ChatGoogleGenerativeAI。下面的类专注于整合后的 SDK 中不可用的 Vertex AI 平台服务

聊天模型

ChatAnthropicVertex

Vertex AI Model Garden 上的 Anthropic
已弃用——对于 Gemini 模型,请改用 ChatGoogleGenerativeAI
from langchain_google_vertexai import ChatVertexAI
Vertex AI Model Garden 上的 Llama
from langchain_google_vertexai.model_garden_maas.llama import VertexModelGardenLlama
Vertex AI Model Garden 上的 Mistral
from langchain_google_vertexai.model_garden_maas.mistral import VertexModelGardenMistral
从 HuggingFace 加载的本地 Gemma 模型。
from langchain_google_vertexai.gemma import GemmaChatLocalHF
从 Kaggle 加载的本地 Gemma 模型。
from langchain_google_vertexai.gemma import GemmaChatLocalKaggle
Vertex AI Model Garden 上的 Gemma
from langchain_google_vertexai.gemma import GemmaChatVertexAIModelGarden
作为聊天接口的图像描述生成模型。
from langchain_google_vertexai.vision_models import VertexAIImageCaptioningChat
根据提示词编辑图像。目前仅支持无蒙版编辑。
from langchain_google_vertexai.vision_models import VertexAIImageEditorChat
根据提示词生成图像。
from langchain_google_vertexai.vision_models import VertexAIImageGeneratorChat
作为聊天接口的视觉问答模型。
from langchain_google_vertexai.vision_models import VertexAIVisualQnAChat

LLM

(旧版)字符串输入、字符串输出的 LLM 接口。

VertexAIModelGarden

通过 Vertex AI Model Garden 使用数百个 OSS 模型。
已弃用——对于 Gemini 模型,请改用 GoogleGenerativeAI
from langchain_google_vertexai import VertexAI
从 HuggingFace 加载的本地 Gemma 模型。
from langchain_google_vertexai.gemma import GemmaLocalHF
从 Kaggle 加载的本地 Gemma 模型。
from langchain_google_vertexai.gemma import GemmaLocalKaggle
from langchain_google_vertexai.gemma import GemmaVertexAIModelGarden
作为 LLM 接口的图像描述生成模型。
from langchain_google_vertexai.vision_models import VertexAIImageCaptioning

嵌入模型

已弃用——请改用 GoogleGenerativeAIEmbeddings
from langchain_google_vertexai import VertexAIEmbeddings

文档加载器

AlloyDB for PostgreSQL

Google Cloud 上兼容 PostgreSQL 的数据库。

BigQuery

无服务器数据仓库。

Bigtable

用于结构化和半结构化数据的键值与宽列存储。

Cloud SQL for MySQL

托管式 MySQL 数据库。

Cloud SQL for SQL Server

托管式 SQL Server 数据库。

Cloud SQL for PostgreSQL

托管式 PostgreSQL 数据库。

Cloud Storage (directory)

从 GCS 存储桶目录加载文档。

Cloud Storage (file)

从 GCS 加载单个文档。

El Carro for Oracle Workloads

通过 El Carro 在 Kubernetes 上运行 Oracle 数据库。

Firestore (Native Mode)

NoSQL 文档数据库。

Firestore (Datastore Mode)

Datastore 模式下的 Firestore。

Memorystore for Redis

托管式 Redis 服务。

Spanner

全球分布式关系型数据库。

Speech-to-Text

转录音频文件。
使用 Google Cloud Vision API 加载数据。
from langchain_google_community.vision import CloudVisionLoader

文档转换器

Document AI

从非结构化文档中提取结构化数据。

Google Translate

通过 Cloud Translation API 翻译文本和 HTML。

向量存储

使用 Google Cloud 数据库和 Vertex AI Vector Search 存储并搜索向量。

AlloyDB for PostgreSQL

AlloyDB 上兼容 PostgreSQL 的向量存储。

BigQuery Vector Search

使用带有向量索引的 GoogleSQL 进行语义搜索。

Memorystore for Redis

Memorystore for Redis 上的向量存储。

Spanner

Cloud Spanner 上的向量存储。

Bigtable

Cloud Bigtable 上的向量存储。

Firestore (Native Mode)

Firestore 上的向量存储。

Cloud SQL for MySQL

Cloud SQL for MySQL 上的向量存储。

Cloud SQL for PostgreSQL

Cloud SQL for PostgreSQL 上的向量存储。

Vertex AI Vector Search

以前称为 Vertex AI Matching Engine,提供低延迟向量数据库。这类向量数据库通常被称为向量相似度匹配或近似最近邻(ANN)服务。

Vertex AI Vector Search + Datastore

结合 Datastore 进行文档存储的向量搜索。

检索器

Vertex AI Search

通过 Vertex AI Search 使用生成式 AI 驱动的搜索。

Document AI Warehouse

使用 Document AI Warehouse 搜索、存储和管理文档。
Other retrievers
from langchain_google_community import VertexAIMultiTurnSearchRetriever
from langchain_google_community import VertexAISearchRetriever
from langchain_google_community import VertexAISearchSummaryTool

工具

将智能体与各种 Google Cloud 服务集成。

Text-to-Speech

使用 100 多种语音合成自然流畅的语音。

回调

跟踪 LLM/聊天模型的使用情况。
跟踪 VertexAI 使用信息。
from langchain_google_vertexai.callbacks import VertexAICallbackHandler
查看文档了解更多详细信息。
from langchain_google_community.callbacks.bigquery_callback import BigQueryCallbackHandler

评估器

使用 Vertex AI 评估模型输出。
使用 Vertex AI 模型进行成对评估。
from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluator
使用 Vertex AI 模型进行单次预测评估。
from langchain_google_vertexai.evaluators.evaluation import VertexStringEvaluator

其他 Google 产品

与核心 Cloud Platform 之外的各种 Google 服务集成。

文档加载器

Google Drive

从 Google Drive 加载文件。目前支持 Google Docs。

检索器

Google Drive

从 Google Drive 检索文档。

工具

Google Search

通过 Google Custom Search Engine(CSE)进行网页搜索。

Google Drive

与 Google Drive 交互。

MCP

MCP Toolbox

连接到包括 Cloud SQL 和 AlloyDB 在内的数据库。

工具包

Gmail

通过 Gmail API 创建、搜索和发送电子邮件。

第三方集成

通过非官方第三方 API 访问 Google 服务。

搜索

cloro

支持 AI Overview 的 Google 搜索结果。