Skip to main content

Momento

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

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

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

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

安装和设置

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

缓存

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

将 Momento 缓存集成到您的应用程序中:

from langchain.cache import 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))

内存

Momento 可以作为大型语言模型的分布式内存存储。

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

from langchain.memory import MomentoChatMessageHistory

向量存储

Momento 向量索引 (MVI) 可以用作向量存储。

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

from langchain_community.vectorstores import MomentoVectorIndex

Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书