Skip to main content

Momento

Momento Cache 是全球首个真正的无服务器缓存服务,提供即时弹性、零扩展能力和超快性能。

Momento Vector Index 突出表现为最具生产力、最易于使用的完全无服务器向量索引。

对于这两项服务,只需获取 SDK,获取 API 密钥,在代码中输入几行代码,就可以开始使用。它们共同为您的 LLM 数据需求提供全面的解决方案。

本页面介绍如何在 LangChain 中使用 Momento 生态系统。

安装与设置

  • 这里注册一个免费账户以获取API密钥
  • 使用 pip install momento 安装Momento Python SDK

缓存

将 Momento 用作无服务器、分布式、低延迟的缓存,用于 LLM 提示和响应。标准缓存是 Momento 用户在任何环境中的主要使用案例。

要将 Momento Cache 集成到您的应用程序中:

from langchain.cache import MomentoCache

然后,使用以下代码进行设置:

from datetime import timedelta
from momento import CacheClient, Configurations, CredentialProvider
from langchain.globals import set_llm_cache

# 实例化 Momento 客户端
cache_client = CacheClient(
Configurations.Laptop.v1(),
CredentialProvider.from_environment_variable("MOMENTO_API_KEY"),
default_ttl=timedelta(days=1))

# 选择一个您喜欢的 Momento 缓存名称
cache_name = "langchain"

# 实例化 LLM 缓存
set_llm_cache(MomentoCache(cache_client, cache_name))

内存

Momento 可以用作 LLM 的分布式内存存储。

请参见 这个笔记本 以了解如何将 Momento 用作聊天消息历史的内存存储。

from langchain.memory import MomentoChatMessageHistory

向量存储

Momento Vector Index (MVI) 可用作向量存储。

请参阅 此笔记本 了解如何将 MVI 用作向量存储。

from langchain_community.vectorstores import MomentoVectorIndex

此页面是否有帮助?


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