What it is
A retrieval-augmented generation (RAG) platform answers questions from a body of documents. Documents are split into chunks, each chunk is turned into an embedding vector and stored in a vector index. At question time the platform embeds the question, retrieves the most similar chunks and passes them to a large language model as context for the answer. A multi-tenant platform does this for many customers at once, each with their own documents, users and limits.
Why it exists
LLMs do not know an organisation's private, current documents, and fine-tuning is a poor way to add facts that change weekly. Retrieval puts the relevant passages into the prompt at query time, so answers can cite current sources and access rules can be applied per user. Running it as a shared platform lets many teams or customers reuse the same pipeline, stores and LLM capacity instead of each building their own.
How it works
Requirements and estimates. Functional: upload documents, ask questions, get answers with sources. Non-functional: strict tenant isolation, freshness (new documents searchable within minutes), a few seconds per answer, bounded cost. An illustrative estimate: 500 tenants × 20,000 documents × 20 chunks ≈ 200 M chunks; at 1,024 float32 dimensions that is about 800 GB of raw vectors before index overhead and replicas. At 30 questions/s with ~4,000 prompt tokens and ~400 output tokens per answer, the LLM must process over 100,000 tokens per second, which is what provider quotas and the bill are measured in.
Ingestion. Uploads are stored (object storage) and a message is queued. Workers parse the file, split it into chunks (by structure where possible: headings, paragraphs, table rows; with some overlap), call an embedding model in batches and upsert vectors plus metadata (tenant, document id, access labels, version) into the vector store. Often a keyword index (BM25) is written at the same time for hybrid search. The queue absorbs bulk uploads; freshness becomes "backlog ÷ worker throughput".
Retrieval. The orchestrator embeds the question with the same model used for ingestion, runs an approximate nearest-neighbour search (HNSW or IVF-style indexes) for the top k chunks, often combines it with keyword search and reranks the candidates with a cross-encoder. Every query is scoped to the caller's tenant (and, inside a tenant, to documents the user may read).
Tenant isolation. Options, from strongest to cheapest: a separate index or collection per tenant; a namespace/partition per tenant inside a shared cluster; a shared index with a mandatory metadata filter. In every case the tenant id comes from the verified token at the gateway, and the retrieval service adds the scope itself. The LLM never decides what it is allowed to see.
Generation and the LLM gateway. The prompt combines instructions, retrieved chunks and the question. Calls go through an LLM gateway that knows each deployment's quota (requests and tokens per minute), routes by weight or remaining quota, retries 429s with backoff and honours Retry-After, fails over when a deployment is unhealthy and accounts tokens per tenant for limits and billing.
Semantic cache. Before retrieval, the question's embedding is compared to recently answered questions of the same tenant. Above a similarity threshold, the cached answer is returned. This saves the most expensive step, at the risk of wrong hits and stale answers.
Evaluation. A golden set of questions with reference answers and expected source documents runs through the real pipeline on every change. Retrieval is scored (recall@k, whether the expected chunk was retrieved), answers are scored for faithfulness to the retrieved context and for correctness, often by a judge model calibrated against human labels. Production traces, user feedback and sampled reviews complement it.
When to use it
- Questions over private or fast-changing documents: support knowledge bases, internal wikis, contracts, product manuals.
- When answers must cite sources and respect per-user document permissions.
- When several teams or customers need the same capability and sharing the pipeline and LLM capacity pays off.
When not to
- Structured questions ("revenue by region last quarter") are better served by querying the database, possibly with an LLM writing the query.
- A small, stable corpus that fits in the model's context window may not need a retrieval pipeline at all.
- When wrong answers are unacceptable and cannot be checked, retrieval reduces but does not eliminate fabricated answers.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Index per tenant | Strongest isolation, easy deletion, per-tenant tuning | Many small indexes, more operational overhead, poorer packing |
| Shared index + mandatory filter | Cheap, simple scaling | One missing filter is a data leak; filtered ANN can lose recall |
| More chunks in the prompt (higher k) | Better chance the answer is included | More tokens: higher cost, latency and quota use; distracts the model |
| Semantic cache | Fewer LLM calls, low latency for repeats | Wrong hits at loose thresholds; invalidation work |
| Queue-based ingestion | Uploads never fail on bursts | Freshness depends on the backlog |
| LLM gateway | Failover, quota pooling, per-tenant accounting | Another hop and another component to run redundantly |
Alternatives
- Long-context prompting: put whole documents in the prompt. Simple for small corpora; cost and latency grow with every token, and access control is still yours.
- Fine-tuning: teaches style and format well, facts poorly; hard to update and impossible to scope per user.
- Classic search plus summaries: a keyword or hybrid search UI with extractive snippets; cheaper and fully grounded, less conversational.
- Agentic retrieval: an agent decides which tools and searches to run; more flexible, harder to bound in cost and latency (see the AI agent platform case study).
Failure modes
- Quota exhaustion: peak traffic exceeds the provider's request or token limits; 429s become failed answers. Retries without backoff make it worse.
- Provider or regional outage: without a fallback deployment that has spare quota, the platform is down even though all your own components are healthy.
- Cross-tenant leak: a missing filter, a shared cache key or a tenant id taken from user input exposes another tenant's data.
- Prompt injection through documents: an uploaded document contains instructions; retrieved into a prompt, it can steer the model. Treat retrieved text as data, restrict what the model's output can trigger.
- Silent quality regression: a new chunker, embedding model or prompt lowers answer quality while latency and error rate look fine.
- Embedding model change: vectors from different models are not comparable; switching models means re-embedding the corpus (plan a dual-write migration).
- Incomplete deletion: a deleted document lingers as vectors, keyword entries or cached answers.
In production
Run ingestion and querying as separate deployments so a bulk import cannot slow answers. Keep document versions and delete by document id across every store, including the cache. Put per-tenant rate and token limits at the gateway. Trace every request (retrieved chunk ids, prompt size, tokens, model, latency) so a bad answer can be explained. Provision fallback LLM capacity with headroom for the largest deployment's share. Gate releases on the evaluation suite and keep sampling production answers.
Common misconceptions
- "The system prompt keeps tenants apart." Prompts are not access control; isolation belongs in retrieval.
- "The vector database is the bottleneck." Retrieval usually takes tens of milliseconds; generation takes seconds and is quota-limited.
- "More orchestrator instances fix 429s." They send more calls into the same quota.
- "If nothing errors, answers are fine." Quality needs its own measurement.
- "Retries fix rate limits." Without backoff and a budget they multiply load on an exhausted quota.
Interview angle
Start with requirements and numbers: corpus size, vector storage, peak questions per second and tokens per second. Draw ingestion (queue, workers, embeddings, vector + keyword index) separately from the query path (gateway, orchestrator, cache, retrieval, LLM gateway). Expect probes on tenant isolation (where the tenant id comes from, per-tenant index vs filter), on handling provider limits and outages, on freshness and deletion, on prompt injection and on how you know the answers are good. Naming evaluation as a release gate stands out.
Model assumptions
The simulation is a simplified model, not a benchmark. Questions arrive at random (Poisson). An LLM deployment is modelled as a server with 64 concurrent generations of ~800 ms each (lognormal, cv 0.4); its provider quota is a token bucket counted in requests per second (deployment A: 20/s, B: 40/s), whereas real quotas usually count tokens and requests per minute. A call over the quota fails at once, and the orchestrator turns it into a failed answer. The embedding call (~25 ms) and vector search (~30 ms) are modelled as a server and a database. The semantic cache is a fixed 40% hit probability per lookup, so a retry re-rolls the cache (a real cache would miss the same question again, which makes retries look slightly better here than in reality). Ingest workers take ~400 ms per document including parsing, chunking and embedding (4 in parallel, ≈ 10 documents/s); embedding load from ingestion is not added to the shared embedding model. The LLM gateway uses weighted round robin by quota and health checks every 500 ms (2 failures eject, 3 successes restore). The tenant-scoped query, the evaluation run and the worker → embedding → vector store hops are scripted illustrations, not simulated. All numbers, including the opening estimate, are illustrative orders of magnitude.