-
Notifications
You must be signed in to change notification settings - Fork 46.5k
fix(memory/holographic): track retrieval counts across retriever paths #55729
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
BongSuCHOI
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
BongSuCHOI: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.
+142
−11
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
104 changes: 104 additions & 0 deletions
104
tests/plugins/memory/test_holographic_retrieval_count.py
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,104 @@ | ||
| """Regression coverage for holographic fact retrieval counters.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
|
|
||
| import pytest | ||
|
|
||
| from plugins.memory.holographic import HolographicMemoryProvider | ||
| from plugins.memory.holographic import holographic as hrr | ||
|
|
||
|
|
||
| def _make_provider(tmp_path): | ||
| provider = HolographicMemoryProvider( | ||
| config={"db_path": str(tmp_path / "memory_store.db"), "hrr_dim": 64} | ||
| ) | ||
| provider.initialize(session_id="test-session") | ||
| return provider | ||
|
|
||
|
|
||
| def _call_fact_store(provider, **args): | ||
| return json.loads(provider.handle_tool_call("fact_store", args)) | ||
|
|
||
|
|
||
| def _counts_by_id(provider): | ||
| return { | ||
| fact["fact_id"]: fact["retrieval_count"] | ||
| for fact in provider._store.list_facts(limit=20) | ||
| } | ||
|
|
||
|
|
||
| def test_search_increments_retrieval_count_for_returned_facts(tmp_path): | ||
| provider = _make_provider(tmp_path) | ||
| try: | ||
| kept = _call_fact_store( | ||
| provider, | ||
| action="add", | ||
| content='"Hermes" records holographic memory retrieval counts.', | ||
| category="tool", | ||
| )["fact_id"] | ||
| other = _call_fact_store( | ||
| provider, | ||
| action="add", | ||
| content='"Cafe24" deployment cache behavior is unrelated.', | ||
| category="tool", | ||
| )["fact_id"] | ||
|
|
||
| result = _call_fact_store( | ||
| provider, | ||
| action="search", | ||
| query="Hermes holographic retrieval", | ||
| limit=1, | ||
| ) | ||
|
|
||
| assert [fact["fact_id"] for fact in result["results"]] == [kept] | ||
| assert _counts_by_id(provider) == {kept: 1, other: 0} | ||
|
|
||
| _call_fact_store( | ||
| provider, | ||
| action="search", | ||
| query="Hermes holographic retrieval", | ||
| limit=1, | ||
| ) | ||
| assert _counts_by_id(provider) == {kept: 2, other: 0} | ||
| finally: | ||
| provider.shutdown() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("args"), | ||
| [ | ||
| {"action": "probe", "entity": "Hermes", "limit": 2}, | ||
| {"action": "related", "entity": "Hermes", "limit": 2}, | ||
| {"action": "reason", "entities": ["Hermes", "Memory"], "limit": 2}, | ||
| ], | ||
| ) | ||
| def test_structural_retrieval_increments_returned_fact_counts(tmp_path, args): | ||
| if not hrr._HAS_NUMPY: | ||
| pytest.skip("structural holographic retrieval requires numpy") | ||
|
|
||
| provider = _make_provider(tmp_path) | ||
| try: | ||
| _call_fact_store( | ||
| provider, | ||
| action="add", | ||
| content='"Hermes" and "Memory" should update retrieval counters.', | ||
| category="tool", | ||
| ) | ||
| _call_fact_store( | ||
| provider, | ||
| action="add", | ||
| content='"Hermes" and "Cron" share operational context.', | ||
| category="tool", | ||
| ) | ||
|
|
||
| result = _call_fact_store(provider, **args) | ||
| returned_ids = {fact["fact_id"] for fact in result["results"]} | ||
|
|
||
| assert returned_ids | ||
| counts = _counts_by_id(provider) | ||
| for fact_id in returned_ids: | ||
| assert counts[fact_id] == 1 | ||
| finally: | ||
| provider.shutdown() | ||
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.
This probe case has no category, so it takes probe's direct scoring path rather than the category-bank branch that calls
_score_facts_by_vector()(retrieval.py:139-152). Please add a categorized probe assertion so the new bookkeeping in that helper has regression coverage.