>

Pattern 01 · AI Architecture

Enterprise RAG, done right

A production pattern for grounded question-answering over private enterprise content — with access control, evaluation, and freshness built in, not bolted on.

40–60%
of effort goes to ingestion & eval, not the LLM
6–8k
token context budget — retrieved, not dumped
0
documents visible to users without permission

01 · PROBLEM

Generic LLMs hallucinate on your private knowledge

Out of the box, a language model answers from its training data: confident, fluent, and frequently wrong about your products, policies, and procedures. Pointing it at a document folder with a naive upload doesn't fix this — retrieval returns the wrong chunks, stale content outranks current policy, and users with different permissions see the same answers.

This pattern describes the architecture we implement for support copilots, internal knowledge assistants, and customer-facing help systems where every answer must be traceable to a source and no user sees content they aren't entitled to.

02 · WHEN TO USE

Fit and anti-fit

  • You have a large, changing corpus: docs, tickets, runbooks, contracts, wikis.
  • Answers must cite sources and respect document-level permissions.
  • Content freshness matters — policies and products change monthly or faster.
  • You can define what a "good answer" looks like (so you can evaluate it).

Don't use it for stable, small knowledge (a static FAQ is cheaper as fine-tuned prompts or a knowledge base), or where answers require multi-step reasoning across dozens of documents — that's agentic territory (see Multi-Agent Systems).

03 · ARCHITECTURE

Reference architecture

Enterprise RAG architectureEnterprise RAG architecture: documents flow through ingestion, embedding and indexing on the left; user queries flow through hybrid retrieval, reranking and guarded generation on the right, with an evaluation loop underneath. Ingest — offline Retrieve — online Generate, guard, and evaluate Source systemsdocs · tickets · wikis · DBs Chunk & clean512–1024 tok · overlap Embed Vector indexdense embeddings Keyword indexBM25 · metadata filters User query Query rewriteexpand · de-dupe Hybrid retrievaldense + sparse · ACL filter Rerankcross-encoder top-k Context packbudget 6–8k tokens Guarded generationLLM · citations required Policy filterPII · prompt-injection screen Grounded answerwith citations Eval harnessgolden Q/A · judge LLM Feedback loopthumbs · corrections → index Failed evals and user corrections re-enter ingestion — the index is a living asset, not a one-time load.

The critical insight: RAG is two systems — an offline ingestion pipeline and an online retrieval pipeline — joined by an evaluation loop. Most failed pilots build only the right half.

04 · COMPONENTS

What each piece does

ComponentResponsibilityBuild/buy notes
Chunk & cleanSplit documents into retrievable units with metadata (source, section, date, owner, ACL tags)Structure-aware splitting beats fixed token windows; keep tables and procedures intact
EmbedConvert chunks to dense vectorsStart with a strong general model; fine-tune only when evals prove a domain gap
Vector + keyword indexesDense similarity and BM25 lexical search over the same corpuspgvector is fine to start; dedicated stores (Pinecone, Qdrant, OpenSearch) at scale
Query rewriteExpand ambiguous queries, generate sub-queriesSmall, fast model; biggest quality lever per dollar
Hybrid retrievalMerge dense + sparse results, apply permission filters before rankingFilters must come from your identity system, not document metadata alone
RerankCross-encoder re-scores top 50 → top 8Adds 200–500ms; worth it whenever precision matters
Guarded generationLLM answers strictly from packed context, cites sources, refuses when context is insufficientRefusal behavior is a feature — prompt for it explicitly
Eval harnessGolden question set, LLM judge, regression runs on every changeNon-negotiable for production; start with 100–200 questions

05 · FLOW

How a query moves through the system

F1
Authenticate & scope. Resolve the user's identity and entitlements; these travel with the query as filter predicates.
F2
Rewrite. A small model expands the query into 2–4 retrieval-oriented variants (synonyms, sub-questions).
F3
Hybrid retrieve. Dense + keyword search run in parallel; permission filters applied at the index, not after.
F4
Rerank & pack. Cross-encoder narrows to the top chunks; assemble into a token budget with source tags.
F5
Screen & generate. Policy filter checks for prompt injection and PII; the LLM answers only from context, with citations.
F6
Log & learn. Query, retrieved chunks, answer, and feedback are logged; failures feed the eval set and re-ingestion queue.

06 · TRADEOFFS

Decisions with real costs

DecisionOption AOption BOur default
ChunkingFixed 512-token windows — simple, splits meaningStructure-aware — better recall, more engineeringStructure-aware for docs that matter; fixed for the long tail
RetrievalDense only — misses exact terms, SKUs, error codesHybrid dense + BM25 — more infra, better recallHybrid, always, for enterprise corpora
RerankingSkip it — lower latencyCross-encoder — +200–500ms, materially better top-kInclude; latency is tunable, wrong answers aren't
FreshnessNightly re-index — simple, stale up to 24hEvent-driven ingestion — real-time, more plumbingEvent-driven for high-churn sources, nightly for the rest
Model hostingAPI (OpenAI/Anthropic/Bedrock) — fast start, per-token costSelf-hosted — data control, GPU ops burdenAPI first; self-host only for hard data-residency constraints

07 · SECURITY

Non-negotiables

  • Permission-aware retrieval: entitlement filters execute inside the index query. Post-filtering ranked results leaks existence and wastes budget.
  • PII handling: detect and tag PII at ingestion; redact or tokenize before embedding when the use case doesn't need raw values.
  • Prompt injection: treat retrieved content as untrusted data, never instructions. Screen both user input and high-risk retrieved chunks.
  • Data residency: embeddings are derived data — they inherit the classification of their source documents. Keep them in the same boundary.

08 · GOVERNANCE

Running it like a system, not a demo

  • Eval-gated changes: no index rebuild, chunking change, or prompt edit ships without the regression suite passing.
  • Source lineage: every citation resolves to document + version + retrieval timestamp. Stale answers are debuggable.
  • Ownership: each source has a named owner responsible for freshness; orphaned sources get quarantined, not silently served.
  • Audit log: who asked what, what was retrieved, what was answered — retained per your compliance requirements.

09 · COST

Where the money goes

  • Ingestion & embedding are one-time-ish per document, then incremental — usually the smallest line item.
  • Retrieval infra (vector store, reranker GPUs) is fixed monthly cost; size it to QPS and corpus, not vibes.
  • Generation tokens dominate at scale: a 8k-token context at high QPS dwarfs everything else. Reranking + tight context budgets are cost controls, not just quality controls.
  • Eval & labeling is the hidden budget line — plan for ongoing golden-set maintenance, not a one-time effort.

10 · IMPLEMENTATION

A phased path that de-risks

P0
Prove retrieval (2–3 weeks). One high-value corpus, 150 golden questions, baseline precision/recall. If retrieval can't hit your bar, no generator will save it.
P1
Guarded pilot (4–6 weeks). Permission filtering, policy screens, citations, eval-gated deploys. Internal users only.
P2
Harden ingestion (ongoing). Event-driven updates, source ownership, quarantine for stale content. This is where pilots become products.
P3
Scale & optimize (ongoing). Caching, context-budget tuning, cost-per-answer dashboards, expansion to new corpora.

Engagement tie-in: our Agentic AI practice implements this pattern end-to-end, and the Agentic AI Readiness Assessment scores your corpus, permissions, and eval maturity before you commit.

11 · RELATED

Keep exploring

Multi-Agent Systems

When answers need planning, tool use, and multi-step reasoning — the agent layer above RAG.

Read pattern →

Agentic AI

Our practice for production copilots, assistants, and agent systems with eval built in.

Explore practice →

Advisory

AI strategy and readiness assessments that decide whether to build before how.

Explore practice →

Start here

Talk to an Architect

Bring your hardest AI, data, or modernization problem. We'll tell you plainly whether we can help — and what it takes.

FAQ

Questions we hear

Access control, evaluation, and freshness. Enterprise RAG enforces per-user document permissions at retrieval time, runs a regression eval suite on every index or prompt change, and treats ingestion as a pipeline with SLAs — not a one-time upload.

Retrieval quality. Chunking that splits procedures mid-step, missing metadata for filtering, and no reranking stage account for most quality failures we see. Instrument retrieval precision before tuning the generator.

Postgres with pgvector is a legitimate starting point up to roughly single-digit millions of vectors with modest QPS. Move to a dedicated vector store when you need hybrid search at scale, multi-tenancy, or sub-100ms p99 latency with heavy filtering.