docs/architecture/decisions/004-one-cached-knowledge-document.md
004. Chat uses one cached knowledge document
Status
Accepted (2026-10-11)
Context
The verified material about Dominic and his work is small enough to fit in the model's context. A retrieval system would introduce storage, indexing and selection work without a need to divide the corpus.
Decision
Chat answers only from one hand-written knowledge document. Place the whole document in the prompt and use the model provider's prompt caching. Do not add retrieval, embeddings, a vector database or browsing.
Review the document as public site content. It must contain no client names or private details. Store it outside the repository in Upstash Redis under ai-cv:chat:knowledge. The repository will be public; the source document should not be available as a repository file or in its history. Upload it from an external file with pnpm knowledge:push <file>.
Load it at the endpoint and cache it in module memory for three minutes. Place the prompt-caching breakpoint immediately after the complete document, with only fixed rules before it. Missing, empty or invalid knowledge produces 503 and a clear server log; expired knowledge is not served after a failed refresh.
Consequences
- There is one source to review and maintain for factual chat answers.
- Every answer has the full approved corpus available.
- Missing facts remain unknown rather than being filled from other sources.
- Provider choice must support prompt caching. A corpus that no longer fits requires a new decision rather than quietly adding retrieval.
- Updating the document does not require rebuilding or redeploying the site.
- A warm server may retain the previous document for up to three minutes.
- Redis is required for chat, alongside its role in enforcing usage limits.
- Keeping the file out of Git does not make its facts secret: answers expose approved information, so the same privacy review still applies.