Memcached
Memcached 是一個免費且開放原始碼、高效能、分散式記憶體物件快取系統,本質上是通用的,但旨在透過減輕資料庫負載來加速動態 Web 應用程式。
本頁面涵蓋如何將 Memcached 與 langchain 搭配使用,使用 pymemcache 作為用戶端連線到已在執行的 Memcached 執行個體。
安裝與設定
pip install pymemcache
LLM 快取
將 Memcached 快取整合到您的應用程式
from langchain.globals import set_llm_cache
from langchain_openai import OpenAI
from langchain_community.cache import MemcachedCache
from pymemcache.client.base import Client
llm = OpenAI(model="gpt-3.5-turbo-instruct", n=2, best_of=2)
set_llm_cache(MemcachedCache(Client('localhost')))
# The first time, it is not yet in cache, so it should take longer
llm.invoke("Which city is the most crowded city in the USA?")
# The second time it is, so it goes faster
llm.invoke("Which city is the most crowded city in the USA?")
在範例筆記本中瞭解更多資訊