System Design: Enterprise Knowledge Assistant (RAG)

A complete system design for an enterprise RAG assistant serving 50,000 employees: requirements, capacity estimates, architecture, ingestion and query flows, permissions, data model, scaling, reliability, security, evaluation and trade-offs.

On this page

The design brief#

“Design an AI assistant that lets 50,000 employees ask questions about internal policies, procedures and technical documentation, with answers grounded in company documents.”

This walk-through follows the AI system design framework.

1. Requirements#

Functional

  • Natural-language Q&A over documents in SharePoint, Confluence, a policy management system and PDF manuals.
  • Answers cite sources with links; “I don’t know” when the corpus lacks the answer.
  • Multi-turn conversation with follow-up questions.
  • Users see only answers drawn from documents they may access.
  • Feedback (thumbs up/down with reason); hand-off to a human (open an HR/IT ticket).

Non-functional

Requirement Target
Latency First token < 2 s p95; full answer < 8 s p95
Availability 99.9% during business hours
Freshness Document changes searchable within 1 hour; deletions within 15 minutes
Quality Faithfulness ≥ 0.9, answer correctness ≥ 0.8 on golden set; recall@20 ≥ 0.9
Security SSO, document-level ACLs, no training on company data by vendors, EU data residency
Cost < €0.02 per question on average

Out of scope (v1): actions (booking leave), structured-data analytics, external customers.

2. Capacity estimates#

  • 50,000 employees, 20% daily active, 5 questions each → 50,000 questions/day.
  • Peak: 3× average over an 8-hour day → 50,000 / 28,800 s × 3 ≈ 5 questions/s peak.
  • Tokens per question: 600 system + 3,000 context (5 chunks × 600) + 800 history + 100 question ≈ 4,500 input, 350 output.
  • Per day: 225M input + 17.5M output tokens. At illustrative $3/$15 per million: ≈ $675 + $263 ≈ $940/day before caching and routing (~$0.019 per question).
  • Peak tokens/minute: 5 × 60 × 4,850 ≈ 1.5M tokens/min → check provider rate limits; reserve throughput or use two regions.
  • Corpus: 2M documents → ~20M chunks × 1,024-dim float32 ≈ 80 GB of vectors (~120 GB with HNSW overhead); int8 quantization → ~30 GB.

3. High-level architecture#

Knowledge assistant — high-level architecture
flowchart TB
    subgraph Clients
        WEB["Web app"]
        TEAMS["Teams / Slack bot"]
    end
    subgraph Edge
        GWAPI["API gateway<br/>SSO / OIDC, rate limits"]
    end
    subgraph App["Assistant service — stateless, autoscaled"]
        ORCH["Chat orchestrator<br/>Spring AI"]
        QR["Query rewriter"]
        RET["Retriever<br/>hybrid + ACL filter"]
        RR["Reranker"]
        GR["Guardrails<br/>input & output"]
    end
    subgraph Data
        CONV[("Conversation store<br/>PostgreSQL")]
        IDX[("Search index<br/>vectors + BM25 + metadata")]
        CACHE[("Redis<br/>sessions, response cache")]
        PERM[("Permission cache<br/>user → groups")]
    end
    subgraph AI["AI platform"]
        AIGW["AI gateway"]
        LLM["Chat models<br/>primary + fallback"]
        EMB["Embedding model"]
        RRM["Rerank model"]
    end
    subgraph Ingest["Ingestion — event-driven"]
        CONN["Connectors<br/>SharePoint, Confluence, policy system"]
        Q1[["Change queue"]]
        PIPE["Parse → chunk → enrich → embed"]
    end
    OBS["Tracing, evals,<br/>cost dashboards"]
    WEB --> GWAPI
    TEAMS --> GWAPI
    GWAPI --> ORCH
    ORCH --> GR
    ORCH --> QR
    ORCH --> RET --> IDX
    RET --> PERM
    RET --> RR --> AIGW
    ORCH --> CONV
    ORCH --> CACHE
    ORCH --> AIGW
    AIGW --> LLM
    AIGW --> EMB
    AIGW --> RRM
    CONN --> Q1 --> PIPE --> AIGW
    PIPE --> IDX
    ORCH -.-> OBS

4. Ingestion flow#

Event-driven ingestion with permissions
sequenceDiagram
    participant SRC as SharePoint / Confluence
    participant CON as Connector
    participant Q as Change queue
    participant P as Ingestion worker
    participant EMB as Embedding model
    participant IDX as Search index
    SRC-->>CON: webhook or delta sync: doc changed
    CON->>SRC: fetch content + metadata + ACL
    CON->>Q: DocumentChanged(id, version, acl)
    Q->>P: consume
    P->>P: parse (layout-aware), clean, structure-aware chunking
    P->>P: add title/section path, contextual header, metadata
    P->>EMB: embed chunks (batched)
    P->>IDX: upsert chunks for doc version N, ACL on every chunk
    P->>IDX: delete chunks of version N-1
    Note over CON,IDX: Deleted doc → DocumentDeleted → remove all chunks.<br/>ACL-only change → update metadata, no re-embedding.

Design points:

  • Idempotent upserts keyed by (doc_id, version, chunk_no); safe to replay.
  • ACL changes update metadata only — cheap and fast.
  • Periodic full reconciliation catches missed webhooks.
  • A dead-letter queue for documents that fail parsing, with an ops dashboard.

5. Query flow#

Answering a question
sequenceDiagram
    actor U as Employee
    participant O as Orchestrator
    participant G as Guardrails
    participant C as Response cache
    participant R as Retriever
    participant I as Index
    participant K as Reranker
    participant L as LLM via AI gateway
    U->>O: question + conversation id (JWT)
    O->>G: input checks (injection, PII policy, topic)
    O->>O: load last turns, rewrite to standalone query
    O->>C: lookup(normalised query, user ACL hash)
    C-->>O: miss
    O->>R: retrieve(query, user groups, filters)
    R->>I: BM25 top 50 + vector top 50, ACL pre-filter
    I-->>R: candidates
    R->>R: RRF fusion → top 40
    R->>K: rerank → top 5 (+ parent sections)
    K-->>O: context with source ids
    O->>L: system prompt + sources + history + question (stream)
    L-->>U: streamed answer with [n] citations
    O->>G: output checks (citations valid, PII, policy)
    O->>O: save turn, trace, tokens, cost

6. Data model#

document(id, source, url, title, owner, version, updated_at, language, doc_type, acl_groups[])
chunk(id, document_id, version, chunk_no, section_path, text, contextual_header,
      embedding vector(1024), tsv tsvector, acl_groups[], effective_date, region)
conversation(id, user_id, created_at, title)
message(id, conversation_id, role, content, prompt_version, model, tokens_in, tokens_out,
        cost, retrieved_chunk_ids[], feedback, created_at)

ACL groups are denormalised onto every chunk for filtering inside the index query.

7. Key design decisions and trade-offs#

Decision Choice Alternative and why not
Index OpenSearch with vectors + BM25 (or PostgreSQL + pgvector at smaller scale) Dedicated vector DB: extra system, and hybrid is needed anyway
Retrieval Hybrid + RRF + cross-encoder rerank Vector only: misses codes, product names, acronyms
Chunking Structure-aware, ~500 tokens, heading path + contextual header Fixed-size: splits sections, loses context
Permissions ACL pre-filter in index query Post-filter in app: leak risk, empty results
Model Mid-tier model by default; route complex questions to a frontier model Frontier for all: ~3–5× cost for little gain on simple questions
Caching Prompt caching for system prompt; response cache keyed by query + ACL hash, short TTL Semantic cache across users: risk of leaking answers across permission sets
Agentic RAG Not in v1 Adds latency and unpredictability; revisit for multi-hop questions

8. Scaling and reliability#

  • Orchestrator is stateless; scale horizontally on CPU and concurrent streams.
  • Index: shards by document hash; replicas for query throughput; int8 quantization.
  • AI gateway: provider rate-limit handling, fallback model in a second region, circuit breakers.
  • Timeouts per step; if reranker fails, use fused results; if LLM fails, show top sources as search results (degraded mode).
  • Ingestion is decoupled through a queue, so source outages or embedding throttling never affect queries.

9. Security and governance#

  • SSO with OIDC; user groups resolved from the directory and cached briefly.
  • Document ACLs enforced at retrieval; tested with automated “permission leak” test cases.
  • Prompt-injection defences: retrieved text wrapped as data, instructions to ignore embedded commands, output checks. See AI security.
  • Data protection: EU-hosted models through the cloud provider, no-training terms, PII masking in logs, 30-day trace retention.
  • Registered in the AI inventory; risk-tiered as limited risk (internal information assistant), transparency notice shown to users.

10. Evaluation and monitoring#

  • Golden set of 300 questions across departments, including no-answer and permission-boundary cases.
  • CI gate on recall@20, faithfulness, correctness and citation accuracy.
  • Online: 5% of traffic judged for faithfulness; dashboards for thumbs-down rate, “I don’t know” rate, latency, cost per question; weekly review of failures.

11. Extensions to discuss#

  • Agentic RAG for multi-hop questions; GraphRAG for policy-to-regulation mapping.
  • Actions through tools (create ticket, book leave) with confirmation — see the support agent case study.
  • Personalisation by role, country and language.

Review notes#

Summary#

  • Two pipelines: event-driven ingestion with ACLs and versioning; an online query path with rewrite, hybrid retrieval, rerank, generation and guardrails.
  • Estimate tokens, cost and peak tokens per minute early — they drive model choice and capacity.
  • Enforce permissions in the index query; never in the prompt.
  • Design degraded modes and fallbacks; evaluate continuously.