Skip to content

Conversation

@thepatrickchin
Copy link
Contributor

@thepatrickchin thepatrickchin commented Jan 20, 2026

Description

Add similarity_score field to MemoryItem and implement threshold-based filtering in Redis search method with similarity_threshold kwarg

Closes #1433

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • New Features

    • Added similarity-based filtering for search results via a configurable similarity threshold.
    • Search results now surface per-item similarity scores as part of returned memory items.
  • Tests

    • Added tests verifying similarity_score is recorded and that threshold-based filtering excludes appropriate results.

✏️ Tip: You can customize this high-level summary in your review settings.

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>
@thepatrickchin thepatrickchin requested a review from a team as a code owner January 20, 2026 10:20
@copy-pr-bot
Copy link

copy-pr-bot bot commented Jan 20, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Walkthrough

Adds similarity score handling to Redis semantic search: a similarity_threshold search kwarg is accepted and used to filter results by doc.score; each returned MemoryItem now carries an optional similarity_score field.

Changes

Cohort / File(s) Summary
Redis Editor Implementation
packages/nvidia_nat_redis/src/nat/plugins/redis/redis_editor.py
Adds similarity_threshold to search kwargs and logs it. Extracts similarity_score from doc.score, skips items failing the threshold, passes similarity_score into _create_memory_item(), and updates logging to report processed vs filtered counts. Updated _create_memory_item() signature to accept `similarity_score: float
Redis Editor Tests
packages/nvidia_nat_redis/tests/test_redis_editor.py
Adds assertion that similarity_score is set for first search result. New test test_search_with_similarity_threshold_filters_results mocks docs with scores [0.2, 0.6, 0.4] and verifies threshold filtering yields only the expected subset; adjusts mocked JSON fetches accordingly.
Data Model
src/nat/memory/models.py
Adds `similarity_score: float

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main changes: adding similarity scores and threshold filtering to Redis semantic search, matching the PR's core objectives.
Linked Issues check ✅ Passed The PR fully implements both requirements from issue #1433: adds similarity_score field to MemoryItem and implements similarity_threshold parameter for filtering in Redis search.
Out of Scope Changes check ✅ Passed All changes are within scope: MemoryItem model extended with similarity_score, Redis editor implements threshold filtering and score propagation, and tests validate both features.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@willkill07 willkill07 self-assigned this Jan 20, 2026
@willkill07 willkill07 added feature request New feature or request non-breaking Non-breaking change labels Jan 20, 2026
@willkill07
Copy link
Member

/ok to test c6f419d

Copy link
Member

@willkill07 willkill07 left a comment

Choose a reason for hiding this comment

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

Documentation build appears to have failed.

The runner failure is a known transient issue -- working on a fix for that separately.

…ation

- bullet points under kwargs need a blank line

Signed-off-by: Patrick Chin <8509935+thepatrickchin@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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).

@willkill07
Copy link
Member

/ok to test bf1292d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add similarity score to Redis semantic search result items

2 participants