langchain/libs/community/tests/integration_tests/cache
Dmitriy Prokopchuk 53b0a99f37
community: Memcached LLM Cache Integration (#27323)
## 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>
2024-11-07 03:07:59 +00:00
..
fake_embeddings.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
test_astradb.py multiple: langchain 0.2 in master (#21191) 2024-05-08 16:46:52 -04:00
test_azure_cosmosdb_cache.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
test_cassandra.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
test_gptcache.py multiple: langchain 0.2 in master (#21191) 2024-05-08 16:46:52 -04:00
test_memcached_cache.py community: Memcached LLM Cache Integration (#27323) 2024-11-07 03:07:59 +00:00
test_momento_cache.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
test_opensearch_cache.py multiple: langchain 0.2 in master (#21191) 2024-05-08 16:46:52 -04:00
test_redis_cache.py multiple: langchain 0.2 in master (#21191) 2024-05-08 16:46:52 -04:00
test_singlestoredb_cache.py community: add SingleStoreDB semantic cache (#23218) 2024-07-05 09:26:06 -04:00
test_upstash_redis_cache.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00