project-nomad/admin/app/controllers
jakeaturner 65f96ee1e1 fix(rag): improve context-reliance hedging and use heading metadata at query time
Users often saw the assistant disclaim ("Sorry, I couldn't find specific
context regarding X, but here's a general answer...") even when material
that directly answered the query was embedded. Two compounding causes,
both on the read/generation side:

1. The rag_context system prompt explicitly authorized the hedge: it told
   the model to fall back to general knowledge and "acknowledge the
   limitations," and mandated "According to the information available..."
   citations that pushed small models into meta-commentary preambles.
   Rewrote it to treat the retrieved context as the primary, authoritative
   source, lead with the answer, fall back to general knowledge *silently*,
   and never emit "couldn't find specific context" phrasing, while still allowing
   the model itself to make some "sanity-check" decisions if the retrieved context
   seems wildly incorrect or unrelated to the user's query.

2. The injected context labeled each block with a raw relevance score
   (e.g. "Relevance: 42.3%"). nomic-embed cosine scores for genuinely
   relevant passages sit ~0.4-0.6, so the number primed the model to
   distrust correct context. Dropped the model-visible score (it stays in
   the logs) and replaced it with a neutral source-title label.

Also added a conservative, score-scaled heading boost in rerankResults:
when query keywords match a chunk's section/article title (ZIM metadata we
already fetch), nudge its rank. Same diminishing-returns shape as the
existing boosts and gated behind the existing semantic-quality threshold,
so it can't promote a weak match.

Scope note: this removes the visible hedge and improves ranking of
already-retrieved chunks. It does NOT fix retrieval recall — diluted
1500-token chunks that never reach dense search's top-k are unaffected.
That's a follow-up (smaller chunks + BM25/RRF hybrid).
2026-06-03 21:58:28 -07:00
..
benchmark_controller.ts fix(security): SSRF validation for map downloads and error sanitization (CWE-918, CWE-209) (#552) 2026-04-21 14:26:28 -07:00
chats_controller.ts fix(security): SSRF validation for map downloads and error sanitization (CWE-918, CWE-209) (#552) 2026-04-21 14:26:28 -07:00
collection_updates_controller.ts fix(security): path traversal and SSRF protections from pre-launch audit 2026-03-11 14:08:09 -07:00
docs_controller.ts fix(Docs): fix doc rendering 2025-07-11 15:31:07 -07:00
downloads_controller.ts feat(downloads): rich progress, friendly names, cancel, and live status (#554) 2026-04-03 14:26:50 -07:00
easy_setup_controller.ts feat(AI): enable remote AI chat host 2026-04-03 14:26:50 -07:00
home_controller.ts fix(OSM): osm installation 2025-08-20 23:05:19 -07:00
maps_controller.ts feat(Maps): regional map downloads via go-pmtiles extract (#780) 2026-05-20 10:16:00 -07:00
ollama_controller.ts fix(rag): improve context-reliance hedging and use heading metadata at query time 2026-06-03 21:58:28 -07:00
rag_controller.ts refactor(KB): typed failure codes for embedSingleFile + accurate HTTP status 2026-05-20 10:16:00 -07:00
settings_controller.ts feat(AI): enable flash_attn by default and disable ollama cloud (#616) 2026-04-03 14:26:50 -07:00
system_controller.ts fix(security): SSRF validation for map downloads and error sanitization (CWE-918, CWE-209) (#552) 2026-04-21 14:26:28 -07:00
zim_controller.ts feat(Content): custom ZIM library sources with pre-seeded mirrors (#593) 2026-05-20 10:16:00 -07:00