fix: prioritize mentioned_at over occurred_start in temporal scoring#177
Closed
fix: prioritize mentioned_at over occurred_start in temporal scoring#177
Conversation
The current temporal scoring logic prioritizes LLM-extracted occurred_start/end over the user-provided mentioned_at timestamp. This causes issues because: 1. mentioned_at is ALWAYS reliably set from the timestamp parameter passed to retain() 2. occurred_start/end is LLM-extracted and non-deterministic (often null) 3. Users expect their explicit timestamps to be used for temporal queries This change reverses the priority so that: 1. mentioned_at (user-provided, reliable) is checked first 2. occurred_start/end (LLM-extracted) is used as fallback when mentioned_at is null Modified 5 locations in retrieval.py: - retrieve_temporal_combined() entry points and neighbors - retrieve_temporal() entry points and neighbors - _get_temporal_entry_points() Added test_temporal_scoring_priority.py with unit tests for the new behavior.
nicoloboschi
requested changes
Jan 19, 2026
Collaborator
nicoloboschi
left a comment
There was a problem hiding this comment.
the assumption of starting from occurred is that users will ask "when X happened" rather than "when I said about X"
since mentioned_at is always NOT NULL (we set now() if not passed) this change will defeat almost entirely the purpose of occurred time extraction
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.
Problem
When users pass a
timestamptoretain(), they expect that timestamp to be used for temporal queries. However, the current implementation prioritizesoccurred_start(LLM-extracted) overmentioned_at(user-provided), causing unintuitive behavior.Current behavior:
The issues:
mentioned_atis always reliably set from the user'stimestampparameteroccurred_startis non-deterministic - depends on LLM extraction, often nullEvidence from testing:
Running the same
retain()call 3 times with identical timestamps:mentioned_atoccurred_start✓occurred_start✓occurred_start✗occurred_start✗occurred_start✗occurred_start✗occurred_start✗occurred_start✓occurred_start✓mentioned_atis 100% reliable.occurred_startis ~44% reliable.Solution
Reverse the priority order so user-provided timestamps take precedence:
Before (current):
After (proposed):
Rationale
mentioned_atwill be null/default and LLM-extracted dates still worktimestampparameter will now "just work" for temporal queriesFiles Changed
hindsight-api/hindsight_api/engine/search/retrieval.pyretrieve_temporal()- 2 occurrencesretrieve_temporal_combined()- 2 occurrences_get_temporal_entry_points()- 1 occurrencehindsight-api/tests/test_temporal_scoring_priority.py(NEW)best_datepriority logicTesting
After this change:
query_timestampwill correctly filter bymentioned_atMigration
No migration needed. This is a behavior change that makes the API work as users expect.