-
Notifications
You must be signed in to change notification settings - Fork 46.7k
fix(memory): increment retrieval_count on search results in holographic memory (#17899) #39664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dusterbloom
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
dusterbloom:fix/holographic-retrieval-count
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Tests for holographic memory retrieval_count increment (#17899). | ||
|
|
||
| retrieval_count was never incremented because FactRetriever.search() | ||
| bypassed store.search_facts(), the only place that bumped the counter. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from plugins.memory.holographic.store import MemoryStore | ||
| from plugins.memory.holographic.retrieval import FactRetriever | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def store(tmp_path): | ||
| db = str(tmp_path / "test_memory.db") | ||
| return MemoryStore(db_path=db, default_trust=0.5, hrr_dim=128) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def retriever(store): | ||
| return FactRetriever(store=store, hrr_dim=128, hrr_weight=0.0) | ||
|
|
||
|
|
||
| class TestRetrievalCount: | ||
| """retrieval_count should be incremented when facts are retrieved.""" | ||
|
|
||
| def test_search_increments_count(self, store, retriever): | ||
| """After searching, retrieval_count should go from 0 to >= 1.""" | ||
| fact_id = store.add_fact("Python is a programming language") | ||
|
|
||
| # Verify starting at 0 | ||
| row = store._conn.execute( | ||
| "SELECT retrieval_count FROM facts WHERE fact_id = ?", (fact_id,) | ||
| ).fetchone() | ||
| assert row["retrieval_count"] == 0 | ||
|
|
||
| # Search and find it | ||
| results = retriever.search("Python", min_trust=0.0) | ||
| assert len(results) >= 1 | ||
|
|
||
| # Verify incremented | ||
| row = store._conn.execute( | ||
| "SELECT retrieval_count FROM facts WHERE fact_id = ?", (fact_id,) | ||
| ).fetchone() | ||
| assert row["retrieval_count"] >= 1 | ||
|
|
||
| def test_multiple_searches_accumulate(self, store, retriever): | ||
| """Multiple searches should keep incrementing.""" | ||
| store.add_fact("Rust is memory safe") | ||
|
|
||
| retriever.search("Rust", min_trust=0.0) | ||
| retriever.search("Rust", min_trust=0.0) | ||
| retriever.search("Rust", min_trust=0.0) | ||
|
|
||
| row = store._conn.execute( | ||
| "SELECT retrieval_count FROM facts WHERE content LIKE '%Rust%'" | ||
| ).fetchone() | ||
| assert row["retrieval_count"] >= 3 | ||
|
|
||
| def test_unrelated_search_no_increment(self, store, retriever): | ||
| """Searching for something else shouldn't increment unrelated facts.""" | ||
| fact_id = store.add_fact("Haskell is purely functional") | ||
| store.add_fact("Rust is memory safe") | ||
|
|
||
| retriever.search("Rust", min_trust=0.0) | ||
|
|
||
| row = store._conn.execute( | ||
| "SELECT retrieval_count FROM facts WHERE fact_id = ?", (fact_id,) | ||
| ).fetchone() | ||
| assert row["retrieval_count"] == 0 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please route this through a locked MemoryStore helper rather than writing
_conndirectly.MemoryStoredeliberately shares one SQLite connection and one_lockfor serialized access (store.py:101-112); this new write bypasses that contract and duplicates the existing counter SQL insearch_facts().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@teknium1 I've implemented this with the locked MemoryStore helper. Might wanna take a look
And following your suggestion, I've wired all the retrieval paths to increment the count.
#73901