Add similarity scores and threshold filtering to Redis semantic search#1434
Conversation
Add similarity_score field to MemoryItem and implement threshold-based filtering in Redis search method Signed-off-by: Patrick Chin <8509935+thepatrickchin@users.noreply.github.com>
WalkthroughAdds similarity score handling to Redis semantic search: a Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RedisEditor as Editor
participant EmbeddingService as Embeddings
participant Redis
participant Storage as JSONStore
Client->>Editor: search(query, top_k, similarity_threshold?)
Editor->>Embeddings: embed(query)
Embeddings-->>Editor: vector
Editor->>Redis: semantic search(vector, top_k)
Redis-->>Editor: docs with doc.score
Editor->>Editor: filter docs by similarity_threshold (doc.score <= threshold)
Editor->>JSONStore: fetch JSON for kept docs
JSONStore-->>Editor: doc JSONs
Editor->>Client: [MemoryItem{..., similarity_score}] list
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/ok to test c6f419d |
willkill07
left a comment
There was a problem hiding this comment.
Documentation build appears to have failed.
The runner failure is a known transient issue -- working on a fix for that separately.
packages/nvidia_nat_redis/src/nat/plugins/redis/redis_editor.py
Outdated
Show resolved
Hide resolved
…ation - bullet points under kwargs need a blank line Signed-off-by: Patrick Chin <8509935+thepatrickchin@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/nvidia_nat_redis/src/nat/plugins/redis/redis_editor.py`:
- Around line 126-129: Validate and coerce similarity_threshold from kwargs
(e.g., in the block where similarity_threshold = kwargs.get(...)) by checking
isinstance/try-converting to float and setting a safe default or None on
failure; then when iterating search results (references to doc.score in the
vector search loop), ensure doc.score is not None and is numeric before
converting to float or comparing—skip or treat non-numeric scores as
below-threshold. Update the comparison logic to only compare when both floats
are valid and use a defined fallback behavior (e.g., treat invalid threshold as
no threshold or treat invalid score as failing the threshold check).
|
/ok to test bf1292d |
|
/merge |
Description
Add
similarity_scorefield toMemoryItemand implement threshold-based filtering in Redis search method withsimilarity_thresholdkwargCloses #1433
By Submitting this PR I confirm:
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.