谷歌
所有与Google Cloud Platform和其他Google产品相关的功能。
语言模型
我们建议个人开发者从Gemini API (langchain-google-genai)开始,当他们需要访问商业支持和更高的速率限制时,再转向Vertex AI (langchain-google-vertexai)。如果您已经适应云或云原生,那么您可以立即开始使用Vertex AI。
请在这里找到更多信息。
谷歌生成式人工智能
通过GoogleGenerativeAI类访问谷歌AI Gemini 模型,如 gemini-pro 和 gemini-pro-vision。
安装 Python 包。
pip install langchain-google-genai查看使用示例。
from langchain_google_genai import GoogleGenerativeAIVertex AI 模型库
通过Vertex AI Model Garden服务访问PaLM和数百个开源模型。
我们需要安装 langchain-google-vertexai Python 包。
pip install langchain-google-vertexai查看使用示例。
from langchain_google_vertexai import VertexAIModelGarden聊天模型
谷歌生成式人工智能
通过ChatGoogleGenerativeAI类访问谷歌AI Gemini 模型,如 gemini-pro 和 gemini-pro-vision。
pip install -U langchain-google-genai配置您的 API 密钥。
export GOOGLE_API_KEY=your-api-keyfrom langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(model="gemini-pro")
llm.invoke("Sing a ballad of LangChain.")当提供单个聊天消息时,Gemini vision 模型支持图像输入。
from langchain_core.messages import HumanMessage
from langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(model="gemini-pro-vision")
message = HumanMessage(
content=[
{
"type": "text",
"text": "What's in this image?",
}, # You can optionally provide text parts
{"type": "image_url", "image_url": "https://picsum.photos/seed/picsum/200/300"},
]
)
llm.invoke([message])image_url 的值可以是以下之一:
公共图像 URL
gcs 文件(例如,"gcs://path/to/file.png")
本地文件路径
base64 编码的图像(例如,data:image/png;base64,abcd124)
PIL 图像
Vertex AI
通过 Google Cloud 访问 PaLM 聊天模型,如 chat-bison 和 codechat-bison。
我们需要安装 langchain-google-vertexai Python 包。
pip install langchain-google-vertexai查看使用示例。
from langchain_google_vertexai import ChatVertexAI嵌入模型
谷歌生成式人工智能嵌入
查看使用示例。
pip install -U langchain-google-genai配置您的 API 密钥。
export GOOGLE_API_KEY=your-api-keyfrom langchain_google_genai import GoogleGenerativeAIEmbeddingsVertex AI
我们需要安装 langchain-google-vertexai Python 包。
pip install langchain-google-vertexai查看使用示例。
from langchain_google_vertexai import VertexAIEmbeddings文档加载器
AlloyDB for PostgreSQL
Google Cloud AlloyDB 是谷歌云上提供高性能、无缝集成和令人印象深刻的可扩展性的全托管关系数据库服务。AlloyDB 与 PostgreSQL 100% 兼容。
安装 Python 包:
pip install langchain-google-alloydb-pg查看使用示例。
from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBLoaderBigQuery
Google Cloud BigQuery 是一种无服务器且成本效益的企业数据仓库,可跨云工作并随着您在谷歌云上的数据扩展。
我们需要安装带有 Big Query 依赖项的 langchain-google-community。
pip install langchain-google-community[bigquery]查看使用示例。
from langchain_google_community import BigQueryLoaderBigtable
Google Cloud Bigtable 是谷歌云中的完全托管 NoSQL 大数据数据库服务。
安装 Python 包:
pip install langchain-google-bigtablefrom langchain_google_bigtable import BigtableLoader
### 云 SQL for MySQL
> [Google Cloud SQL for MySQL](https://cloud.google.com/sql) 是一个完全托管的数据库服务,可帮助您在 Google Cloud 上设置、维护、管理和管理 MySQL 关系数据库。
安装 Python 包:
```bash
pip install langchain-google-cloud-sql-mysql查看使用示例。
from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLDocumentLoader云 SQL for SQL Server
Google Cloud SQL for SQL Server 是一个完全托管的数据库服务,可帮助您在 Google Cloud 上设置、维护、管理和管理 SQL Server 数据库。 安装 Python 包:
pip install langchain-google-cloud-sql-mssql查看使用示例。
from langchain_google_cloud_sql_mssql import MSSQLEngine, MSSQLLoader云 SQL for PostgreSQL
Google Cloud SQL for PostgreSQL 是一个完全托管的数据库服务,可帮助您在 Google Cloud 上设置、维护、管理和管理 PostgreSQL 关系数据库。 安装 Python 包:
pip install langchain-google-cloud-sql-pg查看使用示例。
from langchain_google_cloud_sql_pg import PostgresEngine, PostgresLoader云存储
云存储 是一种用于在 Google Cloud 中存储非结构化数据的托管服务。 我们需要安装带有 Google Cloud 存储依赖项的
langchain-google-community。
pip install langchain-google-community[gcs]Google Cloud Storage 有两个加载器:Directory 和 File。 查看使用示例。
from langchain_google_community import GCSDirectoryLoader查看使用示例。
from langchain_google_community import GCSFileLoaderEl Carro 用于 Oracle 工作负载
Google El Carro Oracle Operator 提供了一种在 Kubernetes 中运行 Oracle 数据库的方式,作为一个可移植、开源、社区驱动的、无供应商锁定的容器编排系统。
pip install langchain-google-el-carro查看使用示例。
from langchain_google_el_carro import ElCarroLoaderGoogle Drive
Google Drive 是由 Google 开发的文件存储和同步服务。 目前,只支持
Google Docs。 我们需要安装带有 Google Drive 依赖项的langchain-google-community。
pip install langchain-google-community[drive]查看使用示例和授权说明。
from langchain_google_community import GoogleDriveLoaderFirestore(原生模式)
Google Cloud Firestore 是一个为自动扩展、高性能和易于应用程序开发而构建的 NoSQL 文档数据库。 安装 Python 包:
pip install langchain-google-firestore查看使用示例。
from langchain_google_firestore import FirestoreLoaderFirestore(Datastore 模式)
Google Cloud Firestore(Datastore 模式) 是一个为自动扩展、高性能和易于应用程序开发而构建的 NoSQL 文档数据库。 Firestore 是 Datastore 的最新版本,相比 Datastore 引入了几项改进。 安装 Python 包:
pip install langchain-google-datastore查看使用示例。
from langchain_google_datastore import DatastoreLoaderMemorystore for Redis
Google Cloud Memorystore for Redis 是一个完全托管的 Redis 服务,用于 Google Cloud。在 Google Cloud 上运行的应用程序可以利用高度可扩展、可用性高、安全的 Redis 服务来实现极高的性能,而无需管理复杂的 Redis 部署。 安装 Python 包:
pip install langchain-google-memorystore-redis查看使用示例。
from langchain_google_memorystore_redis import MemorystoreLoaderSpanner
Google Cloud Spanner 是一个完全托管的、关键任务的关系数据库服务,可在 Google Cloud 上提供全球范围的事务一致性、高可用性的自动同步复制,并支持两种 SQL 方言:GoogleSQL(带扩展的 ANSI 2011)和 PostgreSQL。 安装 Python 包:
pip install langchain-google-spanner查看使用示例。
from langchain_google_spanner import SpannerLoader语音转文本
Google Cloud 语音转文本 是由 Google 云中的 Google 语音识别模型提供支持的音频转录 API。 该文档加载器将音频文件转录为文本,并将文本结果输出为文档。 首先,我们需要安装带有语音转文本依赖项的
langchain-google-community。
pip install langchain-google-community[speech]查看使用示例和授权说明。
from langchain_google_community import SpeechToTextLoader文档转换器
文档 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 DocAIParserGoogle 翻译
Google 翻译 是由 Google 开发的多语言神经机器翻译服务,用于将文本、文档和网站从一种语言翻译为另一种语言。
GoogleTranslateTransformer允许您使用 Google Cloud 翻译 API 翻译文本和 HTML。 首先,我们需要安装带有翻译依赖项的langchain-google-community。
pip install langchain-google-community[translate]查看使用示例和授权说明。
from langchain_google_community import GoogleTranslateTransformer向量存储
AlloyDB for PostgreSQL
Google Cloud AlloyDB 是 Google Cloud 上提供高性能、无缝集成和令人印象深刻的可扩展性的全托管关系数据库服务。AlloyDB 与 PostgreSQL 100% 兼容。 安装 Python 包:
pip install langchain-google-alloydb-pg查看使用示例。
from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBVectorStoreBigQuery 向量搜索
Google Cloud BigQuery 是 Google Cloud 中的无服务器且具有成本效益的企业数据仓库。 Google Cloud BigQuery 向量搜索 BigQuery 向量搜索允许您使用 GoogleSQL 进行语义搜索,使用向量索引快速但近似结果,或使用蛮力进行精确结果。 它可以计算欧氏距离或余弦距离。在 LangChain 中,我们默认使用欧氏距离。 我们需要安装几个 Python 包。
pip install google-cloud-bigquery查看使用示例。
from langchain.vectorstores import BigQueryVectorSearchMemorystore for Redis
Google Cloud Memorystore for Redis 是 Google Cloud 的一个全托管 Redis 服务。在 Google Cloud 上运行的应用程序可以通过利用高度可扩展、可用、安全的 Redis 服务来实现极致性能,而无需管理复杂的 Redis 部署负担。 安装 Python 包:
pip install langchain-google-memorystore-redis查看使用示例。
from langchain_google_memorystore_redis import RedisVectorStoreSpanner
Google Cloud Spanner 是 Google Cloud 上的一个全托管、关键任务、关系数据库服务,提供全球规模的事务一致性、高可用性的自动同步复制,并支持两种 SQL 方言:GoogleSQL(带扩展的 ANSI 2011)和 PostgreSQL。 安装 Python 包:
pip install langchain-google-spanner
参见[使用示例](/zh/langchain/integrations/vectorstores/google_spanner)。
```python
from langchain_google_spanner import SpannerVectorStoreFirestore(原生模式)
Google Cloud Firestore 是一种NoSQL文档数据库,专为自动扩展、高性能和应用程序开发的便利性而构建。
安装python包:
pip install langchain-google-firestore参见使用示例。
from langchain_google_firestore import FirestoreVectorstore云 SQL for MySQL
Google Cloud SQL for MySQL 是一种完全托管的数据库服务,可帮助您在Google Cloud上设置、维护、管理和管理MySQL关系数据库。
安装python包:
pip install langchain-google-cloud-sql-mysql参见使用示例。
from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLVectorStore云 SQL for PostgreSQL
Google Cloud SQL for PostgreSQL 是一种完全托管的数据库服务,可帮助您在Google Cloud上设置、维护、管理和管理PostgreSQL关系数据库。
安装python包:
pip install langchain-google-cloud-sql-pg参见使用示例。
from langchain_google_cloud_sql_pg import PostgresEngine, PostgresVectorStoreVertex AI矢量搜索
Google Cloud Vertex AI矢量搜索 来自Google Cloud,
以前被称为
Vertex AI Matching Engine,提供行业领先的高规模
低延迟矢量数据库。这些矢量数据库通常
被称为矢量相似度匹配或近似最近邻(ANN)服务。
安装python包:
pip install langchain-google-vertexai参见使用示例。
from langchain_google_vertexai import VectorSearchVectorStoreScaNN
(可扩展最近邻)是一个python包。
ScaNN是一种用于高效的大规模矢量相似度搜索的方法。
ScaNN包括搜索空间修剪和最大内积搜索的量化,还支持其他距离函数,如
欧几里德距离。该实现针对具有AVX2支持的x86处理器进行了优化。请参阅其Google Research github
以获取更多详细信息。
我们需要安装scann python包。
pip install scann参见使用示例。
from langchain_community.vectorstores import ScaNN检索器
Google Drive
我们需要安装几个python包。
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib参见使用示例和授权说明。
from langchain_googledrive.retrievers import GoogleDriveRetrieverVertex AI搜索
来自Google Cloud,允许开发人员快速构建基于生成式AI的搜索引擎,用于客户和员工。
我们需要安装google-cloud-discoveryengine python包。
pip install google-cloud-discoveryengine参见使用示例。
from langchain.retrievers import GoogleVertexAISearchRetrieverDocument AI Warehouse
来自Google Cloud,允许企业在单一平台中搜索、存储、管理和管理文档及其AI提取
数据和元数据。
from langchain.retrievers import GoogleDocumentAIWarehouseRetriever
docai_wh_retriever = GoogleDocumentAIWarehouseRetriever(
project_number=...
)
query = ...
documents = docai_wh_retriever.invoke(
query, user_ldap=...
)工具
文本转语音
Google Cloud文本转语音 是Google Cloud服务,可让开发人员
合成具有100多种语音的自然语音,可用于多种语言和变体。
它应用了DeepMind在WaveNet和Google强大神经网络方面的突破性研究
以提供可能的最高保真度。
我们需要安装一个python包。
pip install google-cloud-text-to-speech查看使用示例和授权说明。
from langchain_google_community import TextToSpeechToolGoogle Drive
我们需要安装几个 Python 包。
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib查看使用示例和授权说明。
from langchain_community.utilities.google_drive import GoogleDriveAPIWrapper
from langchain_community.tools.google_drive.tool import GoogleDriveSearchToolGoogle Finance
我们需要安装一个 Python 包。
pip install google-search-results查看使用示例和授权说明。
from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapperGoogle Jobs
我们需要安装一个 Python 包。
pip install google-search-results查看使用示例和授权说明。
from langchain_community.tools.google_jobs import GoogleJobsQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapperGoogle Lens
查看使用示例和授权说明。
from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapperGoogle Places
我们需要安装一个 Python 包。
pip install googlemaps查看使用示例和授权说明。
from langchain.tools import GooglePlacesToolGoogle Scholar
我们需要安装一个 Python 包。
pip install google-search-results查看使用示例和授权说明。
from langchain_community.tools.google_scholar import GoogleScholarQueryRun
from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapperGoogle Search
设置自定义搜索引擎,按照这些说明
从上一步获取 API 密钥和自定义搜索引擎 ID,并将它们设置为环境变量
GOOGLE_API_KEY 和 GOOGLE_CSE_ID。
from langchain_google_community import GoogleSearchAPIWrapper有关此包装器的更详细演练,请参见此笔记本。
我们可以轻松地将此包装器加载为工具(用于与代理一起使用)。我们可以这样做:
from langchain.agents import load_tools
tools = load_tools(["google-search"])Google Trends
我们需要安装一个 Python 包。
pip install google-search-results查看使用示例和授权说明。
from langchain_community.tools.google_trends import GoogleTrendsQueryRun
from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper工具包
GMail
Google Gmail 是由 Google 提供的免费电子邮件服务。
此工具包通过 Gmail API 处理电子邮件。
我们需要安装带有必需依赖项的 langchain-google-community:
pip install langchain-google-community[gmail]查看使用示例和授权说明。
from langchain_google_community import GmailToolkit存储
AlloyDB for PostgreSQL
AlloyDB for PostgreSQL 是 Google Cloud 上提供高性能、无缝集成和令人印象深刻的可扩展性的完全托管关系数据库服务。AlloyDB 与 PostgreSQL 100% 兼容。
安装 Python 包:
pip install langchain-google-alloydb-pg查看使用示例。
from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBChatMessageHistoryCloud SQL for PostgreSQL
Cloud SQL for PostgreSQL 是 Google Cloud 上的全托管数据库服务,可帮助您在 PostgreSQL 关系数据库上设置、维护、管理和管理。
安装 Python 包:
pip install langchain-google-cloud-sql-pg查看使用示例。
from langchain_google_cloud_sql_pg import PostgresEngine, PostgresChatMessageHistory云 SQL for MySQL
云 SQL for MySQL 是一个完全托管的数据库服务,可帮助您在 Google Cloud 上设置、维护、管理和管理 MySQL 关系数据库。
安装 Python 包:
pip install langchain-google-cloud-sql-mysql查看使用示例。
from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLChatMessageHistory云 SQL for SQL Server
云 SQL for SQL Server 是一个完全托管的数据库服务,可帮助您在 Google Cloud 上设置、维护、管理和管理 SQL Server 数据库。
安装 Python 包:
pip install langchain-google-cloud-sql-mssql查看使用示例。
from langchain_google_cloud_sql_mssql import MSSQLEngine, MSSQLChatMessageHistorySpanner
Google Cloud Spanner 是 Google Cloud 上的一个完全托管的、关键任务关系数据库服务,可在全球范围内提供事务一致性、高可用性的自动同步复制,并支持两种 SQL 方言:GoogleSQL(带扩展的 ANSI 2011)和 PostgreSQL。
安装 Python 包:
pip install langchain-google-spanner查看使用示例。
from langchain_google_spanner import SpannerChatMessageHistoryMemorystore for Redis
Google Cloud Memorystore for Redis 是 Google Cloud 上的一个完全托管的 Redis 服务。在 Google Cloud 上运行的应用程序可以通过利用高度可扩展、可用、安全的 Redis 服务实现极高的性能,而无需管理复杂的 Redis 部署负担。
安装 Python 包:
pip install langchain-google-memorystore-redis查看使用示例。
from langchain_google_memorystore_redis import MemorystoreChatMessageHistoryBigtable
Google Cloud Bigtable 是 Google Cloud 上的完全托管的 NoSQL 大数据数据库服务。
安装 Python 包:
pip install langchain-google-bigtable查看使用示例。
from langchain_google_bigtable import BigtableChatMessageHistoryFirestore(原生模式)
Google Cloud Firestore 是一种为自动扩展、高性能和应用程序开发便利而构建的 NoSQL 文档数据库。
安装 Python 包:
pip install langchain-google-firestore查看使用示例。
from langchain_google_firestore import FirestoreChatMessageHistoryFirestore(Datastore 模式)
Google Cloud Firestore 数据存储模式 是一种为自动扩展、高性能和应用程序开发便利而构建的 NoSQL 文档数据库。
Firestore 是 Datastore 的最新版本,并引入了几项改进。
安装 Python 包:
pip install langchain-google-datastore查看使用示例。
from langchain_google_datastore import DatastoreChatMessageHistoryEl Carro:Kubernetes 的 Oracle Operator
提供了一种在可移植、开源、社区驱动、无供应商锁定的容器编排系统 Kubernetes 中运行 Oracle 数据库的方法。
pip install langchain-google-el-carro查看使用示例。
from langchain_google_el_carro import ElCarroChatMessageHistory聊天加载器
GMail
Gmail 是 Google 提供的免费电子邮件服务。
此加载器与通过 Gmail API 处理电子邮件一起使用。
我们需要安装带有底层依赖关系的 langchain-google-community。
pip install langchain-google-community[gmail]查看使用示例和授权说明。
from langchain_google_community import GMailLoader第三方集成
SearchApi
SearchApi 提供了一个第三方 API,用于访问 Google 搜索结果、YouTube 搜索和转录,以及其他与 Google 相关的引擎。
查看使用示例和授权说明.
from langchain_community.utilities import SearchApiAPIWrapperSerpApi
SerpApi 提供了第三方 API 来访问谷歌搜索结果。
查看使用示例和授权说明。
from langchain_community.utilities import SerpAPIWrapperSerper.dev
查看使用示例和授权说明。
from langchain_community.utilities import GoogleSerperAPIWrapperYouTube
YouTube Search 包搜索
YouTube视频,避免使用其受到严格限制的 API。
它使用 YouTube 主页上的表单,并抓取生成的页面。
我们需要安装一个 Python 包。
pip install youtube_search查看使用示例。
from langchain.tools import YouTubeSearchToolYouTube 音频
YouTube 是由
使用 YoutubeAudioLoader 来获取/下载音频文件。
然后,使用 OpenAIWhisperParser 将其转录为文本。
我们需要安装几个 Python 包。
pip install yt_dlp pydub librosa查看使用示例和授权说明。
from langchain_community.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
from langchain_community.document_loaders.parsers import OpenAIWhisperParser, OpenAIWhisperParserLocalYouTube 字幕
YouTube 是由
我们需要安装 youtube-transcript-api Python 包。
pip install youtube-transcript-api查看使用示例。
from langchain_community.document_loaders import YoutubeLoader