Add SemanticCache vector index config - #619
Open
omribz156 wants to merge 2 commits into
Open
Conversation
Signed-off-by: Omri SirComp <omribz156@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a configurable vector-index configuration path for SemanticCache, allowing the cache’s vector field to be created with HNSW (or other supported RedisVL vector algorithms) instead of being hardcoded to FLAT, and documents the new configuration in the LLM cache user guide.
Changes:
- Extend
SemanticCacheIndexSchema.from_paramsto acceptvector_index_configand merge it into the vector field attrs while protecting vectorizer-derived attrs (dims,datatype,distance_metric). - Add
vector_index_configplumbing toSemanticCacheconstructor so the schema/index can be created with a non-FLAT algorithm (e.g., HNSW). - Add unit tests for default FLAT behavior, HNSW config acceptance, and invalid config rejection; update the LLM cache notebook with a configuration example.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
redisvl/extensions/cache/llm/schema.py |
Adds vector_index_config support to the semantic cache index schema builder while preventing overrides of derived attrs. |
redisvl/extensions/cache/llm/semantic.py |
Wires vector_index_config through SemanticCache initialization into schema/index creation. |
tests/unit/test_llmcache_schema.py |
Adds unit coverage for FLAT default, HNSW config, and invalid algorithm/override behavior. |
docs/user_guide/03_llmcache.ipynb |
Documents how to configure the semantic cache’s vector index algorithm (example: HNSW). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vishal-bala
reviewed
Sep 3, 2026
vishal-bala
left a comment
Collaborator
There was a problem hiding this comment.
Hi, this is coming along - can you rebase onto main to get changes to allow the CI tests to proceed?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #602.
vector_index_configtoSemanticCacheso the cache vector field can be created with HNSW or other supported vector index options instead of always using FLAT.dims,datatype, anddistance_metricderived from the vectorizer / semantic-cache COSINE behavior.Verification
.venv\Scripts\python.exe -m pytest --noconftest tests/unit/test_llmcache_schema.py.venv\Scripts\python.exe -m black --check redisvl/extensions/cache/llm/schema.py redisvl/extensions/cache/llm/semantic.py tests/unit/test_llmcache_schema.py.venv\Scripts\python.exe -m compileall redisvl/extensions/cache/llm/schema.py redisvl/extensions/cache/llm/semantic.py tests/unit/test_llmcache_schema.py.venv\Scripts\python.exe -c "import json; json.load(open('docs/user_guide/03_llmcache.ipynb', encoding='utf-8')); print('notebook json ok')"git diff --checkI also tried the normal pytest command first, but local execution without
--noconftestis blocked on this Windows machine because the repo autouse fixture invokes Docker Compose and the Docker CLI is not available here.This was implemented with Codex assistance, with the patch kept focused on the cache schema/config path and docs.
Note
Low Risk
Additive constructor option with unchanged default FLAT behavior; risk is mainly misconfigured index settings affecting search performance, not data or auth paths.
Overview
Adds optional
vector_index_configonSemanticCacheso the Redis vector field for prompt embeddings can use HNSW (or other supported algorithms) instead of always FLAT, while dims, datatype, and cosine distance still come from the vectorizer and are rejected if overridden in config.SemanticCacheIndexSchema.from_paramsmerges user config onto the default FLAT attrs and passes the result into index creation; the LLM cache user guide documents HNSW setup and notes that the algorithm is fixed after index creation (recreate withoverwrite=Trueto change it).Unit tests cover default FLAT, HNSW options, invalid algorithms, and blocked overrides of vectorizer-derived fields.
Reviewed by Cursor Bugbot for commit 40297d2. Bugbot is set up for automated code reviews on this repo. Configure here.