Skip to content

Improve the search memories in KeyValueMemory Toolset#1236

Merged
Pooria90 merged 13 commits into
mainfrom
pooria/improve-kv-store
Jul 15, 2026
Merged

Improve the search memories in KeyValueMemory Toolset#1236
Pooria90 merged 13 commits into
mainfrom
pooria/improve-kv-store

Conversation

@Pooria90

@Pooria90 Pooria90 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1249

Adds pluggable relevance ranking to the prebuilt key-value memory toolset. The search_memories tool previously did a plain case-insensitive substring match; it now ranks results through a swappable SearchAlgorithm. Two implementations ship:

  • LexicalSearch (the new zero-dependency default; key-weighted token overlap, exact-key jackpot, multi-term coverage, and a difflib fuzzy fallback for typos).

  • SemanticSearch (opt-in embedding-similarity search that reuses the existing Embedding + VectorBackend infra and keeps a lazily-maintained vector index in sync as memories change).

The whole search layer lives under prebuilt/tools/memory/search/. The KeyValueMemoryToolSet gains a search= argument to select or customize the ranker.

Type of change

  • Bug fix
  • Feature
  • Breaking change
  • Docs
  • Refactor / chore / build / tests

Checklist

  • Lint & format pass (ruff check . && ruff format .)
  • Tests added/updated and pass locally (pytest tests)
  • Docs updated if user-facing behavior changed
  • Breaking changes include migration notes

Notes

Behavior change (non-breaking): search_memories returns 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 default LexicalSearch needs no dependencies or setup.

Swap in semantic search:

from railtracks.prebuilt.tools.memory import SemanticSearch
from railtracks.retrieval.embedding import OpenAIEmbedding
from railtracks.retrieval.stores.vector.backends import InMemoryBackend

memory = rt.prebuilt.KeyValueMemoryToolSet(
    search=SemanticSearch(
        embedding=OpenAIEmbedding(),
        backend=InMemoryBackend(snapshot_path="memory_vectors.json"),  # optional persistence
    ),
)

Pooria90 and others added 10 commits July 9, 2026 18:04
…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.
@Pooria90
Pooria90 marked this pull request as ready for review July 13, 2026 20:13
Amir-R25
Amir-R25 previously approved these changes Jul 14, 2026

@Amir-R25 Amir-R25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks very cool, two nits but LGTM 🚀

Comment thread packages/railtracks/src/railtracks/prebuilt/tools/memory/search/lexical.py Outdated
Comment thread packages/railtracks/src/railtracks/prebuilt/tools/memory/key_value.py Outdated
soulFood5632
soulFood5632 previously approved these changes Jul 14, 2026

@soulFood5632 soulFood5632 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work Pooria

@Pooria90
Pooria90 dismissed stale reviews from soulFood5632 and Amir-R25 via aacf37e July 15, 2026 01:03
@Pooria90
Pooria90 requested a review from Amir-R25 July 15, 2026 01:04

@soulFood5632 soulFood5632 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Pooria90
Pooria90 merged commit 1e72a25 into main Jul 15, 2026
11 checks passed
@Pooria90
Pooria90 deleted the pooria/improve-kv-store branch July 15, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Memory Search

3 participants