Momento
Momento Cache 是世界上第一個真正的無伺服器快取服務,提供即時彈性、擴展到零的能力和極快的效能。
Momento Vector Index 以其最高效率、最易於使用且完全無伺服器的向量索引而脫穎而出。
對於這兩項服務,只需取得 SDK、取得 API 金鑰、在您的程式碼中輸入幾行,即可開始使用。它們共同為您的 LLM 資料需求提供全面的解決方案。
本頁面涵蓋如何在 LangChain 中使用 Momento 生態系統。
安裝與設定
- 在此處註冊免費帳戶 here 以取得 API 金鑰
- 使用
pip install momento
安裝 Momento Python SDK
快取
使用 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
API 參考:MomentoChatMessageHistory
向量儲存庫
Momento Vector Index (MVI) 可以用作向量儲存庫。
請參閱 此筆記本,以逐步了解如何將 MVI 用作向量儲存庫。
from langchain_community.vectorstores import MomentoVectorIndex
API 參考:MomentoVectorIndex