Skip to main content
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

# 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 Vector Index(MVI)可用作向量存储。 查看此 notebook,了解如何将 MVI 用作向量存储。
from langchain_community.vectorstores import MomentoVectorIndex