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 模型、Anthropic on 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"

聊天模型

使用 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")

# 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 对象。

嵌入模型

使用 gemini-embedding-exp-03-07 等模型和 GoogleGenerativeAIEmbeddings 类生成文本嵌入。

查看 使用示例

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])

大型语言模型

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

查看 使用示例

from langchain_google_genai import GoogleGenerativeAI

llm = GoogleGenerativeAI(model="gemini-2.0-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
API 参考:ChatVertexAI

Anthropic on 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

Anthropic on Vertex AI Model Garden中的 Mistral

from langchain_google_vertexai.model_garden_maas.mistral import VertexModelGardenMistral

来自 Hugging Face 的本地 Gemma

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

from langchain_google_vertexai.gemma import GemmaChatLocalHF
API 参考:GemmaChatLocalHF

来自 Kaggle 的本地 Gemma

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

from langchain_google_vertexai.gemma import GemmaChatLocalKaggle

Anthropic on 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

大型语言模型

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

Anthropic on Vertex AI Model Garden

通过 Vertex AI Model Garden 服务访问 Gemini 以及数百个开源模型。需要 langchain-google-vertexai

查看 使用示例

from langchain_google_vertexai import VertexAIModelGarden

来自 Hugging Face 的本地 Gemma

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

from langchain_google_vertexai.gemma import GemmaLocalHF
API 参考:GemmaLocalHF

来自 Kaggle 的本地 Gemma

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

from langchain_google_vertexai.gemma import GemmaLocalKaggle

Anthropic on 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

嵌入模型

Vertex AI

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

查看 使用示例

from langchain_google_vertexai import VertexAIEmbeddings
API 参考:VertexAI 嵌入

文档加载器

从各种 Google Cloud 源加载文档。

AlloyDB for PostgreSQL

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

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

用于 SQL Server 的 Cloud SQL

用于 SQL Server 的 Google Cloud SQL 是一项全托管的 SQL Server 数据库服务。

安装 Python 包:

pip install langchain-google-cloud-sql-mssql

请参阅 使用示例

from langchain_google_cloud_sql_mssql import MSSQLLoader # MSSQLEngine also available

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

云存储

云存储 是一项用于存储非结构化数据的托管服务。

使用 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

El Carro 适用于 Oracle 工作负载

Google El Carro Oracle 运算符 在 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(数据仓储模式)

Google Cloud Firestore(Datastore 模式)

安装 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 语音转文本 可转录音频文件。

使用语音转文本依赖项进行安装:

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
API 参考:Blob |DocAIParser

谷歌翻译

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

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 向量搜索来存储和检索向量。

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

Google Cloud BigQuery, BigQuery 是 Google Cloud 中无服务器且具成本效益的企业级数据仓库。

Google Cloud BigQuery 向量搜索 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

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

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

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

Google Cloud Vertex AI 向量搜索(来自 Google Cloud,前身为 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 服务检索信息。

使用 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
# 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

文档智能仓库

使用 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 服务集成。

Text-to-Speech

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

安装所需的包:

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

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

from langchain_google_community import 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-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.agents import load_tools
tools = load_tools(["google-search"])
API 参考:load_tools

查看 详细笔记本

查询 Google Trends 数据。需要 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

内存

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

AlloyDB for PostgreSQL

使用 AlloyDB 实现聊天记忆。

安装 Python 包:

pip install langchain-google-alloydb-pg

请参阅 使用示例

from langchain_google_alloydb_pg import AlloyDBChatMessageHistory # AlloyDBEngine also available

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

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

用于 SQL Server 的 Cloud SQL

使用 Cloud SQL for SQL Server 实现聊天记忆。

安装 Python 包:

pip install langchain-google-cloud-sql-mssql

请参阅 使用示例

from langchain_google_cloud_sql_mssql import MSSQLChatMessageHistory # MSSQLEngine also available

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

使用 Firestore 实现聊天记忆。

安装 Python 包:

pip install langchain-google-firestore

请参阅 使用示例

from langchain_google_firestore import FirestoreChatMessageHistory

Firestore(数据仓储模式)

使用 Firestore(Datastore 模式) 实现聊天记忆。

安装 Python 包:

pip install langchain-google-datastore

请参阅 使用示例

from langchain_google_datastore import DatastoreChatMessageHistory

El Carro:Kubernetes 的 Oracle 操作员

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

安装 Python 包:

pip install langchain-google-el-carro

请参阅 使用示例

from langchain_google_el_carro import ElCarroChatMessageHistory

回调函数

跟踪 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 Drive 文件存储。目前支持 Google Docs

使用 Drive 依赖项安装:

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
API 参考:ScaNN

检索器

Google Drive

从 Google Drive 检索文档。

安装所需的包:

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

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

from langchain_googledrive.retrievers import GoogleDriveRetriever

工具

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-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.agents import load_tools
tools = load_tools(["google-search"])
API 参考:load_tools

查看 详细笔记本

查询 Google Trends 数据。需要 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 参考:GMail 加载器

第三方集成

通过第三方 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 搜索工具

搜索 YouTube 个视频,无需使用官方 API。需要 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