-
Couldn't load subscription status.
- Fork 59
Add LangCache wrapper (LLM cache extension) with configurable distance scale #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Implement LangCacheWrapper as BaseLLMCache extension - Support semantic and exact search strategies - Add distance_threshold support (converts to similarity_threshold) - Add attributes filtering for metadata-based searches - Fix SDK integration issues: - Use correct response model attributes (entry_id, data) - Remove incorrect context manager usage - Convert similarity to distance (1.0 - similarity) - Handle optional attributes in store operations - Add comprehensive unit tests (16 tests) - All 444 unit tests passing - Type checking, formatting, and linting passing
…redis) and convert accordingly\n\n- Add distance_scale option to LangCacheWrapper (default: normalized)\n- Convert distance_threshold to similarity_threshold based on scale\n- Convert returned similarity to vector_distance based on scale\n- No change to SemanticCache behavior; opened issue #407 to track threshold inconsistencies there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a LangCache-based LLM cache wrapper with configurable distance scale and fixes an async connection parameter in AsyncSearchIndex. It also introduces unit/integration tests and updates packaging to include an optional langcache extra.
- Add LangCacheWrapper with exact/semantic search, consistent hit shape, and distance scale support ("normalized" or "redis")
- Fix AsyncSearchIndex.connect to pass url kwarg to the connection factory; add integration test
- Update packaging: add langcache extra; adjust Python requirement
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_langcache_wrapper.py | New unit tests for LangCacheWrapper covering init, store/check paths, threshold conversion, and delete/update behavior. |
| tests/integration/test_async_search_index.py | Adds regression test ensuring AsyncSearchIndex.connect accepts redis_url and connects successfully despite deprecation. |
| redisvl/index/index.py | Fixes async connect to call RedisConnectionFactory with url=redis_url (consistent with factory’s API). |
| redisvl/extensions/cache/llm/langcache.py | Implements LangCacheWrapper with distance scale conversions, sync/async store/check/delete, and consistent CacheHit output. |
| redisvl/extensions/cache/llm/init.py | Re-exports LangCacheWrapper in the llm package namespace. |
| pyproject.toml | Adds optional dependency extra for langcache and tightens the minimum Python version to 3.9.2. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…type in check/acheck to Optional[Dict[str, Any]]\n- Clarify docstrings for distance_threshold conversion for both scales\n- Factor helpers: _similarity_threshold, _build_search_kwargs, _hits_from_response to reduce duplication
|
Addressed review feedback:
|
… in Redis connection factory to allow cluster/non-cluster assignments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me! Left a couple comments that I think we should sync on
…ction flag; update tests accordingly
… AsyncSearchIndex callers; tests: fix schema prefix typo
|
Fully deprecated |
…dd tests; remove unused import in CLI
0c5761a to
b760113
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Summary
Add a LangCache wrapper to RedisVL LLM cache extensions so users can leverage LangCache for semantic caching via the familiar
BaseLLMCacheinterface. Also make the wrapper’s distance threshold semantics explicit and configurable so users can swap it out for an existingSemanticCacheinstance easily.Motivation
What’s included
LangCacheWrapperimplementingBaseLLMCache(sync + async) that talks to the LangCache service:store/checkAPIsvector_distance) compatible with existing callersdistance_scale:"normalized": interpretdistance_thresholdas 0–1 semantic distance; converts to/from similarity (1 - d)"redis": interpretdistance_thresholdas native COSINE [0–2]; converts usingnorm_cosine_distance/denorm_cosine_distanceUsage
Docs
Related
SemanticCache