适用于Google Cloud SQL for PostgreSQL的LangChain集成
项目描述
快速入门
为了使用此库,您首先需要完成以下步骤
安装
使用 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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9ef581a780472b6a387d16bc42a53c3a347dc8220a389010271a86f3883659be |
|
MD5 | 4c37b7bb2a6eef30aaeb10972e9cf6bc |
|
BLAKE2b-256 | 2ad4f92ead0490ecbc7ab044b84c9fec942151b27297a6c3baca04ca889a9a11 |