When organizations want an AI assistant on their website or intranet, generic models fail for two reasons: they lack private domain data and hallucinate when uncertain. In production engineering, the proven solution is Retrieval-Augmented Generation (RAG).
1. Three Pillars of Reliable RAG
- Smart Chunking & Metadata: Split CMS nodes, manuals, or PDFs into 400-600 token chunks with overlap while preserving URL, language, date, and access-control metadata.
- Hybrid Search (Vector + Keyword): Combining semantic embeddings with BM25/Elasticsearch keyword matching prevents misses on product codes, acronyms, and legal IDs.
- Grounded Generation: Pass only verified context chunks to Claude and enforce strict source citations.
2. Grounded System Prompt Pattern
$systemPrompt = <<<PROMPT
Answer strictly using the provided CONTEXT.
If the answer is not present in the context, reply: "I do not have that information in the current documentation."
Always cite the source URL at the end.
PROMPT;
3. Permission-Aware Retrieval
Always enforce user role permissions at the vector/search query stage before passing retrieved chunks to the LLM.