Skip to main content

Google

Google Cloud Platform 及其他 Google 产品相关的所有功能。

聊天模型

我们建议个人开发者从 Gemini API (langchain-google-genai) 开始,当他们需要访问商业支持和更高的速率限制时,再转向 Vertex AI (langchain-google-vertexai)。如果您已经是云友好型或云原生的,那么您可以立即开始使用 Vertex AI。
有关更多信息,请参见 这里

Google 生成式 AI

通过 ChatGoogleGenerativeAI 类访问 GoogleAI Gemini 模型,例如 gemini-progemini-pro-vision

pip install -U langchain-google-genai

配置您的 API 密钥。

export GOOGLE_API_KEY=your-api-key
from langchain_google_genai import ChatGoogleGenerativeAI

llm = ChatGoogleGenerativeAI(model="gemini-pro")
llm.invoke("Sing a ballad of LangChain.")

Gemini 视觉模型在提供单个聊天消息时支持图像输入。

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-bisoncodechat-bison

我们需要安装 langchain-google-vertexai python 包。

pip install langchain-google-vertexai

查看 使用示例

from langchain_google_vertexai import ChatVertexAI

LLMs

Google 生成式 AI

通过 GoogleGenerativeAI 类访问 GoogleAI 的 Gemini 模型,例如 gemini-progemini-pro-vision

安装 Python 包。

pip install langchain-google-genai

查看 使用示例

from langchain_google_genai import GoogleGenerativeAI

Vertex AI 模型花园

通过 Vertex AI Model Garden 服务访问 PaLM 和数百个开源模型。

我们需要安装 langchain-google-vertexai Python 包。

pip install langchain-google-vertexai

查看 使用示例

from langchain_google_vertexai import VertexAIModelGarden

嵌入模型

Google 生成式 AI 嵌入

查看 使用示例

pip install -U langchain-google-genai

配置您的 API 密钥。

export GOOGLE_API_KEY=your-api-key
from langchain_google_genai import GoogleGenerativeAIEmbeddings

Vertex AI

我们需要安装 langchain-google-vertexai python 包。

pip install langchain-google-vertexai

查看 使用示例

from langchain_google_vertexai import VertexAIEmbeddings

Palm 嵌入

我们需要安装 langchain-community python 包。

pip install langchain-community
from langchain_community.embeddings.google_palm import GooglePalmEmbeddings

文档加载器

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, AlloyDBLoader

BigQuery

Google Cloud BigQuery 是一个无服务器且具有成本效益的企业数据仓库,可以跨云工作,并随着您在 Google Cloud 中的数据规模而扩展。

我们需要安装带有 Big Query 依赖项的 langchain-google-community

pip install langchain-google-community[bigquery]

查看 使用示例

from langchain_google_community import BigQueryLoader

Bigtable

Google Cloud Bigtable 是谷歌在谷歌云中完全托管的 NoSQL 大数据数据库服务。 安装 Python 包:

pip install langchain-google-bigtable

查看 Google Cloud 使用示例

from langchain_google_bigtable import BigtableLoader

Cloud 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, MySQLDocumentLoader

Cloud 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

Cloud 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 中存储非结构化数据的托管服务。

我们需要安装 langchain-google-community 及其 Google Cloud Storage 依赖项。

pip install langchain-google-community[gcs]

对于 Google Cloud Storage 有两个加载器:DirectoryFile 加载器。

请参见 使用示例

from langchain_google_community import GCSDirectoryLoader

请参见 使用示例

from langchain_google_community import GCSFileLoader

El Carro for Oracle Workloads

Google El Carro Oracle Operator 提供了一种在Kubernetes中运行Oracle数据库的方法,作为一种可移植的开源、社区驱动的、无供应商锁定的容器编排系统。

pip install langchain-google-el-carro

请参见 使用示例

from langchain_google_el_carro import ElCarroLoader

Google Drive

Google Drive 是由 Google 开发的文件存储和同步服务。

目前,仅支持 Google Docs

我们需要安装带有 Google Drive 依赖项的 langchain-google-community

pip install langchain-google-community[drive]

查看 使用示例和授权说明

from langchain_google_community import GoogleDriveLoader

Firestore (原生模式)

Google Cloud Firestore 是一个为自动扩展、高性能和简化应用开发而构建的 NoSQL 文档数据库。 安装 Python 包:

pip install langchain-google-firestore

请参见 使用示例

from langchain_google_firestore import FirestoreLoader

Firestore (Datastore 模式)

Google Cloud Firestore 在 Datastore 模式下 是一个为自动扩展、高性能和简化应用开发而构建的 NoSQL 文档数据库。 Firestore 是 Datastore 的最新版本,并引入了多个改进。 安装 python 包:

pip install langchain-google-datastore

请参见 使用示例

from langchain_google_datastore import DatastoreLoader

Memorystore 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 MemorystoreLoader

Spanner

Google Cloud Spanner 是一个完全托管的、关键任务的关系数据库服务,运行在 Google Cloud 上,提供全球范围内的事务一致性、高可用性的自动同步复制,以及对两种 SQL 方言的支持:GoogleSQL(ANSI 2011 扩展)和 PostgreSQL。 安装 Python 包:

pip install langchain-google-spanner

查看 使用示例

from langchain_google_spanner import SpannerLoader

语音转文本

Google Cloud Speech-to-Text 是一个由 Google Cloud 中的语音识别模型驱动的音频转录 API。

该文档加载器可以转录音频文件,并将文本结果输出为文档。

首先,我们需要安装带有语音转文本依赖项的 langchain-google-community

pip install langchain-google-community[speech]

请查看 用法示例和授权说明

from langchain_google_community import SpeechToTextLoader

文档转换器

文档 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]

请参见 使用示例

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

向量存储

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, AlloyDBVectorStore

BigQuery 向量搜索

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

Google Cloud BigQuery 向量搜索 BigQuery 向量搜索允许您使用 GoogleSQL 进行语义搜索,使用向量索引以快速但近似的结果,或使用暴力搜索以获得精确结果。

它可以计算欧几里得距离或余弦距离。使用 LangChain 时,我们默认使用欧几里得距离。

我们需要安装几个 Python 包。

pip install google-cloud-bigquery

查看 使用示例

from langchain.vectorstores import BigQueryVectorSearch

Memorystore 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 RedisVectorStore

Spanner

Google Cloud Spanner 是一个完全托管的、关键任务的关系数据库服务,运行在 Google Cloud 上,提供全球范围内的事务一致性、高可用性的自动同步复制,以及对两种 SQL 方言的支持:GoogleSQL(ANSI 2011 及扩展)和 PostgreSQL。
安装 Python 包:

pip install langchain-google-spanner

查看 用法示例

from langchain_google_spanner import SpannerVectorStore

Firestore(原生模式)

Google Cloud Firestore 是一个为自动扩展、高性能和易于应用程序开发而构建的 NoSQL 文档数据库。 安装 Python 包:

pip install langchain-google-firestore

查看 使用示例

from langchain_google_firestore import FirestoreVectorstore

Cloud 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

Cloud 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, PostgresVectorStore

Vertex AI 向量搜索

Google Cloud Vertex AI 向量搜索 来自 Google Cloud,前称为 Vertex AI Matching Engine,提供行业领先的高规模低延迟向量数据库。这些向量数据库通常被称为向量相似性匹配或近似最近邻 (ANN) 服务。

安装 Python 包:

pip install langchain-google-vertexai

查看 使用示例

from langchain_google_vertexai import VectorSearchVectorStore

ScaNN

Google ScaNN (可扩展最近邻) 是一个 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 GoogleDriveRetriever

Vertex AI Search 来自 Google Cloud,允许开发者快速为客户和员工构建基于生成式 AI 的搜索引擎。

我们需要安装 google-cloud-discoveryengine python 包。

pip install google-cloud-discoveryengine

查看 使用示例

from langchain.retrievers import GoogleVertexAISearchRetriever

文档 AI 仓库

文档 AI 仓库 是 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 Text-to-Speech 是一个 Google Cloud 服务,允许开发者合成自然听起来自然的语音,提供100多种声音,支持多种语言和变体。它运用了 DeepMind 在 WaveNet 方面的开创性研究和 Google 强大的神经网络,以提供尽可能高的保真度。

我们需要安装一个 Python 包。

pip install google-cloud-text-to-speech

查看 用法示例和授权说明

from langchain_google_community import TextToSpeechTool

Google 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 GoogleDriveSearchTool

Google Finance

我们需要安装一个python包。

pip install google-search-results

查看用法示例和授权说明

from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

Google Jobs

我们需要安装一个 python 包。

pip install google-search-results

查看用法示例和授权说明

from langchain_community.tools.google_jobs import GoogleJobsQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

Google Lens

查看使用示例和授权说明

from langchain_community.tools.google_lens import GoogleLensQueryRun
from langchain_community.utilities.google_lens import GoogleLensAPIWrapper

Google Places

我们需要安装一个python包。

pip install googlemaps

查看使用示例和授权说明

from langchain.tools import GooglePlacesTool

Google Scholar

我们需要安装一个 Python 包。

pip install google-search-results

查看使用示例和授权说明

from langchain_community.tools.google_scholar import GoogleScholarQueryRun
from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapper

Google 搜索

  • 设置一个自定义搜索引擎,按照 这些说明 操作
  • 从上一步获取 API 密钥和自定义搜索引擎 ID,并将它们分别设置为环境变量 GOOGLE_API_KEYGOOGLE_CSE_ID
from langchain_google_community import GoogleSearchAPIWrapper

有关此包装器的更详细说明,请参阅 此笔记本

我们可以轻松地将此包装器加载为工具(以便与代理一起使用)。我们可以这样做:

from langchain.agents import load_tools
tools = load_tools(["google-search"])

我们需要安装一个 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, AlloyDBChatMessageHistory

Cloud 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

Cloud SQL for MySQL

Cloud SQL for MySQL 是一项完全托管的数据库服务,帮助您在 Google Cloud 上设置、维护、管理和管理 MySQL 关系数据库。 安装 Python 包:

pip install langchain-google-cloud-sql-mysql

请参见 使用示例

from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLChatMessageHistory

Cloud SQL for SQL Server

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, MSSQLChatMessageHistory

Spanner

Google Cloud Spanner 是一个完全托管的、关键任务的关系数据库服务,运行在 Google Cloud 上,提供全球范围内的事务一致性、高可用性的自动同步复制,并支持两种 SQL 方言:GoogleSQL(带扩展的 ANSI 2011)和 PostgreSQL。 安装 Python 包:

pip install langchain-google-spanner

请参见 使用示例

from langchain_google_spanner import SpannerChatMessageHistory

Memorystore 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 MemorystoreChatMessageHistory

Bigtable

Google Cloud Bigtable 是谷歌在 Google Cloud 中完全托管的 NoSQL 大数据数据库服务。 安装 python 包:

pip install langchain-google-bigtable

请参阅 使用示例

from langchain_google_bigtable import BigtableChatMessageHistory

Firestore(本机模式)

Google Cloud Firestore 是一个为自动扩展、高性能和易于应用开发而构建的 NoSQL 文档数据库。 安装 Python 包:

pip install langchain-google-firestore

请参见 使用示例

from langchain_google_firestore import FirestoreChatMessageHistory

Firestore (Datastore 模式)

Google Cloud Firestore 在 Datastore 模式下 是一个为自动扩展、高性能和简化应用开发而构建的 NoSQL 文档数据库。 Firestore 是 Datastore 的最新版本,并引入了多个改进。 安装 Python 包:

pip install langchain-google-datastore

查看 使用示例

from langchain_google_datastore import DatastoreChatMessageHistory

El Carro:Kubernetes 的 Oracle 操作员

Google El Carro Oracle Operator for Kubernetes 提供了一种在 Kubernetes 中运行 Oracle 数据库的方法,作为一个可移植的、开源的、 社区驱动的、无供应商锁定的容器编排系统。

pip install langchain-google-el-carro

查看 用法示例

from langchain_google_el_carro import ElCarroChatMessageHistory

聊天加载器

GMail

Gmail 是由谷歌提供的免费电子邮件服务。
此加载器通过 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 SearchApiAPIWrapper

SerpApi

SerpApi 提供了一个第三方 API 来访问 Google 搜索结果。

查看使用示例和授权说明

from langchain_community.utilities import SerpAPIWrapper

Serper.dev

查看用例示例和授权说明

from langchain_community.utilities import GoogleSerperAPIWrapper

YouTube

YouTube Search 包用于搜索 YouTube 视频,避免使用其受到严格限制的 API。

它使用 YouTube 首页上的表单,并抓取结果页面。

我们需要安装一个 Python 包。

pip install youtube_search

查看 使用示例

from langchain.tools import YouTubeSearchTool

YouTube 音频

YouTube 是一个由 Google 创建的在线视频分享和社交媒体平台。

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

YouTube 字幕

YouTube 是一个由 Google 创建的在线视频分享和社交媒体平台。

我们需要安装 youtube-transcript-api python 包。

pip install youtube-transcript-api

查看 使用示例

from langchain_community.document_loaders import YoutubeLoader

此页面是否有帮助?


您还可以留下详细的反馈 在 GitHub 上