Skip to content

fix: use correct 'score' field for memory relevance filtering#480

Open
jesseturner21 wants to merge 2 commits into
mainfrom
fix/memory-relevance-score-field-365
Open

fix: use correct 'score' field for memory relevance filtering#480
jesseturner21 wants to merge 2 commits into
mainfrom
fix/memory-relevance-score-field-365

Conversation

@jesseturner21
Copy link
Copy Markdown
Contributor

Summary

  • Fixed MemorySessionManager._retrieve_memories_for_llm() to use the correct score field from the API response instead of the non-existent relevanceScore field
  • The old code record.get("relevanceScore", config.relevance_score) would always fall back to the threshold value itself, meaning filtering never actually removed any records
  • Updated test fixtures to use score instead of relevanceScore to match the real API response format

API Reference: https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_MemoryRecordSummary.html

Fixes #365

Test plan

  • Unit tests pass (pytest tests/bedrock_agentcore/memory/test_session.py - 155 passed)
  • Model tests pass (pytest tests/bedrock_agentcore/memory/models/test_models.py - 15 passed)
  • Verified against real AWS resources: the retrieve_memory_records API returns records with a score field (confirmed relevanceScore is not present in the response)
  • Confirmed that with the fix, records below the relevance_score threshold are correctly filtered out
  • Matches the pattern already used in the Strands integration (session_manager.py:862)

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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

✅ No Breaking Changes Detected

No 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.
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.

[Bug] Long-term memory relevance filtering uses relevanceScore, but RetrieveMemoryRecords returns score

1 participant