# Story: Chat RAG Answer (happy path)
**Phase:** `03_story_chat_rag.md` · **E2E:** `tests/e2e/test_chat_rag.py`
## Narrative
As **a user** (friend, colleague, future me), I want to ask Brain a question
about Reese's setup and get a grounded, chippy answer that points me at the
exact documentation — so I can actually *do* the thing.
- **Given** the knowledge base is imported and I type "How is my Kubernetes
cluster set up?"
- **When** Brain embeds the question, retrieves the top chunks by cosine
similarity, maps them to their parent documents, and feeds the **full
document text** to `turbo`
- **Then** I see a streamed, upbeat answer that cites the source
(`Homelab/kubernetes.md`), grounded in the doc's specifics (Talos,
Cilium, the node list) — and never in anything the docs don't say.
## Acceptance criteria
1. `POST /api/chat` streams SSE: `delta` events then a final `done` event
carrying `{deflected, sources[], suggestions[]}` (PLAN §4).
2. Retrieval: top-4 chunks (`BOR_TOP_K_CHUNKS`), cosine via pgvector
`<=>`, score = 1 − distance.
3. Context assembly: top-2 **distinct documents** by best-chunk score, full
content, capped at `BOR_MAX_CONTEXT_CHARS` with truncation marker.
4. System prompt = locked persona + HONESTY GATE rules (PLAN §6), with
`HIGH` and `…`.
5. The answer arrives **streamed** (multiple deltas), rendered live.
6. Source chips (mono, `source/path`) render under the answer bubble.
7. Per-turn log line emitted (PLAN §9) and a `query_log` row inserted
(`deflected=false`, top_score, sources, latency).
8. LLM/embedding failure → JSON/SSE error the UI turns into the error banner
(no hang, no stale button).
## UI Visualization & Structure
- Chat column centered at 46rem (PLAN §7.1); user bubble right (brand
indigo, white text ≥4.5:1), Brain bubble left (white, ink text, avatar 🧠).
- While generating: typing indicator → live-appended text (see
loading-feedback story for the full state machine — this story only needs
"deltas render as they arrive and the button is busy throughout").
- **Source chips:** pill, `font-family: mono`, `bg --brand-soft`,
`color --brand-ink` (6.3:1), `max-width` + ellipsis; each shows
`Homelab/kubernetes.md`. `aria-label` when truncated.
- Bubble content is safe-rendered markdown (escape-first local renderer —
`