Skip to main content
Open on GitHub

Google

所有与 Google CloudGoogle Gemini 及其他 Google 产品相关的功能。

  1. Google 生成式 AI (Gemini API & AI Studio):通过 Gemini API 直接访问 Google Gemini 模型。使用 Google AI Studio 进行快速原型设计,并通过 langchain-google-genai 包快速上手。这通常是个人开发者的最佳起点。
  2. Google Cloud (Vertex AI 及其他服务):通过 Google Cloud Platform 访问 Gemini 模型、Vertex AI Model Garden 以及各种云服务(数据库、存储、文档 AI 等)。使用 langchain-google-vertexai 包来获取 Vertex AI 模型,以及特定包(例如 langchain-google-cloud-sql-pglangchain-google-community)来获取其他云服务。这非常适合已在使用 Google Cloud 或需要企业级功能(如 MLOps、特定模型微调或企业支持)的开发者。

有关更多差异信息,请参阅 Google 关于从 Gemini API 迁移到 Vertex AI 的指南

Gemini 模型和 Vertex AI 平台的集成包维护在 langchain-google 仓库中。 您可以在 googleapis GitHub 组织和 langchain-google-community 包中找到 LangChain 与其他 Google API 和服务的集成。

Google 生成式 AI (Gemini API & AI Studio)

使用 Gemini API 直接访问 Google Gemini 模型,最适合快速开发和实验。Gemini 模型可在 Google AI Studio 中找到。

pip install -U langchain-google-genai

免费开始使用,并从 Google AI Studio 获取您的 API 密钥。

export GOOGLE_API_KEY="YOUR_API_KEY"

Chat Models

使用 ChatGoogleGenerativeAI 类与 Gemini 2.0 和 2.5 模型进行交互。详情请参阅 本指南

from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.messages import HumanMessage

llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash")

# 简单的文本调用
result = llm.invoke("Sing a ballad of LangChain.")
print(result.content)

# 使用 gemini-pro-vision 进行多模态调用
message = HumanMessage(
content=[
{
"type": "text",
"text": "What's in this image?",
},
{"type": "image_url", "image_url": "https://picsum.photos/seed/picsum/200/300"},
]
)
result = llm.invoke([message])
print(result.content)

image_url 可以是公共 URL、GCS URI(gs://...)、本地文件路径、base64 编码的图像字符串(data:image/png;base64,...)或 PIL Image 对象。

Embedding Models

使用 GoogleGenerativeAIEmbeddings 类生成文本嵌入,例如使用 gemini-embedding-exp-03-07 模型。

请参阅用法示例

from langchain_google_genai import GoogleGenerativeAIEmbeddings

embeddings = GoogleGenerativeAIEmbeddings(model="models/gemini-embedding-exp-03-07")
vector = embeddings.embed_query("What are embeddings?")
print(vector[:5])

LLMs

使用 (旧版) LLM 接口和 GoogleGenerativeAI 类来访问相同的 Gemini 模型。

请参阅用法示例

from langchain_google_genai import GoogleGenerativeAI

llm = GoogleGenerativeAI(model="gemini-2.0-flash")
result = llm.invoke("Sing a ballad of LangChain.")
print(result)
API Reference:GoogleGenerativeAI

Google Cloud

通过 Vertex AI 和特定的云集成访问 Gemini 模型、Vertex AI Model Garden 及其他 Google Cloud 服务。

Vertex AI 模型需要 langchain-google-vertexai 包。其他服务可能需要额外的包,如 langchain-google-communitylangchain-google-cloud-sql-pg 等。

pip install langchain-google-vertexai
# pip install langchain-google-community[...] # 适用于其他服务

Google Cloud 集成通常使用 Application Default Credentials (ADC)。有关设置说明(例如,使用 gcloud auth application-default login),请参阅Google Cloud 身份验证文档

Chat Models

Vertex AI

通过 Vertex AI 平台访问 Gemini 等聊天模型。

请参阅用法示例

from langchain_google_vertexai import ChatVertexAI
API Reference:ChatVertexAI

Vertex AI Model Garden 中的 Anthropic 模型

请参阅用法示例

from langchain_google_vertexai.model_garden import ChatAnthropicVertex
API Reference:ChatAnthropicVertex

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

Hugging Face 的本地 Gemma 模型

HuggingFace 加载的本地 Gemma 模型。需要 langchain-google-vertexai

from langchain_google_vertexai.gemma import GemmaChatLocalHF
API Reference:GemmaChatLocalHF

Kaggle 的本地 Gemma 模型

Kaggle 加载的本地 Gemma 模型。需要 langchain-google-vertexai

from langchain_google_vertexai.gemma import GemmaChatLocalKaggle
API Reference:GemmaChatLocalKaggle

Vertex AI Model Garden 中的 Gemma 模型

需要 langchain-google-vertexai

from langchain_google_vertexai.gemma import GemmaChatVertexAIModelGarden

Vertex AI 图像字幕生成

Image Captioning model 实现为聊天模型。需要 langchain-google-vertexai

from langchain_google_vertexai.vision_models import VertexAIImageCaptioningChat

Vertex AI 图像编辑器

给定图像和提示,编辑图像。目前仅支持无遮罩编辑。需要 langchain-google-vertexai

from langchain_google_vertexai.vision_models import VertexAIImageEditorChat

Vertex AI 图像生成器

根据提示生成图像。需要 langchain-google-vertexai

from langchain_google_vertexai.vision_models import VertexAIImageGeneratorChat

Vertex AI 视觉问答

视觉问答模型的聊天实现。需要 langchain-google-vertexai

from langchain_google_vertexai.vision_models import VertexAIVisualQnAChat
API Reference:VertexAIVisualQnAChat

LLMs

您还可以使用 (旧版) 字符串输入、字符串输出 LLM 接口。

Vertex AI Model Garden

通过 Vertex AI Model Garden 服务访问 Gemini 和数百种 OSS 模型。需要 langchain-google-vertexai

请参阅用法示例

from langchain_google_vertexai import VertexAIModelGarden
API Reference:VertexAIModelGarden

HuggFace 的本地 Gemma 模型

HuggingFace 加载的本地 Gemma 模型。需要 langchain-google-vertexai

from langchain_google_vertexai.gemma import GemmaLocalHF
API Reference:GemmaLocalHF

Kaggle 的本地 Gemma 模型

Kaggle 加载的本地 Gemma 模型。需要 langchain-google-vertexai

from langchain_google_vertexai.gemma import GemmaLocalKaggle
API Reference:GemmaLocalKaggle

Vertex AI Model Garden 中的 Gemma 模型

需要 langchain-google-vertexai

from langchain_google_vertexai.gemma import GemmaVertexAIModelGarden

Vertex AI 图像字幕生成

Image Captioning model 实现为 LLM。需要 langchain-google-vertexai

from langchain_google_vertexai.vision_models import VertexAIImageCaptioning

Embedding Models

Vertex AI

使用部署在 Vertex AI 上的模型生成嵌入。需要 langchain-google-vertexai

请参阅用法示例

from langchain_google_vertexai import VertexAIEmbeddings
API Reference:VertexAIEmbeddings

Document Loaders

从各种 Google Cloud 源加载文档。

AlloyDB for PostgreSQL

Google Cloud AlloyDB 是一个完全托管的、与 PostgreSQL 兼容的数据库服务。

安装 Python 包:

pip install langchain-google-alloydb-pg

请参阅用法示例

from langchain_google_alloydb_pg import AlloyDBLoader # 也提供 AlloyDBEngine

BigQuery

Google Cloud BigQuery 是一个无服务器数据仓库。

使用 BigQuery 依赖项进行安装:

pip install langchain-google-community[bigquery]

请参阅用法示例

from langchain_google_community import BigQueryLoader
API Reference:BigQueryLoader

Bigtable

Google Cloud Bigtable 是一个完全托管的 NoSQL 大数据数据库服务。

安装 Python 包:

pip install langchain-google-bigtable

请参阅用法示例

from langchain_google_bigtable import BigtableLoader

Cloud SQL for MySQL

Google Cloud SQL for MySQL 是一个完全托管的 MySQL 数据库服务。

安装 Python 包:

pip install langchain-google-cloud-sql-mysql

请参阅用法示例

from langchain_google_cloud_sql_mysql import MySQLLoader # 也提供 MySQLEngine

Cloud SQL for SQL Server

Google Cloud SQL for SQL Server 是一个完全托管的 SQL Server 数据库服务。

安装 Python 包:

pip install langchain-google-cloud-sql-mssql

请参阅用法示例

from langchain_google_cloud_sql_mssql import MSSQLLoader # 也提供 MSSQLEngine

Cloud SQL for PostgreSQL

Google Cloud SQL for PostgreSQL 是一个完全托管的 PostgreSQL 数据库服务。

安装 Python 包:

pip install langchain-google-cloud-sql-pg

请参阅用法示例

from langchain_google_cloud_sql_pg import PostgresLoader # 也提供 PostgresEngine

Cloud Storage

Cloud Storage 是一种托管的非结构化数据存储服务。

使用 GCS 依赖项进行安装:

pip install langchain-google-community[gcs]

从目录或特定文件加载:

请参阅目录用法示例

from langchain_google_community import GCSDirectoryLoader
API Reference:GCSDirectoryLoader

请参阅文件用法示例

from langchain_google_community import GCSFileLoader
API Reference:GCSFileLoader

Cloud Vision 加载器

使用 Google Cloud Vision API 加载数据。

使用 Vision 依赖项进行安装:

pip install langchain-google-community[vision]
from langchain_google_community.vision import CloudVisionLoader
API Reference:CloudVisionLoader

El Carro for Oracle Workloads

Google El Carro Oracle Operator 在 Kubernetes 中运行 Oracle 数据库。

安装 Python 包:

pip install langchain-google-el-carro

请参阅用法示例

from langchain_google_el_carro import ElCarroLoader

Firestore (Native Mode)

Google Cloud Firestore 是一个 NoSQL 文档数据库。

安装 Python 包:

pip install langchain-google-firestore

请参阅用法示例

from langchain_google_firestore import FirestoreLoader

Firestore (Datastore Mode)

Google Cloud Firestore in Datastore mode

安装 Python 包:

pip install langchain-google-datastore

请参阅用法示例

from langchain_google_datastore import DatastoreLoader

Memorystore for Redis

Google Cloud Memorystore for Redis 是一个完全托管的 Redis 服务。

安装 Python 包:

pip install langchain-google-memorystore-redis

请参阅用法示例

from langchain_google_memorystore_redis import MemorystoreDocumentLoader

Spanner

Google Cloud Spanner 是一个完全托管的、全球分布式的关系型数据库服务。

安装 Python 包:

pip install langchain-google-spanner

请参阅用法示例

from langchain_google_spanner import SpannerLoader

Speech-to-Text

Google Cloud Speech-to-Text 可转录音频文件。

使用 Speech-to-Text 依赖项进行安装:

pip install langchain-google-community[speech]

请参阅用法示例和授权说明

from langchain_google_community import SpeechToTextLoader
API Reference:SpeechToTextLoader

Document Transformers

使用 Google Cloud 服务转换文档。

Document AI

Google Cloud Document AI 是一个 Google Cloud 服务,可将文档中的非结构化数据转换为结构化数据,使其更易于理解、分析和使用。

我们需要设置一个 GCS 存储桶并创建自己的 OCR processor GCS_OUTPUT_PATH 应该是 GCS 上某个文件夹的路径(以 gs:// 开头), 并且 processor 名称应类似于 projects/PROJECT_NUMBER/locations/LOCATION/processors/PROCESSOR_ID。 我们可以通过编程方式获取它,或者从 Google Cloud Console 的“Processor details” 标签页中的“Prediction endpoint”部分复制。

pip install langchain-google-community[docai]

请参阅用法示例

from langchain_core.document_loaders.blob_loaders import Blob
from langchain_google_community import DocAIParser
API Reference:Blob | DocAIParser

Google Translate

Google Translate 是由 Google 开发的多语言神经机器 翻译服务,用于将文本、文档和网站从一种语言翻译成另一种语言。

GoogleTranslateTransformer 允许您使用 Google Cloud Translation API 翻译文本和 HTML。

首先,我们需要安装带有翻译依赖项的 langchain-google-community

pip install langchain-google-community[translate]

请参阅用法示例和授权说明

from langchain_google_community import GoogleTranslateTransformer

Vector Stores

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

AlloyDB for PostgreSQL

Google Cloud AlloyDB 是一个完全托管的关系型数据库服务,可在 Google Cloud 上提供高性能、无缝集成和卓越的可扩展性。AlloyDB 与 PostgreSQL 100% 兼容。

安装 Python 包:

pip install langchain-google-alloydb-pg

请参阅用法示例

from langchain_google_alloydb_pg import AlloyDBVectorStore # 也提供 AlloyDBEngine

Google Cloud BigQuery, BigQuery 是 Google Cloud 中无服务器且经济高效的企业级数据仓库。

Google Cloud BigQuery Vector Search BigQuery 向量搜索允许您使用 GoogleSQL 进行语义搜索,使用向量索引获取快速但近似的结果,或者使用暴力搜索获取精确结果。

它可以计算欧几里得距离或余弦距离。在 LangChain 中,我们默认使用欧几里得距离。

我们需要安装几个 Python 包。

pip install google-cloud-bigquery

请参阅用法示例

# 注意:BigQueryVectorSearch 可能位于 langchain 或 langchain_community 中,具体取决于版本
# 请检查用法示例中的导入。
from langchain.vectorstores import BigQueryVectorSearch # 或 langchain_community.vectorstores

Memorystore for Redis

使用 Memorystore for Redis 的向量存储。

安装 Python 包:

pip install langchain-google-memorystore-redis

请参阅用法示例

from langchain_google_memorystore_redis import RedisVectorStore

Spanner

使用 Cloud Spanner 的向量存储。

安装 Python 包:

pip install langchain-google-spanner

请参阅用法示例

from langchain_google_spanner import SpannerVectorStore

Firestore (Native Mode)

使用 Firestore 的向量存储。

安装 Python 包:

pip install langchain-google-firestore

请参阅用法示例

from langchain_google_firestore import FirestoreVectorStore

Cloud SQL for MySQL

使用 Cloud SQL for MySQL 的向量存储。

安装 Python 包:

pip install langchain-google-cloud-sql-mysql

请参阅用法示例

from langchain_google_cloud_sql_mysql import MySQLVectorStore # 也提供 MySQLEngine

Cloud SQL for PostgreSQL

使用 Cloud SQL for PostgreSQL 的向量存储。

安装 Python 包:

pip install langchain-google-cloud-sql-pg

请参阅用法示例

from langchain_google_cloud_sql_pg import PostgresVectorStore # 也提供 PostgresEngine

Google Cloud 的 Google Cloud Vertex AI Vector Search 原名 Vertex AI Matching Engine,提供行业领先的高规模、低延迟向量数据库。这些向量数据库通常 被称为向量相似性匹配或近似最近邻 (ANN) 服务。

安装 Python 包:

pip install langchain-google-vertexai

请参阅用法示例

from langchain_google_vertexai import VectorSearchVectorStore
使用 DataStore 后端

使用 Datastore 进行文档存储的向量搜索。

请参阅用法示例

from langchain_google_vertexai import VectorSearchVectorStoreDatastore
使用 GCS 后端

VectorSearchVectorStore 的别名,用于在 GCS 中存储文档/索引。

from langchain_google_vertexai import VectorSearchVectorStoreGCS

Retrievers

使用 Google Cloud 服务检索信息。

使用 Vertex AI Search 构建支持生成式 AI 的搜索引擎。 Google Cloud 使开发者能够快速为客户和员工构建支持生成式 AI 的搜索引擎。

请参阅用法示例

注意:GoogleVertexAISearchRetriever 已弃用。请使用 langchain-google-community 中的以下组件。

安装 google-cloud-discoveryengine 包以进行底层访问。

pip install google-cloud-discoveryengine langchain-google-community
VertexAIMultiTurnSearchRetriever
from langchain_google_community import VertexAIMultiTurnSearchRetriever
VertexAISearchRetriever
# 注意:示例代码显示了 VertexAIMultiTurnSearchRetriever,请确认 VertexAISearchRetriever 是否独立或相关。
# 假设它可能相关或原始内容有误:
from langchain_google_community import VertexAISearchRetriever # 如有需要,请验证类名
VertexAISearchSummaryTool
from langchain_google_community import VertexAISearchSummaryTool

Document AI Warehouse

使用 Document AI Warehouse 搜索、存储和管理文档。

注意:GoogleDocumentAIWarehouseRetriever(来自 langchain)已弃用。请使用 langchain-google-community 中的 DocumentAIWarehouseRetriever

需要安装相关的 Document AI 包(请查看具体文档)。

pip install langchain-google-community # 如有需要,请添加特定的 docai 依赖项
from langchain_google_community.documentai_warehouse import DocumentAIWarehouseRetriever

Tools

将代理与各种 Google 服务集成。

Text-to-Speech

Google Cloud Text-to-Speech 是一个 Google Cloud 服务,它使开发者能够 合成自然语音,拥有 100 多种语音,支持多种语言和变体。 它应用了 DeepMind 在 WaveNet 和 Google 强大的神经网络方面的突破性研究成果,以提供尽可能高的保真度。

安装所需的软件包:

pip install google-cloud-text-to-speech langchain-google-community

请参阅用法示例和授权说明

from langchain_google_community import TextToSpeechTool
API Reference:TextToSpeechTool

Google Drive

用于与 Google Drive 交互的工具。

安装所需的软件包:

pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledrive

请参阅用法示例和授权说明

from langchain_googledrive.utilities.google_drive import GoogleDriveAPIWrapper
from langchain_googledrive.tools.google_drive.tool import GoogleDriveSearchTool

Google Finance

查询金融数据。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

Google Jobs

查询职位列表。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_jobs import GoogleJobsQueryRun
# 注意:实用程序可能是共享的,例如列出了 GoogleFinanceAPIWrapper,请验证正确的实用程序
# from langchain_community.utilities.google_jobs import GoogleJobsAPIWrapper # 如果存在

Google Lens

执行视觉搜索。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapper

Google Places

搜索地点信息。需要 googlemaps 包和 Google Maps API 密钥。

pip install googlemaps langchain # 需要基础 langchain

请参阅用法示例和授权说明

# 注意:GooglePlacesTool 可能位于 langchain 或 langchain_community 中,具体取决于版本
from langchain.tools import GooglePlacesTool # 或 langchain_community.tools
API Reference:GooglePlacesTool

Google Scholar

搜索学术论文。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_scholar import GoogleScholarQueryRun
from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapper

使用 Google 自定义搜索引擎 (CSE) 执行网络搜索。需要 GOOGLE_API_KEYGOOGLE_CSE_ID

安装 langchain-google-community

pip install langchain-google-community

包装器:

from langchain_google_community import GoogleSearchAPIWrapper

工具:

from langchain_community.tools import GoogleSearchRun, GoogleSearchResults

加载代理:

from langchain_community.agent_toolkits.load_tools import load_tools
tools = load_tools(["google-search"])
API Reference:load_tools

请参阅详细的 Notebook

查询 Google Trends 数据。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_trends import GoogleTrendsQueryRun
from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper

Toolkits

用于特定 Google 服务的工具集合。

GMail

Google Gmail 是 Google 提供的免费电子邮件服务。 此工具包通过 Gmail API 处理电子邮件。

pip install langchain-google-community[gmail]

请参阅用法示例和授权说明

# 加载整个工具包
from langchain_google_community import GmailToolkit

# 或使用单个工具
from langchain_google_community.gmail.create_draft import GmailCreateDraft
from langchain_google_community.gmail.get_message import GmailGetMessage
from langchain_google_community.gmail.get_thread import GmailGetThread
from langchain_google_community.gmail.search import GmailSearch
from langchain_google_community.gmail.send_message import GmailSendMessage

Memory

使用 Google Cloud 数据库存储对话历史。

AlloyDB for PostgreSQL

使用 AlloyDB 进行聊天记忆。

安装 Python 包:

pip install langchain-google-alloydb-pg

请参阅用法示例

from langchain_google_alloydb_pg import AlloyDBChatMessageHistory # 也提供 AlloyDBEngine

Cloud SQL for PostgreSQL

使用 Cloud SQL for PostgreSQL 进行聊天记忆。

安装 Python 包:

pip install langchain-google-cloud-sql-pg

请参阅用法示例

from langchain_google_cloud_sql_pg import PostgresChatMessageHistory # 也提供 PostgresEngine

Cloud SQL for MySQL

使用 Cloud SQL for MySQL 进行聊天记忆。

安装 Python 包:

pip install langchain-google-cloud-sql-mysql

请参阅用法示例

from langchain_google_cloud_sql_mysql import MySQLChatMessageHistory # 也提供 MySQLEngine

Cloud SQL for SQL Server

使用 Cloud SQL for SQL Server 进行聊天记忆。

安装 Python 包:

pip install langchain-google-cloud-sql-mssql

请参阅用法示例

from langchain_google_cloud_sql_mssql import MSSQLChatMessageHistory # 也提供 MSSQLEngine

Spanner

使用 Cloud Spanner 进行聊天记忆。

安装 Python 包:

pip install langchain-google-spanner

请参阅用法示例

from langchain_google_spanner import SpannerChatMessageHistory

Memorystore for Redis

使用 Memorystore for Redis 进行聊天记忆。

安装 Python 包:

pip install langchain-google-memorystore-redis

请参阅用法示例

from langchain_google_memorystore_redis import MemorystoreChatMessageHistory

Bigtable

使用 Cloud Bigtable 进行聊天记忆。

安装 Python 包:

pip install langchain-google-bigtable

请参阅用法示例

from langchain_google_bigtable import BigtableChatMessageHistory

Firestore (Native Mode)

使用 Firestore 进行聊天记忆。

安装 Python 包:

pip install langchain-google-firestore

请参阅用法示例

from langchain_google_firestore import FirestoreChatMessageHistory

Firestore (Datastore Mode)

使用 Firestore in Datastore mode 进行聊天记忆。

安装 Python 包:

pip install langchain-google-datastore

请参阅用法示例

from langchain_google_datastore import DatastoreChatMessageHistory

El Carro: The Oracle Operator for Kubernetes

使用通过 El Carro 运行的 Oracle 数据库进行聊天记忆。

安装 Python 包:

pip install langchain-google-el-carro

请参阅用法示例

from langchain_google_el_carro import ElCarroChatMessageHistory

Callbacks

跟踪 LLM/Chat 模型的使用情况。

Vertex AI callback handler

跟踪 VertexAI 使用情况信息的 Callback Handler。

需要 langchain-google-vertexai

from langchain_google_vertexai.callbacks import VertexAICallbackHandler

Evaluators

使用 Vertex AI 评估模型输出。

需要 langchain-google-vertexai

VertexPairWiseStringEvaluator

使用 Vertex AI 模型进行成对评估。

from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluator

VertexStringEvaluator

使用 Vertex AI 模型评估单个预测字符串。

# 注意:原始内容重复列出了 VertexPairWiseStringEvaluator。假定此类存在。
from langchain_google_vertexai.evaluators.evaluation import VertexStringEvaluator # 如有需要,请验证类名
API Reference:VertexStringEvaluator

Other Google Products

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

Document Loaders

Google Drive

Google Drive 文件存储。目前支持 Google Docs

使用 Drive 依赖项进行安装:

pip install langchain-google-community[drive]

请参阅用法示例和授权说明

from langchain_google_community import GoogleDriveLoader
API Reference:GoogleDriveLoader

Vector Stores

ScaNN (Local Index)

Google ScaNN (Scalable Nearest Neighbors) 是一个 Python 包。

ScaNN 是一种用于大规模高效向量相似性搜索的方法。

ScaNN 包括用于最大内积搜索的搜索空间剪枝和量化,并且还支持欧几里得距离等其他距离函数。该实现针对支持 AVX2 的 x86 处理器进行了优化。有关更多详细信息,请参阅其 Google Research github

安装 scann 包:

pip install scann langchain-community # 需要 langchain-community

请参阅用法示例

from langchain_community.vectorstores import ScaNN
API Reference:ScaNN

Retrievers

Google Drive

从 Google Drive 检索文档。

安装所需的软件包:

pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledrive

请参阅用法示例和授权说明

from langchain_googledrive.retrievers import GoogleDriveRetriever

Tools

Google Drive

用于与 Google Drive 交互的工具。

安装所需的软件包:

pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledrive

请参阅用法示例和授权说明

from langchain_googledrive.utilities.google_drive import GoogleDriveAPIWrapper
from langchain_googledrive.tools.google_drive.tool import GoogleDriveSearchTool

Google Finance

查询金融数据。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

Google Jobs

查询职位列表。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_jobs import GoogleJobsQueryRun
# 注意:实用程序可能是共享的,例如列出了 GoogleFinanceAPIWrapper,请验证正确的实用程序
# from langchain_community.utilities.google_jobs import GoogleJobsAPIWrapper # 如果存在

Google Lens

执行视觉搜索。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapper

Google Places

搜索地点信息。需要 googlemaps 包和 Google Maps API 密钥。

pip install googlemaps langchain # 需要基础 langchain

请参阅用法示例和授权说明

# 注意:GooglePlacesTool 可能位于 langchain 或 langchain_community 中,具体取决于版本
from langchain.tools import GooglePlacesTool # 或 langchain_community.tools
API Reference:GooglePlacesTool

Google Scholar

搜索学术论文。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_scholar import GoogleScholarQueryRun
from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapper

Google Search

使用 Google 自定义搜索引擎 (CSE) 执行网络搜索。需要 GOOGLE_API_KEYGOOGLE_CSE_ID

安装 langchain-google-community

pip install langchain-google-community

包装器:

from langchain_google_community import GoogleSearchAPIWrapper

工具:

from langchain_community.tools import GoogleSearchRun, GoogleSearchResults

加载代理:

from langchain_community.agent_toolkits.load_tools import load_tools
tools = load_tools(["google-search"])
API Reference:load_tools

请参阅详细的 Notebook

查询 Google Trends 数据。需要 google-search-results 包和 SerpApi 密钥。

pip install google-search-results langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.tools.google_trends import GoogleTrendsQueryRun
from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper

Toolkits

GMail

Google Gmail 是 Google 提供的免费电子邮件服务。 此工具包通过 Gmail API 处理电子邮件。

pip install langchain-google-community[gmail]

请参阅用法示例和授权说明

# 加载整个工具包
from langchain_google_community import GmailToolkit

# 或使用单个工具
from langchain_google_community.gmail.create_draft import GmailCreateDraft
from langchain_google_community.gmail.get_message import GmailGetMessage
from langchain_google_community.gmail.get_thread import GmailGetThread
from langchain_google_community.gmail.search import GmailSearch
from langchain_google_community.gmail.send_message import GmailSendMessage

Chat Loaders

GMail

从 Gmail 线程加载聊天历史记录。

使用 GMail 依赖项进行安装:

pip install langchain-google-community[gmail]

请参阅用法示例和授权说明

from langchain_google_community import GMailLoader
API Reference:GMailLoader

3rd Party Integrations

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

SearchApi

SearchApi 提供 Google 搜索、YouTube 等的 API 访问。需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.utilities import SearchApiAPIWrapper
API Reference:SearchApiAPIWrapper

SerpApi

SerpApi 提供 Google 搜索结果的 API 访问。需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.utilities import SerpAPIWrapper
API Reference:SerpAPIWrapper

Serper.dev

Google Serper 提供 Google 搜索结果的 API 访问。需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.utilities import GoogleSerperAPIWrapper

YouTube

YouTube Search Tool

在没有官方 API 的情况下搜索 YouTube 视频。需要 youtube_search 包。

pip install youtube_search langchain # 需要基础 langchain

请参阅用法示例

# 注意:YouTubeSearchTool 可能位于 langchain 或 langchain_community
from langchain.tools import YouTubeSearchTool # 或 langchain_community.tools
API Reference:YouTubeSearchTool

YouTube Audio Loader

下载 YouTube 视频的音频。需要 yt_dlppydublibrosa

pip install yt_dlp pydub librosa langchain-community # 需要 langchain-community

请参阅用法示例和授权说明

from langchain_community.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
# 常与 whisper 解析器一起使用:
# from langchain_community.document_loaders.parsers import OpenAIWhisperParser, OpenAIWhisperParserLocal

YouTube Transcripts Loader

加载视频字幕。需要 youtube-transcript-api

pip install youtube-transcript-api langchain-community # 需要 langchain-community

请参阅用法示例

from langchain_community.document_loaders import YoutubeLoader
API Reference:YoutubeLoader