Improve the search memories in KeyValueMemory Toolset#1236
Merged
Conversation
…ching - Introduced LexicalSearch class for weighted token-overlap ranking. - Added LexicalSearchConfig for tunable scoring weights. - Updated KeyValueMemoryToolSet to support search algorithms. - Enhanced search_memories method to utilize new search functionality. - Added unit tests for LexicalSearch and its configuration.
…SearchAlgorithm into distinct modules
…ue memory retrieval
Pooria90
marked this pull request as ready for review
July 13, 2026 20:13
Amir-R25
previously approved these changes
Jul 14, 2026
Amir-R25
left a comment
Collaborator
There was a problem hiding this comment.
Looks very cool, two nits but LGTM 🚀
Amir-R25
approved these changes
Jul 15, 2026
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
Closes #1249
Adds pluggable relevance ranking to the prebuilt key-value memory toolset. The
search_memoriestool previously did a plain case-insensitive substring match; it now ranks results through a swappableSearchAlgorithm. Two implementations ship:LexicalSearch(the new zero-dependency default; key-weighted token overlap, exact-key jackpot, multi-term coverage, and adifflibfuzzy fallback for typos).SemanticSearch(opt-in embedding-similarity search that reuses the existingEmbedding+VectorBackendinfra and keeps a lazily-maintained vector index in sync as memories change).The whole search layer lives under
prebuilt/tools/memory/search/. TheKeyValueMemoryToolSetgains asearch=argument to select or customize the ranker.Type of change
Checklist
ruff check . && ruff format .)pytest tests)Notes
Behavior change (non-breaking):
search_memoriesreturns the same"- key: value"format and same tool signature, but results are now relevance-ranked rather than raw substring matches. Zero-config usage is unchanged; the defaultLexicalSearchneeds no dependencies or setup.Swap in semantic search: