Skip to content

fix: unified recall scopes docs to namespace, reports honest scores (#1270) - #1271

Merged
ajianaz merged 3 commits into
developfrom
fix/unified-doc-ns-and-scores-1270
Sep 17, 2026
Merged

ajianaz merged 3 commits into
developfrom
fix/unified-doc-ns-and-scores-1270

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

What

recall_unified_all (default CLI recall, --type all):

  • Document arm is namespace-scoped — new Uteke::doc_search_in(query, limit, mode, namespace) retains only documents whose namespace matches the recall's namespace; NULL-namespace documents are global-view-only (consistent with the memory path and fix: doc list honors --namespace on CLI, HTTP, and MCP (#1268) #1269 doc-list semantics).
  • Document scores are honest rank-based values — the doc result's raw hybrid-RRF sum (~0.016–0.033) is reported instead of (k+1)/(k+1+rank) (which reported 1.000 for rank-0 regardless of query). Rank-based scores must not be normalized to the cosine scale in a mixed list; the RRF merge continues to decide ORDER only.
  • Memory-arm threshold fix — recall_hybrid is called with min_score 0.0 (it filters against pre-boost rank-based scores, per recall: default min_score 0.3 suppresses valid embedding matches (found via AMB benchmark wiring) #1223); the caller's threshold is applied post-merge on the reported scores, so --min/--strict behave consistently on both result types.
  • Documents in unified results now carry their namespace in the output payload.

Why

Short queries on the 12.5k-memory PROD snapshot returned the same document set at the top of every query in every namespace: the doc arm ignored the namespace (_ns unused) and reported rank-derived scores (rank-0 = 1.0) that outrank every memory fusion score (~0.16–0.19). Effectively recall "gadio" and recall "billing" gave identical, namespace-violating results. Full evidence in #1270.

Design note: hybrid doc mode is kept (not semantic-only) because index rebuilds evict chunk: vectors (#1110) — on affected stores the semantic arm returns nothing and docs would vanish from unified results entirely; the FTS arm keeps them discoverable.

Testing

  • cargo fmt --check + cargo clippy --all-targets clean (core+cli)
  • cargo test --workspace: 691 passed, 0 failed (a single-run upgrade::replace_binary "Text file busy" failure is a known env race executing/renaming the debug binary — passes on rerun, unrelated area)
  • E2E on the PROD-snapshot store:
    • recall "gadio|billing|quota" --namespace default → all results [memory] with honest scores ~0.19, no cross-namespace docs, no fake 1.0
    • recall "memory lifecycle" --namespace default → relevant [document] Ch6: Memory Lifecycle (ns=default, score 0.016) surfaces correctly
    • doc search (standalone) unchanged

Closes #1270

…1270)

recall_unified_all (the default CLI recall path) leaked documents
across namespaces and reported rank-derived scores that outranked
every memory:

- doc_search was called without a namespace (its ns param was _ns),
  so documents from any namespace - including NULL-namespace rows -
  appeared in every scoped recall
- doc scores were (k+1)/(k+1+rank): rank-0 reported 1.000 for every
  query, a pure rank function that beat all memory fusion scores
  (~0.16-0.19), flooding short-query results with the same doc set
- min_score was applied inside recall_hybrid against pre-boost
  rank-based scores (#1223), where it filters nothing meaningful

Changes:
- new Uteke::doc_search_in(query, limit, mode, namespace) retains
  only exact-namespace documents; NULL-namespace docs are global-
  view-only, matching the #1269 doc-list semantics
- unified doc arm keeps hybrid mode (index rebuilds evict chunk:
  vectors per #1110 - semantic-only would hide docs on affected
  stores) but reports the raw hybrid RRF sum (~0.016-0.033), same
  rank-based family as memory fusion base scores, never a fake 1.0
- memory arm called with min_score 0.0; the caller's threshold is
  applied post-merge on reported scores so --min/--strict work
- unified document results now carry their namespace

Verified: fmt/clippy clean; workspace 691 tests pass; E2E on a
PROD-snapshot store - short queries return only in-namespace
memories with honest scores, and 'memory lifecycle' surfaces the
ns=default chapter-6 document (0.016) instead of a cross-namespace
1.0 artifact.
Comment thread crates/uteke-core/src/lib.rs Fixed
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

doc_search_in fetched the global top-limit results and only then
retained the requested namespace, so scoped searches could silently
return fewer results than exist when matching docs ranked below the
global top-N. Fetch 4x when scoping (mirrors the entity/category
post-filter heuristic on the memory path) and truncate to limit
after the retain.
// Real cosine from the semantic doc arm — not the
// rank-derived RRF sum (kept in `rrf_sum` only for
// merge ordering).
score: dr.score,
The score comment still said 'real cosine from the semantic doc arm'
from an earlier iteration of this change - it is the raw hybrid RRF
sum, and the min_score filter comment claimed both scales were honest
similarities. Spell out the actual caveat instead: both scales are
rank-based with different magnitudes (memory fusion ~0.2 max vs doc
hybrid ~0.033 max), so thresholds above ~0.033 filter all documents;
use --type memory + a vector strategy when cosine-style thresholding
is needed.
@ajianaz
ajianaz merged commit 8ccc600 into develop Sep 17, 2026
15 checks passed
@ajianaz
ajianaz deleted the fix/unified-doc-ns-and-scores-1270 branch September 17, 2026 11:34
ajianaz added a commit that referenced this pull request Sep 18, 2026
…oc-global design note

- Critical Rule #15: key notes/decisions/findings are saved to uteke memory
  (project room) the moment they are confirmed, with read-back verification —
  recording state is part of the task, not an afterthought (#1270 session).
- Per-issue workflow gains the recording step (step 10).
- Known Limitations: documents are global (NULL namespace) by design; scoped
  unified recall therefore never returns documents (#1271), doc search stays
  the global doc view.
ajianaz added a commit that referenced this pull request Sep 18, 2026
* chore(release): complete v0.18.2 metadata lost in #1278 squash

The #1278 squash carried AGENT.md and CHANGELOG (staged correctly) but lost
the in-place edits applied after staging: Cargo.toml/Cargo.lock stayed 0.18.1
and the README version strings kept v0.18.1. This restores them on top of
develop so the release line is consistent again.

Also moves the #1273 Unreleased changelog entry into [0.18.2] with a note:
both #1270/#1271 (this backport) and #1273 land on main together when the
release is tagged, so the shipped version section must list both.

* fix(release): 0.18.2 version lockstep — bundled skill asset + core contract

Follows #1274 (skill parity test) and #1276 (tiered api_registry / core
contract generation): both artifacts embed the workspace version and went
stale when the 0.18.2 bump was reapplied on top of develop. Bumps the
bundled uteke-memory-skill.md version line and regenerates
docs/core-contract.json via docgen.

* fix(release): sync .agents uteke-memory skill copy to 0.18.2

The skill_bundled_matches_repo_copy parity test requires the bundled asset
(crates/uteke-cli/assets/uteke-memory-skill.md) and the repo wiki copy
(.agents/skills/uteke-memory/SKILL.md) to be byte-identical; only the
bundled side was bumped in the previous commit.

---------

Co-authored-by: ajianaz <[email protected]>
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.

recall: unified --type all floods results with cross-namespace docs scored 1.0 (short queries)

2 participants