Skip to main content
在 GitHub 上打开

Momento

Momento Cache 是世界上第一个真正的无服务器缓存服务,提供即时弹性,可扩展到零 功能,以及超快的性能。

Momento Vector Index 是效率最高、最易用、完全无服务器的矢量索引。

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

本页介绍了如何在 LangChain 中使用 Momento 生态。

安装和设置

  • 在此处注册免费帐户以获取 API 密钥
  • 安装 Momento Python SDKpip install momento

缓存

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

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

from langchain.cache import MomentoCache
API 参考:MomentoCache

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

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

# Instantiate the Momento client
cache_client = CacheClient(
Configurations.Laptop.v1(),
CredentialProvider.from_environment_variable("MOMENTO_API_KEY"),
default_ttl=timedelta(days=1))

# Choose a Momento cache name of your choice
cache_name = "langchain"

# Instantiate the LLM cache
set_llm_cache(MomentoCache(cache_client, cache_name))
API 参考:set_llm_cache

存储

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

有关如何将 Momento 用作聊天消息历史记录的内存存储的演练,请参阅此笔记本

from langchain.memory import MomentoChatMessageHistory

矢量存储

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

有关如何将 MVI 用作矢量存储的演练,请参阅此笔记本

from langchain_community.vectorstores import MomentoVectorIndex
API 参考:MomentoVectorIndex