project-nomad/admin/app/controllers
Chris Sherwood 5a72560929 fix(AI): rewrite RAG query on first follow-up (off-by-one in skip-rewrite threshold)
The short-conversation skip in `rewriteQueryWithContext` used `userMessages.length <= 2`,
which short-circuits both the very first turn AND the first follow-up. The follow-up is
the moment the rewriter matters most — it's where pronouns and shorthand ("the bars",
"how long does it last?") need to be resolved against earlier turns before the embedding
search runs. With the rewriter skipped, RAG queries against the raw last message, scores
nothing above the 0.3 threshold, and no context gets injected for that turn.

The visible symptom is the assistant treating the first follow-up in any chat as a
brand-new question — e.g. "great - they threw up 2 of the bars it looks like" answered
as if it were a recipe-bars question, with no carry-forward of the prior chocolate-
poisoning context.

Threshold lowered to `< 2`: skip only when there's exactly one user message (nothing to
rewrite from). From the first follow-up onward the rewriter runs, as originally intended
before commit 96e5027.

Validated against `mistral-nemo:12b` on NOMAD3 by hot-patching the compiled controller
and replaying the dog-chocolate scenario. Post-patch response correctly threads "3
Hershey's bars" from turn 1 into turn 2's answer; pre-patch (per reporter's screenshot)
pivoted to peanut butter bar recipes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 20:34:30 -07:00
..
benchmark_controller.ts fix(security): SSRF validation for map downloads and error sanitization (CWE-918, CWE-209) (#552) 2026-04-17 14:12:02 -07:00
chats_controller.ts fix(security): SSRF validation for map downloads and error sanitization (CWE-918, CWE-209) (#552) 2026-04-17 14:12:02 -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-03 13:47:53 -07:00
ollama_controller.ts fix(AI): rewrite RAG query on first follow-up (off-by-one in skip-rewrite threshold) 2026-05-12 20:34:30 -07:00
rag_controller.ts fix(RAG): add start button in kb modal and ensure restart policy exists (#700) 2026-04-27 22:26:46 -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-17 14:12:02 -07:00
zim_controller.ts feat(Content): custom ZIM library sources with pre-seeded mirrors (#593) 2026-05-04 11:30:59 -07:00