Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
@ fix(ultrawiki): rank the record, not the memory, once events join the fusion
Ruben Lütkee49b6efb61ed
diff --git a/jarvis/ui/web/frontend/src/components/ultrawiki/AskPanel.test.tsx b/jarvis/ui/web/frontend/src/components/ultrawiki/AskPanel.test.tsxindex 0e825c9adb..a5d75e4b24 100644--- a/jarvis/ui/web/frontend/src/components/ultrawiki/AskPanel.test.tsx+++ b/jarvis/ui/web/frontend/src/components/ultrawiki/AskPanel.test.tsx@@ -34,6 +34,9 @@ const HIT: UltraWikiSearchHit = {// the row must render without a grade chip or a context disclosure.rerank_score: null,context: [],+ // Empty means "the item's own stamp IS timestamp_utc" — the shape every+ // leg but the event leg produces.+ recorded_utc: "",};function installFetchMock(routes: Record<string, () => unknown>) {diff --git a/jarvis/ui/web/frontend/src/lib/ultrawikiApi.ts b/jarvis/ui/web/frontend/src/lib/ultrawikiApi.tsindex e4935d023f..df6b0d5331 100644--- a/jarvis/ui/web/frontend/src/lib/ultrawikiApi.ts+++ b/jarvis/ui/web/frontend/src/lib/ultrawikiApi.ts@@ -486,6 +486,7 @@ export interface UltraWikiSearchHit {title: string;snippet: string;permalink: string;+ /** What the hit is ABOUT — an event hit carries the event's own date here. */timestamp_utc: string;/** ORDINAL fused rank score (RRF) — comparable between hits, never absolute. */score: number;@@ -494,6 +495,8 @@ export interface UltraWikiSearchHit {rerank_score: number | null;/** Neighbouring evidence pulled back in after ranking; may be empty. */context: string[];+ /** When the ITEM was recorded; "" means identical to timestamp_utc. */+ recorded_utc: string;}export interface UltraWikiSearchResponse {diff --git a/jarvis/ultrawiki/search.py b/jarvis/ultrawiki/search.pyindex 4806defeaf..6de056b94a 100644--- a/jarvis/ultrawiki/search.py+++ b/jarvis/ultrawiki/search.py@@ -646,6 +646,19 @@ def _fuse(prose, and a vector hit is neither. For an episodic question that orderingis the difference between "on 14 March 2026 in Porto Verde with …" and afragment of the chat that happened to mention it.++ Two properties the event leg makes non-obvious, both enforced here:++ - **One item, one vote per leg.** An itinerary can produce five events, and+ five rows for one ``item_id`` would otherwise stack five RRF+ contributions where every other item gets one. Only an item's BEST rank+ in a leg counts, and ranks are dense over distinct items, so a+ many-event item cannot push the items behind it down either.+ - **Ranking decays the RECORD, not the memory.** The age factor reads+ ``recorded_utc`` (when the item entered the corpus), never the event's+ ``occurred_at``. A note written yesterday about a dinner in 2023 is a+ fresh record; decaying it by the dinner's date demotes it ~65× for+ having remembered something old."""knobs = ranking_settings(cfg)weights = {@@ -664,20 +677,27 @@ def _fuse(("vector", vector_hits),):weight = weights[leg_name]- for rank, hit in enumerate(hits, start=1):+ rank = 0+ for hit in hits:+ labels = matched.setdefault(hit.item_id, [])+ if leg_name in labels:+ continue # this item already voted in this leg+ labels.append(leg_name)+ rank += 1rrf_score[hit.item_id] = (rrf_score.get(hit.item_id, 0.0) + weight / (RRF_K + rank))- labels = matched.setdefault(hit.item_id, [])- if leg_name not in labels:- labels.append(leg_name)representative.setdefault(hit.item_id, hit)if not representative:return []+ recorded = {+ item_id: (base.recorded_utc or base.timestamp_utc)+ for item_id, base in representative.items()+ }by_recency = sorted(representative,- key=lambda item_id: _recency_key(representative[item_id].timestamp_utc),+ key=lambda item_id: _recency_key(recorded[item_id]),reverse=True,)total = len(by_recency)@@ -693,7 +713,7 @@ def _fuse(score=(rrf_score[item_id]* _signal_factor(base, signals or {})- * _age_factor(base.timestamp_utc, half_life, now=now)+ * _age_factor(recorded[item_id], half_life, now=now)+ recency_bonus[item_id]),matched_by=tuple(matched[item_id]),diff --git a/jarvis/ultrawiki/types.py b/jarvis/ultrawiki/types.pyindex fe9d868417..e9774cf2d0 100644--- a/jarvis/ultrawiki/types.py+++ b/jarvis/ultrawiki/types.py@@ -223,6 +223,16 @@ class SearchResult:whenever that optional stage was skipped or failed. ``context`` carriesthe neighbouring evidence pulled back in after ranking (design doc 03,"context expansion"); empty when expansion was skipped or unavailable.++ **Two clocks, deliberately.** ``timestamp_utc`` is what this hit is ABOUT+ and is what the surface shows — for an event hit that is when the event+ happened, not when the message describing it was written.+ ``recorded_utc`` is when the underlying item entered the corpus, i.e. how+ old the RECORD is, and is the only stamp ranking may decay by. Conflating+ them punishes a note written yesterday about a dinner three years ago as+ if the note itself were three years old. Empty means "identical to+ ``timestamp_utc``", which is the case for every leg that reads items+ directly."""item_id: int@@ -235,6 +245,7 @@ class SearchResult:matched_by: tuple[str, ...] = () # e.g. ("keyword", "vector")rerank_score: float | None = None # absolute 0-10 grade, None = not rerankedcontext: tuple[str, ...] = () # neighbouring sections/messages+ recorded_utc: str = "" # when the ITEM was recorded; "" = same as timestamp_utc@dataclass(frozen=True, slots=True)diff --git a/tests/unit/ultrawiki/test_search.py b/tests/unit/ultrawiki/test_search.pyindex 6457eb6e1b..170a92db14 100644--- a/tests/unit/ultrawiki/test_search.py+++ b/tests/unit/ultrawiki/test_search.py@@ -156,6 +156,7 @@ def make_result(score: float = 0.5,title: str | None = None,snippet: str | None = None,+ recorded_utc: str = "",) -> SearchResult:return SearchResult(item_id=item_id,@@ -166,6 +167,7 @@ def make_result(timestamp_utc=timestamp_utc,score=score,matched_by=matched_by,+ recorded_utc=recorded_utc,)@@ -1110,3 +1112,67 @@ async def test_cache_eviction_keeps_the_size_bounded(store, monkeypatch):# "one" was evicted (oldest); asking again re-embeds.await hybrid_search(store, cfg, "one")assert len(fake.calls) == 4+++# ---------------------------------------------------------------------------+# Fusion and the event leg (P5 review, finding 7)+# ---------------------------------------------------------------------------+++def test_fusion_decays_the_record_not_the_memory():+ """The age factor answers "how stale is this note", not "how long ago did+ this happen". An event card carries the event's date in ``timestamp_utc``,+ so decaying by that demotes a note written yesterday about a dinner three+ years ago by ~65x for having remembered something old."""+ from jarvis.ultrawiki.search import _fuse++ fresh = (datetime.now(UTC) - timedelta(days=1)).isoformat().replace("+00:00", "Z")+ old_event = make_result(+ 1,+ timestamp_utc="2023-03-14T19:30:00Z",+ matched_by=("event",),+ recorded_utc=fresh,+ )+ plain = make_result(2, timestamp_utc=fresh)++ fused = _fuse([plain], [], cfg=make_cfg(), event_hits=[old_event])+ by_item = {hit.item_id: hit for hit in fused}+ # Same single-leg RRF contribution on both, so any gap is pure decay.+ assert by_item[1].score == pytest.approx(by_item[2].score, rel=0.02)+ # The date the user asked about still survives for display.+ assert by_item[1].timestamp_utc == "2023-03-14T19:30:00Z"+++def test_a_multi_event_item_votes_once_in_the_event_leg():+ """An itinerary can produce five events. Five rows for one item would+ stack five RRF contributions where every other item gets one."""+ from jarvis.ultrawiki.search import _fuse++ itinerary = [+ make_result(1, matched_by=("event",), title=f"leg {n}") for n in range(5)+ ]+ single = [make_result(2, matched_by=("event",))]++ fused = _fuse(+ [], [], cfg=make_cfg(recency_half_life_days=0.0), event_hits=[*itinerary, *single]+ )+ by_item = {hit.item_id: hit for hit in fused}+ # Item 1 keeps rank 1 and item 2 gets the NEXT dense rank, not rank 6 —+ # a many-event item must not push the items behind it down either.+ assert by_item[1].score == pytest.approx(1.0 / (RRF_K + 1), abs=1e-5)+ assert by_item[2].score == pytest.approx(1.0 / (RRF_K + 2), abs=1e-5)+ assert by_item[1].matched_by == ("event",)+++def test_an_item_matched_by_two_legs_still_counts_both():+ from jarvis.ultrawiki.search import _fuse++ fused = _fuse(+ [make_result(1)],+ [make_result(1, matched_by=("vector",))],+ cfg=make_cfg(recency_half_life_days=0.0),+ event_hits=[make_result(1, matched_by=("event",))],+ )+ assert len(fused) == 1+ assert set(fused[0].matched_by) == {"event", "keyword", "vector"}+ assert fused[0].score == pytest.approx(3.0 / (RRF_K + 1), abs=1e-3)