fix: use correct 'score' field for memory relevance filtering#480
Open
jesseturner21 wants to merge 2 commits into
Open
fix: use correct 'score' field for memory relevance filtering#480jesseturner21 wants to merge 2 commits into
jesseturner21 wants to merge 2 commits into
Conversation
The MemoryRecordSummary API returns 'score' not 'relevanceScore'. The old
code used record.get("relevanceScore", config.relevance_score) which would
always fall back to the threshold value, effectively never filtering any
records. Changed to record.get("score", 0.0) to match the actual API
response and the pattern already used in the Strands integration.
Contributor
✅ No Breaking Changes DetectedNo public API breaking changes found in this PR. |
Records without a score field (e.g. exact-match retrievals) should pass through the relevance filter rather than being silently dropped.
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
MemorySessionManager._retrieve_memories_for_llm()to use the correctscorefield from the API response instead of the non-existentrelevanceScorefieldrecord.get("relevanceScore", config.relevance_score)would always fall back to the threshold value itself, meaning filtering never actually removed any recordsscoreinstead ofrelevanceScoreto match the real API response formatAPI Reference: https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_MemoryRecordSummary.html
Fixes #365
Test plan
pytest tests/bedrock_agentcore/memory/test_session.py- 155 passed)pytest tests/bedrock_agentcore/memory/models/test_models.py- 15 passed)retrieve_memory_recordsAPI returns records with ascorefield (confirmedrelevanceScoreis not present in the response)relevance_scorethreshold are correctly filtered outsession_manager.py:862)