跳转到主要内容

Google Cloud Memorystore的LangChain集成

项目描述

preview pypi versions

快速入门

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

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

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

  3. 启用Google Memorystore for Redis API。

  4. 设置身份验证。

安装

使用pip在此虚拟环境中安装此库。 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-memorystore-redis

Windows

pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install langchain-google-memorystore-redis

向量存储使用

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

from langchain_google_memorystore_redis import RedisVectorStore

redis_client = redis.from_url("redis://127.0.0.1:6379")

embeddings_service = VertexAIEmbeddings(model_name="textembedding-gecko@003")
vectorstore = RedisVectorStore(
    client=redis_client,
    index_name="my_vector_index",
    embeddings=embeddings_service
)

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

文档加载器使用

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

from langchain_google_memorystore_redis import MemorystoreDocumentLoader


loader = MemorystoreDocumentLoader(
    client=redis_client,
    key_prefix="docs:",
    content_fields=set(["page_content"]),
)
docs = loader.lazy_load()

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

聊天消息历史使用

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

from langchain_google_memorystore_redis import MemorystoreChatMessageHistory


history = MemorystoreChatMessageHistory(
    client=redis_client,
    session_id="my-session_id"
)

查看完整的 Chat Message History 教程。

贡献

欢迎并强烈鼓励对该库的贡献。

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

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

许可证

Apache 2.0 - 有关更多信息,请参阅 LICENSE

免责声明

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

项目详情


下载文件

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

源分布

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

构建分布

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页