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
API Reference: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))
API Reference:set_llm_cache
记忆
Momento 可用作 LLM 的分布式内存存储。
请参阅此笔记本了解如何将 Momento 用作聊天消息历史记录的内存存储的演练。
from langchain.memory import MomentoChatMessageHistory
API Reference:MomentoChatMessageHistory
向量存储
Momento Vector Index (MVI) 可 用作向量存储。
请参阅此笔记本了解如何将 MVI 用作向量存储的演练。
from langchain_community.vectorstores import MomentoVectorIndex
API Reference:MomentoVectorIndex