Reference architecture: retrieval-augmented generation (RAG)
RAG grounds a language model in an organisation's own content. It is two systems: an ingestion pipeline that keeps an index fresh, and a query path that has to be fast, safe and observable.
Unstructured sourcesDocuments, PDFs, wiki and web pages, images, audio, video
Unstructured data pathChunked, embedded and indexed
- Parse & extractOCR, transcription, dedup, quality checks
- ClassifyType, topic, sensitivity, PII redaction
- Chunk & enrichStructure-aware chunking, summaries
- Metadata & accessProvenance, filters, ACLs per chunk
- EmbeddingsChunks to vectorsversioned model
- Search indexVector + keyword
→RetrievalRouting, hybrid search, re-ranking, generation
Structured sourcesDatabases, tables, data warehouse, data catalogue
Structured data pathQueried in place, under governance
- Schema & profilingTables, fields, relationships, quality checks
- Classify & describeDomain, sensitivity, ownership, business descriptions
- Governed query layerSQL access, views, row and column policies
- Structured accessExact lookups, aggregations, analytical queries
Online request flowFast, safe and observable
- User or appQuestion or task
- API gatewayAuthentication, quotas, rate limits
- Input guardrailsPrompt injection, PII, policy checks
- RouterUnstructured, structured or both
- RetrieveHybrid search and governed SQL, filtered by the caller's permissions
- Re-rankMost relevant context first
- GenerateGrounded answer with citations and output checks
Key design decisions
- Chunking: split on document structure, not fixed sizes, and keep source and section metadata for citations and access control.
- Hybrid retrieval: combine vector and keyword search, then re-rank. Pure vector search misses exact terms such as product codes.
- Permissions: filter by the caller's entitlements at retrieval time, so the model never sees content the user cannot.
- Versioning: treat the embedding model and index as a versioned pair. Changing one means re-indexing.
- Evaluation: keep a golden question set and measure retrieval quality and answer faithfulness on every change.