跳转到主要内容

适用于Google Cloud SQL for PostgreSQL的LangChain集成

项目描述

preview pypi versions

快速入门

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

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

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

  3. 启用Cloud SQL Admin API。

  4. 设置身份验证。

安装

使用 venv 在虚拟环境中安装此库。 venv 是一种创建隔离Python环境的工具。这些隔离的环境可以有不同的Python包版本,这允许您将一个项目的依赖项与其他项目的依赖项隔离开来。

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

支持的Python版本

Python >= 3.8

Mac/Linux

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

Windows

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

示例用法

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

向量存储使用

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

from langchain_google_cloud_sql_pg import PostgresVectorstore, PostgresEngine
from langchain.embeddings import VertexAIEmbeddings


engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database")
engine.init_vectorstore_table(
    table_name="my-table",
    vector_size=768,  # Vector size for `VertexAIEmbeddings()`
)
embeddings_service = VertexAIEmbeddings(model_name="textembedding-gecko@003")
vectorstore = PostgresVectorStore.create_sync(
    engine,
    table_name="my-table",
    embeddings=embedding_service
)

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

文档加载器使用

使用文档加载器将数据作为文档加载。

from langchain_google_cloud_sql_pg import PostgresEngine, PostgresLoader


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

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

聊天消息历史使用

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

from langchain_google_cloud_sql_pg import PostgresChatMessageHistory, PostgresEngine


engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database")
engine.init_chat_history_table(table_name="my-message-store")
history = PostgresChatMessageHistory.create_sync(
    engine,
    table_name="my-message-store",
    session_id="my-session_id"
)

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

贡献

欢迎并鼓励对库的贡献。

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

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

免责声明

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

项目详情


下载文件

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

源代码分发

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

构建分发

langchain_google_cloud_sql_pg-0.10.0-py3-none-any.whl (39.1 kB 查看哈希值)

上传时间 Python 3

由以下机构支持