跳转到主要内容

Google Cloud AlloyDB for PostgreSQL的LangChain集成

项目描述

preview pypi versions

快速入门

为了使用此库,您首先需要完成以下步骤

  1. 选择或创建一个云平台项目。

  2. 为您的项目启用计费。

  3. 启用AlloyDB API。

  4. 设置身份验证。

安装

使用pip在此virtualenv中安装此库。 virtualenv是一种创建隔离Python环境的工具。它解决的问题主要是依赖性和版本,以及间接的权限。

使用virtualenv,您可以在无需系统安装权限且不与已安装的系统依赖冲突的情况下安装此库。

支持的Python版本

Python >= 3.8

Mac/Linux

pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install langchain-google-alloydb-pg

Windows

pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install langchain-google-alloydb-pg

示例用法

代码示例和代码片段位于samples/文件夹中。

向量存储使用

使用向量存储存储嵌入数据并执行向量搜索。

from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBVectorStore
from langchain_google_vertexai import VertexAIEmbeddings


engine = AlloyDBEngine.from_instance("project-id", "region", "my-cluster", "my-instance", "my-database")
embeddings_service = VertexAIEmbeddings(model_name="textembedding-gecko@003")
vectorstore = AlloyDBVectorStore.create_sync(
    engine,
    table_name="my-table",
    embedding_service=embeddings_service
)

查看完整的向量存储教程。

文档加载器使用

使用文档加载器将数据加载为LangChain Document

from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBLoader


engine = AlloyDBEngine.from_instance("project-id", "region", "my-cluster", "my-instance", "my-database")
loader = AlloyDBLoader.create_sync(
    engine,
    table_name="my-table-name"
)
docs = loader.lazy_load()

查看完整的文档加载器教程。

聊天消息历史使用

使用 ChatMessageHistory 来存储消息并向LLMs提供对话历史。

from langchain_google_alloydb_pg import AlloyDBChatMessageHistory, AlloyDBEngine


engine = AlloyDBEngine.from_instance("project-id", "region", "my-cluster", "my-instance", "my-database")
history = AlloyDBChatMessageHistory.create_sync(
    engine,
    table_name="my-message-store",
    session_id="my-session-id"
)

查看完整的 聊天消息历史教程

贡献

欢迎并向本库贡献,并强烈鼓励。

有关如何开始的信息,请参阅 CONTRIBUTING

请注意,该项目以贡献者行为准则发布。通过参与此项目,您同意遵守其条款。有关更多信息,请参阅 行为准则

许可证

Apache 2.0 - 更多信息请参阅 LICENSE

免责声明

这不是一个官方支持的Google产品。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

此版本没有可用的源代码分发文件。请参阅 生成分发存档的教程

构建分发

langchain_google_alloydb_pg-0.7.0-py3-none-any.whl (40.5 kB 查看哈希值)

上传时间 Python 3

由以下支持