mirror of
https://github.com/hwchase17/langchain.git
synced 2025-04-30 12:55:25 +00:00
## Description This PR adds support for Memcached as a usable LLM model cache by adding the ```MemcachedCache``` implementation relying on the [pymemcache](https://github.com/pinterest/pymemcache) client. Unit test-wise, the new integration is generally covered under existing import testing. All new functionality depends on pymemcache if instantiated and used, so to comply with the other cache implementations the PR also adds optional integration tests for ```MemcachedCache```. Since this is a new integration, documentation is added for Memcached as an integration and as an LLM Cache. ## Issue This PR closes #27275 which was originally raised as a discussion in #27035 ## Dependencies There are no new required dependencies for langchain, but [pymemcache](https://github.com/pinterest/pymemcache) is required to instantiate the new ```MemcachedCache```. ## Example Usage ```python3 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?") ``` --------- Co-authored-by: Erick Friis <erick@langchain.dev> |
||
---|---|---|
.. | ||
adapters | ||
agent | ||
cache | ||
callbacks | ||
chains | ||
chat_message_histories | ||
chat_models | ||
cross_encoders | ||
document_compressors | ||
document_loaders | ||
document_transformers | ||
embeddings | ||
examples | ||
graph_vectorstores | ||
graphs | ||
indexes | ||
llms | ||
memory | ||
prompts | ||
retrievers | ||
smith/evaluation | ||
storage | ||
tools | ||
utilities | ||
vectorstores | ||
__init__.py | ||
.env.example | ||
conftest.py | ||
test_compile.py | ||
test_dalle.py | ||
test_document_transformers.py | ||
test_long_context_reorder.py | ||
test_nuclia_transformer.py | ||
test_pdf_pagesplitter.py |