谷歌
所有与 Google Cloud、Google Gemini 及其他 Google 产品相关的功能。
- Google 生成式 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
包中找到 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 对象。
嵌入模型
使用 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])
LLM
使用 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 模型园和其他 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
Google Cloud 集成通常使用应用程序默认凭据 (ADC)。请参阅 Google Cloud 身份验证文档 以获取设置说明(例如,使用 gcloud auth application-default login
)。
聊天模型
Vertex AI
通过 Vertex AI 平台访问 Gemini
等聊天模型。
参见使用示例。
from langchain_google_vertexai import ChatVertexAI
Vertex AI 模型园上的 Anthropic
参见使用示例。
from langchain_google_vertexai.model_garden import ChatAnthropicVertex
Vertex AI 模型园上的 Llama
from langchain_google_vertexai.model_garden_maas.llama import VertexModelGardenLlama
Vertex AI 模型园上的 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 模型园上的 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 模型园
通过 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 模型园上的 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
文档加载器
从各种 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
适用于 MySQL 的 Google Cloud SQL 是一种完全托管的 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
适用于 PostgreSQL 的 Cloud SQL
适用于 PostgreSQL 的 Google Cloud SQL 是一种完全托管的 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
El Carro 适用于 Oracle 工作负载
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 模式)
安装 Python 包
pip install langchain-google-datastore
参见使用示例。
from langchain_google_datastore import DatastoreLoader
适用于 Redis 的 Memorystore
适用于 Redis 的 Google Cloud Memorystore 是一种完全托管的 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 语音转文本 是一种 Google Cloud 服务,可让开发者利用 100 多种语音、多种语言和变体合成自然发音的语音。它应用了 DeepMind 在 WaveNet 方面的突破性研究和 Google 强大的神经网络,以提供尽可能高的保真度。
安装语音转文本依赖项
pip install langchain-google-community[speech]
参见使用示例和授权说明。
from langchain_google_community import SpeechToTextLoader
文档转换器
使用 Google Cloud 服务转换文档。
文档 AI
Google Cloud 文档 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 与 PostgreSQL 100% 兼容。
安装 Python 包
pip install langchain-google-alloydb-pg
参见使用示例。
from langchain_google_alloydb_pg import AlloyDBVectorStore # AlloyDBEngine also available
BigQuery 向量搜索
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
适用于 Redis 的 Memorystore
使用 适用于 Redis 的 Memorystore 的向量存储。
安装 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
使用 适用于 MySQL 的 Cloud SQL 的向量存储。
安装 Python 包
pip install langchain-google-cloud-sql-mysql
参见使用示例。
from langchain_google_cloud_sql_mysql import MySQLVectorStore # MySQLEngine also available
适用于 PostgreSQL 的 Cloud SQL
使用 适用于 PostgreSQL 的 Cloud SQL 的向量存储。
安装 Python 包
pip install langchain-google-cloud-sql-pg
参见使用示例。
from langchain_google_cloud_sql_pg import PostgresVectorStore # PostgresEngine also available
Vertex AI 向量搜索
Google Cloud 的 Google Cloud Vertex AI 向量搜索(前身为
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
使用 Google Cloud 的 Vertex AI Search 构建生成式 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 仓库
使用 文档 AI 仓库 搜索、存储和管理文档。
注意:GoogleDocumentAIWarehouseRetriever
(来自 langchain
)已弃用。请使用 langchain-google-community
中的 DocumentAIWarehouseRetriever
。
需要安装相关的文档 AI 包(请查阅具体文档)。
pip install langchain-google-community # Add specific docai dependencies if needed
from langchain_google_community.documentai_warehouse import DocumentAIWarehouseRetriever
工具
将代理与各种 Google 服务集成。
文本转语音
Google Cloud 文本转语音 是一种 Google Cloud 服务,可让开发者利用 100 多种语音、多种语言和变体合成自然发音的语音。它应用了 DeepMind 在 WaveNet 方面的突破性研究和 Google 强大的神经网络,以提供尽可能高的保真度。
安装所需包
pip install google-cloud-text-to-speech langchain-google-community
参见使用示例和授权说明。
from langchain_google_community import TextToSpeechTool
Google 云端硬盘
与 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_KEY
和 GOOGLE_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 Trends
查询 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 数据库存储会话历史记录。
适用于 PostgreSQL 的 AlloyDB
使用 AlloyDB 的聊天记忆。
安装 Python 包
pip install langchain-google-alloydb-pg
参见使用示例。
from langchain_google_alloydb_pg import AlloyDBChatMessageHistory # AlloyDBEngine also available
适用于 PostgreSQL 的 Cloud SQL
使用 适用于 PostgreSQL 的 Cloud SQL 的聊天记忆。
安装 Python 包
pip install langchain-google-cloud-sql-pg
参见使用示例。
from langchain_google_cloud_sql_pg import PostgresChatMessageHistory # PostgresEngine also available
适用于 MySQL 的 Cloud SQL
使用 适用于 MySQL 的 Cloud SQL 的聊天记忆。
安装 Python 包
pip install langchain-google-cloud-sql-mysql
参见使用示例。
from langchain_google_cloud_sql_mysql import MySQLChatMessageHistory # MySQLEngine also available
适用于 SQL Server 的 Cloud SQL
使用 适用于 SQL Server 的 Cloud SQL 的聊天记忆。
安装 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
适用于 Redis 的 Memorystore
使用 适用于 Redis 的 Memorystore 的聊天记忆。
安装 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(Datastore 模式)
使用 Datastore 模式下的 Firestore 的聊天记忆。
安装 Python 包
pip install langchain-google-datastore
参见使用示例。
from langchain_google_datastore import DatastoreChatMessageHistory
El Carro:适用于 Kubernetes 的 Oracle Operator
使用通过 El Carro 运行的 Oracle 数据库的聊天记忆。
安装 Python 包
pip install langchain-google-el-carro
参见使用示例。
from langchain_google_el_carro import ElCarroChatMessageHistory
回调
跟踪 LLM/聊天模型使用情况。
Vertex AI 回调处理程序
跟踪
VertexAI
使用信息的 Callback Handler。
需要 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 产品
与核心 Cloud Platform 之外的各种 Google 服务的集成。
文档加载器
Google 云端硬盘
Google 云端硬盘 文件存储。目前支持
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
检索器
Google 云端硬盘
从 Google 云端硬盘检索文档。
安装所需包
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledrive
参见使用示例和授权说明。
from langchain_googledrive.retrievers import GoogleDriveRetriever
工具
Google 云端硬盘
与 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_KEY
和 GOOGLE_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 Trends
查询 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 访问 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_dlp
、pydub
、librosa
。
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