所有 LangChain 与 Google Cloud、Google Gemini 以及其他 Google 产品的集成。
- Google Generative AI (Gemini API 与 AI Studio): 通过 Gemini API 直接访问 Google Gemini 模型。使用 Google AI Studio 进行快速原型设计并使用
langchain-google-genai包快速入门。对于个人开发者来说,这通常是最佳起点。 - Google Cloud (Vertex AI 与其他服务): 通过 Google Cloud Platform 访问 Gemini 模型、Vertex AI 模型库 (Model Garden) 以及各种云服务(数据库、存储、文档 AI 等)。使用
langchain-google-vertexai包处理 Vertex AI 模型,并使用特定包(例如langchain-google-cloud-sql-pg、langchain-google-community)处理其他云服务。这对于已经使用 Google Cloud 或需要 MLOps、特定模型调优或企业支持等企业级功能的开发者来说是理想选择。
有关差异的更多详细信息,请参阅 Google 关于**从 Gemini API 迁移到 Vertex AI** 的指南。
用于 Gemini 模型和 Vertex AI 平台的集成包在 langchain-google 仓库中维护。您可以在 googleapis Github 组织和 langchain-google-community 包中找到大量与其他 Google API 和服务的 LangChain 集成。
Google Generative AI (Gemini API 与 AI Studio)
直接使用 Gemini API 访问 Google Gemini 模型,最适合快速开发和实验。Gemini 模型可在 Google AI Studio 中使用。
pip install -U langchain-google-genaiuv add langchain-google-genai从 Google AI Studio 免费开始并获取您的 API 密钥。
export GOOGLE_API_KEY="YOUR_API_KEY"聊天模型
使用 ChatGoogleGenerativeAI 类与 Gemini 模型进行交互。请参阅本指南中的详细信息。
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.messages import HumanMessage
llm = ChatGoogleGenerativeAI(model="gemini-2.5-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 对象。
嵌入模型
使用 GoogleGenerativeAIEmbeddings 类生成文本嵌入,模型如 gemini-embedding-001。
请参阅使用示例。
from langchain_google_genai import GoogleGenerativeAIEmbeddings
embeddings = GoogleGenerativeAIEmbeddings(model="models/gemini-embedding-001")
vector = embeddings.embed_query("What are embeddings?")
print(vector[:5])LLMs (大型语言模型)
使用 GoogleGenerativeAI 类通过(遗留的)LLM 接口访问相同的 Gemini 模型。
请参阅使用示例。
from langchain_google_genai import GoogleGenerativeAI
llm = GoogleGenerativeAI(model="gemini-2.5-flash")
result = llm.invoke("Sing a ballad of LangChain.")
print(result)Google Cloud
通过 Vertex AI 和特定的云集成,访问 Gemini 模型、Vertex AI 模型库以及其他 Google Cloud 服务。
Vertex AI 模型需要 langchain-google-vertexai 包。其他服务可能需要额外的包,如 langchain-google-community、langchain-google-cloud-sql-pg 等。
pip install langchain-google-vertexai
# pip install langchain-google-community[...] # For other services (对于其他服务)uv add langchain-google-vertexai
# uv add langchain-google-community[...] # For other services (对于其他服务)Google Cloud 集成通常使用应用程序默认凭证 (Application Default Credentials, ADC)。请参阅 Google Cloud 身份验证文档以获取设置说明(例如,使用 gcloud auth application-default login)。
聊天模型
Vertex AI
通过 Vertex AI 平台访问 Gemini 等聊天模型。
请参阅使用示例。
from langchain_google_vertexai import ChatVertexAIAnthropic on Vertex AI Model Garden (Vertex AI 模型库上的 Anthropic)
请参阅使用示例。
from langchain_google_vertexai.model_garden import ChatAnthropicVertexLlama on Vertex AI Model Garden (Vertex AI 模型库上的 Llama)
from langchain_google_vertexai.model_garden_maas.llama import VertexModelGardenLlamaMistral on Vertex AI Model Garden (Vertex AI 模型库上的 Mistral)
from langchain_google_vertexai.model_garden_maas.mistral import VertexModelGardenMistralGemma local from Hugging Face (来自 Hugging Face 的本地 Gemma)
从 HuggingFace 加载的本地 Gemma 模型。需要
langchain-google-vertexai。
from langchain_google_vertexai.gemma import GemmaChatLocalHFGemma local from Kaggle (来自 Kaggle 的本地 Gemma)
从 Kaggle 加载的本地 Gemma 模型。需要
langchain-google-vertexai。
from langchain_google_vertexai.gemma import GemmaChatLocalKaggleGemma on Vertex AI Model Garden (Vertex AI 模型库上的 Gemma)
需要
langchain-google-vertexai。
from langchain_google_vertexai.gemma import GemmaChatVertexAIModelGardenVertex AI image captioning (Vertex AI 图像字幕生成)
图像字幕生成模型作为聊天的实现。需要
langchain-google-vertexai。
from langchain_google_vertexai.vision_models import VertexAIImageCaptioningChatVertex AI image editor (Vertex AI 图像编辑器)
给定图像和提示,编辑图像。目前仅支持无遮罩编辑。需要
langchain-google-vertexai。
from langchain_google_vertexai.vision_models import VertexAIImageEditorChatVertex AI image generator (Vertex AI 图像生成器)
从提示生成图像。需要
langchain-google-vertexai。
from langchain_google_vertexai.vision_models import VertexAIImageGeneratorChatVertex AI visual QnA (Vertex AI 视觉问答)
视觉问答模型的聊天实现。需要
langchain-google-vertexai。
from langchain_google_vertexai.vision_models import VertexAIVisualQnAChatLLMs
您还可以使用(遗留的)字符串输入、字符串输出的 LLM 接口。
Vertex AI Model Garden (Vertex AI 模型库)
通过 Vertex AI Model Garden 服务访问 Gemini 和数百个 OSS 模型。需要 langchain-google-vertexai。
请参阅使用示例。
from langchain_google_vertexai import VertexAIModelGardenGemma local from Hugging Face (来自 Hugging Face 的本地 Gemma)
从 HuggingFace 加载的本地 Gemma 模型。需要
langchain-google-vertexai。
from langchain_google_vertexai.gemma import GemmaLocalHFGemma local from Kaggle (来自 Kaggle 的本地 Gemma)
从 Kaggle 加载的本地 Gemma 模型。需要
langchain-google-vertexai。
from langchain_google_vertexai.gemma import GemmaLocalKaggleGemma on Vertex AI Model Garden (Vertex AI 模型库上的 Gemma)
需要
langchain-google-vertexai。
from langchain_google_vertexai.gemma import GemmaVertexAIModelGardenVertex AI image captioning (Vertex AI 图像字幕生成)
图像字幕生成模型作为 LLM 的实现。需要
langchain-google-vertexai。
from langchain_google_vertexai.vision_models import VertexAIImageCaptioning嵌入模型
Vertex AI
使用部署在 Vertex AI 上的模型生成嵌入。需要 langchain-google-vertexai。
请参阅使用示例。
from langchain_google_vertexai import VertexAIEmbeddings文档加载器
从各种 Google Cloud 来源加载文档。
AlloyDB for PostgreSQL
Google Cloud AlloyDB 是一个完全托管的 PostgreSQL 兼容数据库服务。
安装 Python 包:
pip install langchain-google-alloydb-pguv add langchain-google-alloydb-pg请参阅使用示例。
from langchain_google_alloydb_pg import AlloyDBLoader # AlloyDBEngine 也可用BigQuery
Google Cloud BigQuery 是一个无服务器数据仓库。
使用 BigQuery 依赖项进行安装:
pip install langchain-google-community[bigquery]uv add langchain-google-community[bigquery]请参阅使用示例。
from langchain_google_community import BigQueryLoaderBigtable
Google Cloud Bigtable 是一个完全托管的 NoSQL 大数据数据库服务。
安装 Python 包:
pip install langchain-google-bigtableuv add langchain-google-bigtable请参阅使用示例。
from langchain_google_bigtable import BigtableLoaderCloud SQL for MySQL
Google Cloud SQL for MySQL 是一个完全托管的 MySQL 数据库服务。
安装 Python 包:
pip install langchain-google-cloud-sql-mysqluv add 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-mssqluv add 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-pguv add 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]uv add langchain-google-community[gcs]从目录或特定文件加载:
请参阅目录使用示例。
from langchain_google_community import GCSDirectoryLoader请参阅文件使用示例。
from langchain_google_community import GCSFileLoaderCloud Vision loader (Cloud Vision 加载器)
使用 Google Cloud Vision API 加载数据。
使用 Vision 依赖项进行安装:
pip install langchain-google-community[vision]uv add langchain-google-community[vision]from langchain_google_community.vision import CloudVisionLoaderEl Carro for Oracle Workloads (用于 Oracle 工作负载的 El Carro)
Google El Carro Oracle Operator 在 Kubernetes 中运行 Oracle 数据库。
安装 Python 包:
pip install langchain-google-el-carrouv add langchain-google-el-carro请参阅使用示例。
from langchain_google_el_carro import ElCarroLoaderFirestore (Native Mode) (Firestore - 原生模式)
Google Cloud Firestore 是一个 NoSQL 文档数据库。
安装 Python 包:
pip install langchain-google-firestoreuv add langchain-google-firestore请参阅使用示例。
from langchain_google_firestore import FirestoreLoaderFirestore (Datastore Mode) (Firestore - Datastore 模式)
安装 Python 包:
pip install langchain-google-datastoreuv add langchain-google-datastore请参阅使用示例。
from langchain_google_datastore import DatastoreLoaderMemorystore for Redis
Google Cloud Memorystore for Redis 是一个完全托管的 Redis 服务。
安装 Python 包:
pip install langchain-google-memorystore-redisuv add langchain-google-memorystore-redis请参阅使用示例。
from langchain_google_memorystore_redis import MemorystoreDocumentLoaderSpanner
Google Cloud Spanner 是一个完全托管的、全球分布式的关系数据库服务。
安装 Python 包:
pip install langchain-google-spanneruv add 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]uv add langchain-google-community[speech]请参阅使用示例和授权说明。
from langchain_google_community import SpeechToTextLoader文档转换器 (Document Transformers)
使用 Google Cloud 服务转换文档。
Document AI
Google Cloud Document AI 是一项 Google Cloud 服务,可将文档中的非结构化数据转换为结构化数据,使其更易于理解、分析和使用。
我们需要设置一个 GCS 存储桶并创建您自己的 OCR 处理器。GCS_OUTPUT_PATH 应该是一个 GCS 上的文件夹路径(以 gs:// 开头),
并且处理器名称应类似于 projects/PROJECT_NUMBER/locations/LOCATION/processors/PROCESSOR_ID。
我们可以通过编程方式获取它,或者从 Google Cloud Console 中“Processor details”选项卡的“Prediction endpoint”部分复制。
pip install langchain-google-community[docai]uv add langchain-google-community[docai]请参阅使用示例。
from langchain_core.document_loaders.blob_loaders import Blob
from langchain_google_community import DocAIParserGoogle Translate
Google Translate (谷歌翻译) 是 Google 开发的多语言神经机器翻译服务,用于将文本、文档和网站从一种语言翻译成另一种语言。
GoogleTranslateTransformer 允许您使用 Google Cloud Translation API 翻译文本和 HTML。
首先,我们需要安装带有翻译依赖项的 langchain-google-community。
pip install langchain-google-community[translate]uv add 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 100% 兼容 PostgreSQL。
安装 Python 包:
pip install langchain-google-alloydb-pguv add langchain-google-alloydb-pg请参阅使用示例。
from langchain_google_alloydb_pg import AlloyDBVectorStore # AlloyDBEngine 也可用BigQuery Vector Search
Google Cloud BigQuery,
BigQuery 是 Google Cloud 中一个无服务器、经济高效的企业数据仓库。Google Cloud BigQuery Vector Search
BigQuery 向量搜索允许您使用 GoogleSQL 进行语义搜索,使用向量索引实现快速但近似的结果,或使用暴力搜索实现精确结果。
它可以计算欧几里得距离或余弦距离。在 LangChain 中,我们默认使用欧几里得距离。
我们需要安装几个 Python 包。
pip install google-cloud-bigqueryuv add google-cloud-bigquery请参阅使用示例。
# 注意:BigQueryVectorSearch 可能在 langchain 或 langchain_community 中,具体取决于版本
# 请检查使用示例中的导入。
from langchain.vectorstores import BigQueryVectorSearch # 或 langchain_community.vectorstoresMemorystore for Redis
使用 Memorystore for Redis 的向量存储。
安装 Python 包:
pip install langchain-google-memorystore-redisuv add langchain-google-memorystore-redis请参阅使用示例。
from langchain_google_memorystore_redis import RedisVectorStoreSpanner
使用 Cloud Spanner 的向量存储。
安装 Python 包:
pip install langchain-google-spanneruv add langchain-google-spanner请参阅使用示例。
from langchain_google_spanner import SpannerVectorStoreFirestore (Native Mode) (Firestore - 原生模式)
使用 Firestore 的向量存储。
安装 Python 包:
pip install langchain-google-firestoreuv add langchain-google-firestore请参阅使用示例。
from langchain_google_firestore import FirestoreVectorStoreCloud SQL for MySQL
使用 Cloud SQL for MySQL 的向量存储。
安装 Python 包:
pip install langchain-google-cloud-sql-mysqluv add 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-pguv add langchain-google-cloud-sql-pg请参阅使用示例。
from langchain_google_cloud_sql_pg import PostgresVectorStore # PostgresEngine 也可用Vertex AI Vector Search
Google Cloud Vertex AI Vector Search 来自 Google Cloud,
前身称为Vertex AI Matching Engine,提供了业界领先的高规模、低延迟的向量数据库。这些向量数据库通常被称为向量相似性匹配或近似最近邻 (ANN) 服务。
安装 Python 包:
pip install langchain-google-vertexaiuv add langchain-google-vertexai请参阅使用示例。
from langchain_google_vertexai import VectorSearchVectorStoreWith DataStore Backend (使用 Datastore 后端)
使用 Datastore 进行文档存储的向量搜索。
请参阅使用示例。
from langchain_google_vertexai import VectorSearchVectorStoreDatastoreWith GCS Backend (使用 GCS 后端)
VectorSearchVectorStore的别名,用于将文档/索引存储在 GCS 中。
from langchain_google_vertexai import VectorSearchVectorStoreGCS检索器 (Retrievers)
使用 Google Cloud 服务检索信息。
Vertex AI Search
使用 Vertex AI Search 构建由生成式 AI 驱动的搜索引擎。
Google Cloud 的此服务允许开发者快速为客户和员工构建由生成式 AI 驱动的搜索引擎。
请参阅使用示例。
注意:GoogleVertexAISearchRetriever 已弃用。请使用下方来自 langchain-google-community 的组件。
安装 google-cloud-discoveryengine 包以进行底层访问。
pip install google-cloud-discoveryengine langchain-google-communityuv add google-cloud-discoveryengine langchain-google-communityVertexAIMultiTurnSearchRetriever (Vertex AI 多轮搜索检索器)
from langchain_google_community import VertexAIMultiTurnSearchRetrieverVertexAISearchRetriever (Vertex AI 搜索检索器)
# 注意:示例代码显示的是 VertexAIMultiTurnSearchRetriever,请确认 VertexAISearchRetriever 是否单独存在或相关。
# 假设它可能相关或原文档中存在错字:
from langchain_google_community import VertexAISearchRetriever # 如有需要,请验证类名VertexAISearchSummaryTool (Vertex AI 搜索摘要工具)
from langchain_google_community import VertexAISearchSummaryToolDocument AI Warehouse
使用 Document AI Warehouse 搜索、存储和管理文档。
注意:GoogleDocumentAIWarehouseRetriever(来自 langchain)已弃用。请使用来自 langchain-google-community 的 DocumentAIWarehouseRetriever。
需要安装相关的 Document AI 包(请查阅具体文档)。
pip install langchain-google-community # 如果需要,请添加特定的 docai 依赖项uv add langchain-google-community # 如果需要,请添加特定的 docai 依赖项from langchain_google_community.documentai_warehouse import DocumentAIWarehouseRetriever工具 (Tools)
将智能体 (agents) 与各种 Google 服务集成。
Text-to-Speech (文本转语音)
Google Cloud Text-to-Speech 是一项 Google Cloud 服务,使开发者能够合成具有 100 多种语音、多种语言和变体的自然语音。它应用了 DeepMind 在 WaveNet 方面的突破性研究和 Google 强大的神经网络,以提供最高的保真度。
安装所需的包:
pip install google-cloud-text-to-speech langchain-google-communityuv add google-cloud-text-to-speech langchain-google-community请参阅使用示例和授权说明。
from langchain_google_community import TextToSpeechToolGoogle Drive
用于与 Google Drive 交互的工具。
安装所需的包:
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledriveuv add 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 GoogleDriveSearchToolGoogle Finance (谷歌财经)
查询财务数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add google-search-results langchain-community # 需要 langchain-community请参阅使用示例和授权说明。
from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapperGoogle Jobs (谷歌职位)
查询职位列表。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add 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-communityuv add google-search-results langchain-community # 需要 langchain-community请参阅使用示例和授权说明。
from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapperGoogle Places (谷歌地点)
搜索地点信息。需要 googlemaps 包和 Google Maps API 密钥。
pip install googlemaps langchain # 需要基础 langchainuv add googlemaps langchain # 需要基础 langchain请参阅使用示例和授权说明。
# 注意:GooglePlacesTool 可能在 langchain 或 langchain_community 中,具体取决于版本
from langchain.tools import GooglePlacesTool # 或 langchain_community.toolsGoogle Scholar (谷歌学术)
搜索学术论文。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add google-search-results langchain-community # 需要 langchain-community请参阅使用示例和授权说明。
from langchain_community.tools.google_scholar import GoogleScholarQueryRun
from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapperGoogle Search (谷歌搜索)
使用 Google Custom Search Engine (CSE) 执行网络搜索。需要 GOOGLE_API_KEY 和 GOOGLE_CSE_ID。
安装 langchain-google-community:
pip install langchain-google-communityuv add langchain-google-community封装器 (Wrapper):
from langchain_google_community import GoogleSearchAPIWrapper工具:
from langchain_community.tools import GoogleSearchRun, GoogleSearchResults智能体加载 (Agent Loading):
from langchain_community.agent_toolkits.load_tools import load_tools
tools = load_tools(["google-search"])请参阅详细笔记本。
Google Trends (谷歌趋势)
查询 Google Trends 数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add 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]uv add 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 GmailSendMessageMCP Toolbox
MCP Toolbox 提供了一种简单高效的方式来连接您的数据库,包括 Google Cloud 上的数据库,如 Cloud SQL 和 AlloyDB。借助 MCP Toolbox,您可以将数据库与 LangChain 无缝集成,以构建功能强大的数据驱动应用程序。
安装
配置一个 tools.yaml 来定义您的工具,然后执行 toolbox 来启动服务器:
toolbox --tools-file "tools.yaml"然后,安装 Toolbox 客户端:
pip install toolbox-langchainuv add toolbox-langchain快速入门
这是一个关于如何使用 MCP Toolbox 连接到数据库的简单示例:
from toolbox_langchain import ToolboxClient
async with ToolboxClient("http://127.0.0.1:5000") as client:
tools = client.load_toolset()请参阅使用示例和设置说明。
回调 (Callbacks)
跟踪 LLM/聊天模型的使用情况。
Vertex AI 回调处理器 (Vertex AI callback handler)
跟踪
VertexAI使用信息的回调处理器。
需要 langchain-google-vertexai。
from langchain_google_vertexai.callbacks import VertexAICallbackHandler评估器 (Evaluators)
使用 Vertex AI 评估模型输出。
需要 langchain-google-vertexai。
VertexPairWiseStringEvaluator (Vertex 对偶字符串评估器)
使用 Vertex AI 模型进行对偶评估。
from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluatorVertexStringEvaluator (Vertex 字符串评估器)
使用 Vertex AI 模型评估单个预测字符串。
# 注意:原始文档将 VertexPairWiseStringEvaluator 列出了两次。假设此类别存在。
from langchain_google_vertexai.evaluators.evaluation import VertexStringEvaluator # 如有需要,请验证类名其他 Google 产品 (Other Google Products)
核心云平台之外的各种 Google 服务集成。
文档加载器 (Document loaders)
Google Drive
Google Drive (谷歌云端硬盘) 文件存储。目前支持 Google Docs。
安装 Drive 依赖项:
pip install langchain-google-community[drive]uv add langchain-google-community[drive]请参阅使用示例和授权说明。
from langchain_google_community import GoogleDriveLoader向量存储 (Vector Stores)
ScaNN (本地索引)
Google ScaNN
(Scalable Nearest Neighbors - 可扩展最近邻) 是一个 Python 包。
ScaNN是一种高效进行大规模向量相似性搜索的方法。
ScaNN包括用于最大内积搜索 (Maximum Inner Product Search) 的搜索空间修剪和量化,并且还支持欧几里得距离等其他距离函数。该实现针对支持 AVX2 的 x86 处理器进行了优化。有关更多详细信息,请参阅其 Google Research github。
安装 scann 包:
pip install scann langchain-community # 需要 langchain-communityuv add scann langchain-community # 需要 langchain-community请参阅使用示例。
from langchain_community.vectorstores import ScaNN检索器 (Retrievers)
Google Drive
从 Google Drive 检索文档。
安装所需的包:
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledriveuv add 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-googledriveuv add 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 GoogleDriveSearchToolGoogle Finance (谷歌财经)
查询财务数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add google-search-results langchain-community # 需要 langchain-community请参阅使用示例和授权说明。
from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapperGoogle Jobs (谷歌职位)
查询职位列表。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add 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-communityuv add google-search-results langchain-community # 需要 langchain-community请参阅使用示例和授权说明。
from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapperGoogle Places (谷歌地点)
搜索地点信息。需要 googlemaps 包和 Google Maps API 密钥。
pip install googlemaps langchain # 需要基础 langchainuv add googlemaps langchain # 需要基础 langchain请参阅使用示例和授权说明。
# 注意:GooglePlacesTool 可能在 langchain 或 langchain_community 中,具体取决于版本
from langchain.tools import GooglePlacesTool # 或 langchain_community.toolsGoogle Scholar (谷歌学术)
搜索学术论文。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add google-search-results langchain-community # 需要 langchain-community请参阅使用示例和授权说明。
from langchain_community.tools.google_scholar import GoogleScholarQueryRun
from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapperGoogle Search (谷歌搜索)
使用 Google Custom Search Engine (CSE) 执行网络搜索。需要 GOOGLE_API_KEY 和 GOOGLE_CSE_ID。
安装 langchain-google-community:
pip install langchain-google-communityuv add langchain-google-community封装器 (Wrapper):
from langchain_google_community import GoogleSearchAPIWrapper工具:
from langchain_community.tools import GoogleSearchRun, GoogleSearchResults智能体加载 (Agent Loading):
from langchain_community.agent_toolkits.load_tools import load_tools
tools = load_tools(["google-search"])请参阅详细笔记本。
Google Trends (谷歌趋势)
查询 Google Trends 数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # 需要 langchain-communityuv add 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]uv add 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]uv add langchain-google-community[gmail]请参阅使用示例和授权说明。
from langchain_google_community import GMailLoader第三方集成 (3rd Party Integrations)
通过第三方 API 访问 Google 服务。
SearchApi
SearchApi 提供对 Google 搜索、YouTube 等的 API 访问。需要
langchain-community。
请参阅使用示例和授权说明。
from langchain_community.utilities import SearchApiAPIWrapperSerpApi
SerpApi 提供对 Google 搜索结果的 API 访问。需要
langchain-community。
请参阅使用示例和授权说明。
from langchain_community.utilities import SerpAPIWrapperSerper.dev
Google Serper 提供对 Google 搜索结果的 API 访问。需要
langchain-community。
请参阅使用示例和授权说明。
from langchain_community.utilities import GoogleSerperAPIWrapperYouTube
YouTube Search Tool (YouTube 搜索工具)
无需官方 API 即可搜索 YouTube 视频。需要
Youtube包。
pip install youtube_search langchain # 需要基础 langchainuv add youtube_search langchain # 需要基础 langchain请参阅使用示例。
# 注意:YouTubeSearchTool 可能在 langchain 或 langchain_community 中
from langchain.tools import YouTubeSearchTool # 或 langchain_community.toolsYouTube Audio Loader (YouTube 音频加载器)
下载 YouTube 视频中的音频。需要 yt_dlp、pydub、librosa。
pip install yt_dlp pydub librosa langchain-community # 需要 langchain-communityuv add 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, OpenAIWhisperParserLocalYouTube Transcripts Loader (YouTube 字幕加载器)
加载视频字幕。需要 youtube-transcript-api。
pip install youtube-transcript-api langchain-community # 需要 langchain-communityuv add youtube-transcript-api langchain-community # 需要 langchain-community请参阅使用示例。
from langchain_community.document_loaders import YoutubeLoader