跳到主要内容
所有 LangChain 与 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 包中找到许多与 Google 其他 API 和服务的 LangChain 集成。

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"

聊天模型

使用 ChatGoogleGenerativeAI 类与 Gemini 模型交互。请参阅此指南中的详细信息。
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.messages import HumanMessage

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

# Simple text invocation
result = llm.invoke("Sing a ballad of LangChain.")
print(result.content)

# Multimodal invocation with 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 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[...] # For other services
Google Cloud 集成通常使用应用程序默认凭据 (ADC)。请参阅 Google Cloud 身份验证文档以获取设置说明(例如,使用 gcloud auth application-default login)。

聊天模型

Vertex AI

通过 Vertex AI 平台访问 Gemini 等聊天模型。 请参阅用法示例
from langchain_google_vertexai import ChatVertexAI

Vertex AI Model Garden 上的 Anthropic

请参阅用法示例
from langchain_google_vertexai.model_garden import 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

来自 Kaggle 的本地 Gemma

从 Kaggle 加载的本地 Gemma 模型。需要 langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaChatLocalKaggle

Vertex AI Model Garden 上的 Gemma

需要 langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaChatVertexAIModelGarden

Vertex AI 图像字幕

将图像字幕模型实现为聊天。需要 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

LLMs

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

Vertex AI Model Garden

通过 Vertex AI Model Garden 服务访问 Gemini 和数百个 OSS 模型。需要 langchain-google-vertexai 请参阅用法示例
from langchain_google_vertexai import VertexAIModelGarden

来自 Hugging Face 的本地 Gemma

从 HuggingFace 加载的本地 Gemma 模型。需要 langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaLocalHF

来自 Kaggle 的本地 Gemma

从 Kaggle 加载的本地 Gemma 模型。需要 langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaLocalKaggle

Vertex AI Model Garden 上的 Gemma

需要 langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaVertexAIModelGarden

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 源加载文档。

适用于 PostgreSQL 的 AlloyDB

Google Cloud AlloyDB 是一个完全托管的 PostgreSQL 兼容数据库服务。
安装 python 包
pip install langchain-google-alloydb-pg
请参阅用法示例
from langchain_google_alloydb_pg import AlloyDBLoader # AlloyDBEngine also available

BigQuery

Google Cloud BigQuery 是一个无服务器数据仓库。
安装 BigQuery 依赖项
pip install langchain-google-community[bigquery]
请参阅用法示例
from langchain_google_community import BigQueryLoader

Bigtable

Google Cloud Bigtable 是一个完全托管的 NoSQL 大数据数据库服务。
安装 python 包
pip install langchain-google-bigtable
请参阅用法示例
from langchain_google_bigtable import BigtableLoader

适用于 MySQL 的 Cloud SQL

Google Cloud SQL for MySQL 是一个完全托管的 MySQL 数据库服务。
安装 python 包
pip install langchain-google-cloud-sql-mysql
请参阅用法示例
from langchain_google_cloud_sql_mysql import MySQLLoader # MySQLEngine also available

适用于 SQL Server 的 Cloud SQL

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 also available

适用于 PostgreSQL 的 Cloud SQL

Google Cloud SQL for PostgreSQL 是一个完全托管的 PostgreSQL 数据库服务。
安装 python 包
pip install langchain-google-cloud-sql-pg
请参阅用法示例
from langchain_google_cloud_sql_pg import PostgresLoader # PostgresEngine also available

Cloud Storage

Cloud Storage 是一种用于存储非结构化数据的托管服务。
安装 GCS 依赖项
pip install langchain-google-community[gcs]
从目录或特定文件加载: 请参阅目录用法示例
from langchain_google_community import GCSDirectoryLoader
请参阅文件用法示例
from langchain_google_community import GCSFileLoader

Cloud Vision 加载器

使用 Google Cloud Vision API 加载数据。 安装 Vision 依赖项:
pip install langchain-google-community[vision]
from langchain_google_community.vision import CloudVisionLoader

用于 Oracle 工作负载的 El Carro

Google El Carro Oracle Operator 在 Kubernetes 中运行 Oracle 数据库。
安装 python 包
pip install langchain-google-el-carro
请参阅用法示例
from langchain_google_el_carro import ElCarroLoader

Firestore (原生模式)

Google Cloud Firestore 是一个 NoSQL 文档数据库。
安装 python 包
pip install langchain-google-firestore
请参阅用法示例
from langchain_google_firestore import FirestoreLoader

Firestore (Datastore 模式)

Datastore 模式下的 Google Cloud Firestore.
安装 python 包
pip install langchain-google-datastore
请参阅用法示例
from langchain_google_datastore import DatastoreLoader

适用于 Redis 的 Memorystore

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

语音转文本

Google Cloud Speech-to-Text 转录音频文件。
安装 Speech-to-Text 依赖项
pip install langchain-google-community[speech]
请参阅用法示例和授权说明
from langchain_google_community import SpeechToTextLoader

文档转换器

使用 Google Cloud 服务转换文档。

文档 AI

Google Cloud Document AI 是一种 Google Cloud 服务,可将文档中的非结构化数据转换为结构化数据,使其更易于理解、分析和使用。
我们需要设置一个 GCS 存储桶并创建自己的 OCR 处理器GCS_OUTPUT_PATH 应该是一个 GCS 上的文件夹路径(以 gs:// 开头),处理器名称应该类似于 projects/PROJECT_NUMBER/locations/LOCATION/processors/PROCESSOR_ID。我们可以通过编程方式获取它,也可以从 Google Cloud 控制台的 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

Google 翻译

Google 翻译是 Google 开发的一种多语言神经网络机器翻译服务,用于将文本、文档和网站从一种语言翻译成另一种语言。
GoogleTranslateTransformer 允许您使用 Google Cloud Translation API 翻译文本和 HTML。 首先,我们需要安装具有翻译依赖项的 langchain-google-community
pip install langchain-google-community[translate]
请参阅用法示例和授权说明
from langchain_google_community import GoogleTranslateTransformer

向量存储

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

适用于 PostgreSQL 的 AlloyDB

Google Cloud AlloyDB 是一种完全托管的关系型数据库服务,可在 Google Cloud 上提供高性能、无缝集成和令人印象深刻的可扩展性。AlloyDB 100% 兼容 PostgreSQL。
安装 python 包
pip install langchain-google-alloydb-pg
请参阅用法示例
from langchain_google_alloydb_pg import AlloyDBVectorStore # AlloyDBEngine also available
Google Cloud BigQuery,BigQuery 是 Google Cloud 中一个无服务器且经济高效的企业数据仓库。 Google Cloud BigQuery Vector Search BigQuery 向量搜索允许您使用 GoogleSQL 进行语义搜索,使用向量索引实现快速但近似的结果,或使用暴力搜索实现精确结果。
它可以计算欧几里得距离或余弦距离。在 LangChain 中,我们默认使用欧几里得距离。
我们需要安装几个 python 包。
pip install google-cloud-bigquery
请参阅用法示例
# Note: BigQueryVectorSearch might be in langchain or langchain_community depending on version
# Check imports in the usage example.
from langchain.vectorstores import BigQueryVectorSearch # Or langchain_community.vectorstores

适用于 Redis 的 Memorystore

使用 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 (原生模式)

使用 Firestore 的向量存储。
安装 python 包
pip install langchain-google-firestore
请参阅用法示例
from langchain_google_firestore import FirestoreVectorStore

适用于 MySQL 的 Cloud SQL

使用 Cloud SQL for MySQL 的向量存储。
安装 python 包
pip install langchain-google-cloud-sql-mysql
请参阅用法示例
from langchain_google_cloud_sql_mysql import MySQLVectorStore # MySQLEngine also available

适用于 PostgreSQL 的 Cloud SQL

使用 Cloud SQL for PostgreSQL 的向量存储。
安装 python 包
pip install langchain-google-cloud-sql-pg
请参阅用法示例
from langchain_google_cloud_sql_pg import PostgresVectorStore # PostgresEngine also available
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 后端
用于在 GCS 中存储文档/索引的 VectorSearchVectorStore 的别名。
from langchain_google_vertexai import VectorSearchVectorStoreGCS

检索器

使用 Google Cloud 服务检索信息。
使用 Google Cloud 的 Vertex AI Search 构建生成式 AI 驱动的搜索引擎,允许开发者快速为客户和员工构建生成式 AI 驱动的搜索引擎。
请参阅用法示例 注意:GoogleVertexAISearchRetriever 已弃用。请使用 langchain-google-community 中的以下组件。 安装 google-cloud-discoveryengine 包以进行底层访问。
pip install google-cloud-discoveryengine langchain-google-community
VertexAIMultiTurnSearchRetriever
from langchain_google_community import VertexAIMultiTurnSearchRetriever
VertexAISearchRetriever
# Note: The example code shows VertexAIMultiTurnSearchRetriever, confirm if VertexAISearchRetriever is separate or related.
# Assuming it might be related or a typo in the original doc:
from langchain_google_community import VertexAISearchRetriever # Verify class name if needed
VertexAISearchSummaryTool
from langchain_google_community import VertexAISearchSummaryTool

文档 AI 仓库

使用 Document AI Warehouse 搜索、存储和管理文档。
注意:GoogleDocumentAIWarehouseRetriever(来自 langchain)已弃用。请使用 langchain-google-community 中的 DocumentAIWarehouseRetriever 需要安装相关的 Document AI 包(查看具体文档)。
pip install langchain-google-community # Add specific docai dependencies if needed
from langchain_google_community.documentai_warehouse import DocumentAIWarehouseRetriever

工具

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

文本转语音

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

Google Drive

与 Google 云端硬盘交互的工具。 安装所需的包:
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 财经

查询财务数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

Google 工作

查询职位列表。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_jobs import GoogleJobsQueryRun
# Note: Utilities might be shared, e.g., GoogleFinanceAPIWrapper was listed, verify correct utility
# from langchain_community.utilities.google_jobs import GoogleJobsAPIWrapper # If exists

Google 智能镜头

执行视觉搜索。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapper

Google 地点

搜索地点信息。需要 googlemaps 包和 Google Maps API 密钥。
pip install googlemaps langchain # Requires base langchain
请参阅用法示例和授权说明
# Note: GooglePlacesTool might be in langchain or langchain_community depending on version
from langchain.tools import GooglePlacesTool # Or langchain_community.tools

Google 学术搜索

搜索学术论文。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires 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"])
请参阅详细笔记本 查询 Google 趋势数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_trends import GoogleTrendsQueryRun
from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper

工具包

特定 Google 服务的工具集合。

Gmail

Google Gmail 是 Google 提供的免费电子邮件服务。此工具包通过 Gmail API 处理电子邮件。
pip install langchain-google-community[gmail]
请参阅用法示例和授权说明
# Load the whole toolkit
from langchain_google_community import GmailToolkit

# Or use individual tools
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

MCP 工具箱

MCP Toolbox 提供了一种简单高效的方式来连接到您的数据库,包括 Google Cloud 上的数据库,如 Cloud SQLAlloyDB。通过 MCP Toolbox,您可以无缝地将数据库与 LangChain 集成,以构建强大的数据驱动应用程序。

安装

要开始使用,请安装 Toolbox 服务器和客户端 配置一个 tools.yaml 来定义您的工具,然后执行 toolbox 启动服务器:
toolbox --tools-file "tools.yaml"
然后,安装 Toolbox 客户端
pip install toolbox-langchain

入门

以下是使用 MCP Toolbox 连接到数据库的快速示例
from toolbox_langchain import ToolboxClient

async with ToolboxClient("http://127.0.0.1:5000") as client:

    tools = client.load_toolset()
请参阅用法示例和设置说明

回调

跟踪 LLM/聊天模型使用情况。

Vertex AI 回调处理程序

跟踪 VertexAI 使用信息的回调处理程序。
需要 langchain-google-vertexai
from langchain_google_vertexai.callbacks import VertexAICallbackHandler

评估器

使用 Vertex AI 评估模型输出。 需要 langchain-google-vertexai

VertexPairWiseStringEvaluator

使用 Vertex AI 模型进行成对评估。
from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluator

VertexStringEvaluator

使用 Vertex AI 模型评估单个预测字符串。
# Note: Original doc listed VertexPairWiseStringEvaluator twice. Assuming this class exists.
from langchain_google_vertexai.evaluators.evaluation import VertexStringEvaluator # Verify class name if needed

其他 Google 产品

与核心云平台之外的各种 Google 服务集成。

文档加载器

Google Drive

Google 云端硬盘文件存储。目前支持 Google 文档。
安装云端硬盘依赖项
pip install langchain-google-community[drive]
请参阅用法示例和授权说明
from langchain_google_community import GoogleDriveLoader

向量存储

ScaNN (本地索引)

Google ScaNN (可扩展最近邻) 是一个 python 包。 ScaNN 是一种高效大规模向量相似度搜索方法。
ScaNN 包括用于最大内积搜索的搜索空间剪枝和量化,也支持其他距离函数,例如欧几里得距离。该实现针对支持 AVX2 的 x86 处理器进行了优化。有关更多详细信息,请参阅其 Google Research github
安装 scann
pip install scann langchain-community # Requires langchain-community
请参阅用法示例
from langchain_community.vectorstores import ScaNN

检索器

Google Drive

从 Google 云端硬盘检索文档。 安装所需的包:
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledrive
请参阅用法示例和授权说明
from langchain_googledrive.retrievers import GoogleDriveRetriever

工具

Google Drive

与 Google 云端硬盘交互的工具。 安装所需的包:
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 财经

查询财务数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

Google 工作

查询职位列表。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_jobs import GoogleJobsQueryRun
# Note: Utilities might be shared, e.g., GoogleFinanceAPIWrapper was listed, verify correct utility
# from langchain_community.utilities.google_jobs import GoogleJobsAPIWrapper # If exists

Google 智能镜头

执行视觉搜索。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapper

Google 地点

搜索地点信息。需要 googlemaps 包和 Google Maps API 密钥。
pip install googlemaps langchain # Requires base langchain
请参阅用法示例和授权说明
# Note: GooglePlacesTool might be in langchain or langchain_community depending on version
from langchain.tools import GooglePlacesTool # Or langchain_community.tools

Google 学术搜索

搜索学术论文。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_scholar import GoogleScholarQueryRun
from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapper

Google 搜索

使用 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"])
请参阅详细笔记本 查询 Google 趋势数据。需要 google-search-results 包和 SerpApi 密钥。
pip install google-search-results langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.tools.google_trends import GoogleTrendsQueryRun
from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper

工具包

Gmail

Google Gmail 是 Google 提供的免费电子邮件服务。此工具包通过 Gmail API 处理电子邮件。
pip install langchain-google-community[gmail]
请参阅用法示例和授权说明
# Load the whole toolkit
from langchain_google_community import GmailToolkit

# Or use individual tools
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

聊天加载器

Gmail

从 Gmail 线程加载聊天历史。
安装 Gmail 依赖项
pip install langchain-google-community[gmail]
请参阅用法示例和授权说明
from langchain_google_community import GMailLoader

第三方集成

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

SearchApi

SearchApi 提供 Google 搜索、YouTube 等 API 访问。需要 langchain-community
请参阅用法示例和授权说明
from langchain_community.utilities import SearchApiAPIWrapper

SerpApi

SerpApi 提供 Google 搜索结果的 API 访问。需要 langchain-community
请参阅用法示例和授权说明
from langchain_community.utilities import SerpAPIWrapper

Serper.dev

Google Serper 提供 Google 搜索结果的 API 访问。需要 langchain-community
请参阅用法示例和授权说明
from langchain_community.utilities import GoogleSerperAPIWrapper

YouTube

YouTube 搜索工具

在没有官方 API 的情况下搜索 YouTube 视频。需要 youtube_search 包。
pip install youtube_search langchain # Requires base langchain
请参阅用法示例
# Note: YouTubeSearchTool might be in langchain or langchain_community
from langchain.tools import YouTubeSearchTool # Or langchain_community.tools

YouTube 音频加载器

从 YouTube 视频下载音频。需要 yt_dlppydublibrosa
pip install yt_dlp pydub librosa langchain-community # Requires langchain-community
请参阅用法示例和授权说明
from langchain_community.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
# Often used with whisper parsers:
# from langchain_community.document_loaders.parsers import OpenAIWhisperParser, OpenAIWhisperParserLocal

YouTube 字幕加载器

加载视频字幕。需要 youtube-transcript-api
pip install youtube-transcript-api langchain-community # Requires langchain-community
请参阅用法示例
from langchain_community.document_loaders import YoutubeLoader

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.