Skip to content

feat(cache): add SemanticCache for caching LLM responses - #61

Merged
booleanhunter merged 3 commits into
mainfrom
feat/semantic-cache
Dec 3, 2026
Merged

booleanhunter merged 3 commits into
mainfrom
feat/semantic-cache

Conversation

@booleanhunter

Copy link
Copy Markdown
Member
  • SemanticCache.create() makes a cache that stores prompt and response pairs in Redis and finds them again by the meaning of the prompt. check() returns the nearest entries within a cosine distance threshold, and an empty array on a miss.

  • An entry's id is a SHA-256 hash of the prompt and its filters, so storing the same prompt again replaces the entry.

  • Entries can have a TTL, set on the cache or on one store(), which a cache hit resets by default. Filterable fields, metadata, update(), drop(), clear() and delete() are included.

  • Uses HuggingFaceVectorizer with redis/langcache-embed-v2 if no vectorizer given, with CLS pooling and no normalization.

  • Adds a semantic cache guide to the docs, and updates README.

  • Differences from RedisVL Python: hits are camelCase typed objects, there is no returnFields option, an existing index is only checked for vector size, drop() returns a count, clear() removes only the documents the index can see, and a TTL must be a positive integer. Not included: telemetry, the LangCache REST classes, and create_index=False.

  • The tests use a fake vectorizer, so CI does not download a model.

- add SearchIndex.key(id), which builds the full Redis key from the index prefix and key separator
- build fetch() and fetchMany() keys with key(), so they read the key that load() writes
- strip trailing separators without a regular expression, so separators such as . | and * work
- mention key() in the user guide
@booleanhunter

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T08:56:37.809609Z 718cebc Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 718cebcb54

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- add SemanticCache, which stores prompt and response pairs in Redis and finds them again by the meaning of the prompt
- match prompts within a cosine distance threshold that can be set on the cache or on each call
- identify entries by a hash of the prompt and filters, so storing the same prompt again replaces the entry
- support entry TTLs that a cache hit can reset, filterable fields, metadata, update, drop, clear and delete
- default to the redis/langcache-embed-v2 model through HuggingFaceVectorizer when no vectorizer is given
- export SemanticCache and its types
- add a user guide page for SemanticCache and list it in the sidebar
- add a semantic cache section and example to the README
- describe the range, text and hybrid queries in the README features list
- update the introduction page
@booleanhunter booleanhunter self-assigned this Dec 3, 2026
@booleanhunter booleanhunter added the enhancement New feature or request label Dec 3, 2026
@booleanhunter
booleanhunter merged commit 38db272 into main Dec 3, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant