Skip to content

Commit a15094c

Browse files
authored
feat: include created_at timestamp in search results (#846)
* feat: include created_at timestamp in search results (closes #465) Surface the existing filed_at metadata as created_at in search result objects returned by search_memories(). Enables temporal reasoning over search hits without additional queries. * Feat: add fallback for missing filed_at metadata
1 parent ecd44f7 commit a15094c

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

mempalace/searcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def search_memories(
411411
"wing": meta.get("wing", "unknown"),
412412
"room": meta.get("room", "unknown"),
413413
"source_file": Path(source).name if source else "?",
414+
"created_at": meta.get("filed_at", "unknown"),
414415
"similarity": round(max(0.0, 1 - effective_dist), 3),
415416
"distance": round(dist, 4),
416417
"effective_distance": round(effective_dist, 4),

tests/test_searcher.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ def test_result_fields(self, palace_path, seeded_collection):
5151
assert "source_file" in hit
5252
assert "similarity" in hit
5353
assert isinstance(hit["similarity"], float)
54+
assert "created_at" in hit
55+
56+
def test_created_at_contains_filed_at(self, palace_path, seeded_collection):
57+
"""created_at surfaces the filed_at metadata from the drawer."""
58+
result = search_memories("JWT authentication", palace_path)
59+
hit = result["results"][0]
60+
assert hit["created_at"] == "2026-01-01T00:00:00"
61+
62+
def test_created_at_fallback_when_filed_at_missing(self):
63+
"""created_at defaults to 'unknown' when filed_at is absent."""
64+
mock_col = MagicMock()
65+
mock_col.query.return_value = {
66+
"ids": [["drawer_no_date"]],
67+
"documents": [["Some text without a date"]],
68+
"metadatas": [[{"wing": "project", "room": "backend", "source_file": "x.py"}]],
69+
"distances": [[0.1]],
70+
}
71+
72+
with patch("mempalace.searcher.get_collection", return_value=mock_col):
73+
result = search_memories("test", "/fake/path")
74+
hit = result["results"][0]
75+
assert hit["created_at"] == "unknown"
5476

5577
def test_search_memories_query_error(self):
5678
"""search_memories returns error dict when query raises."""

0 commit comments

Comments
 (0)