KatInterview

Designing LLM Search and Retrieval for High-Token Inputs and Corpus

Machine LearningModel answer

Last updated

Architect an end-to-end RAG system capable of ingesting mega-documents and handling high-token, unstructured user inputs with low latency, strict permissions, and high citation fidelity.

Design an LLM-based search and question-answering architecture that operates over a multi-format context store (PDFs, enterprise wikis, application logs, legal contracts) while seamlessly managing inputs and context sources that far exceed standard LLM context budgets.

The core challenge lies in dual-sided token expansion: incoming user requests may consist of massive pasted payloads (e.g., thousands of lines of stack traces or entire legal clauses), while the target reference materials contain deep, structured, and multi-page texts.

Key Requirements & Constraints

  1. Answer Generation & Precision: Produce accurate, grounded responses backed by verified textual references (citations) while keeping context hallucination minimal.
  2. Dual-Sided Context Limits: Both user queries (e.g., 50k tokens of raw text or code) and indexed target documents (e.g., 500-page manuals) exceed standard high-throughput context limits or cost-effective operational boundaries.
  3. Latency & Cost Budgeting: Target sub-second initial document retrieval and an end-to-end token latency strictly within acceptable operational SLA boundaries (e.g., $< 3$ seconds total runtime), optimizing cost per query.
  4. Access Governance: Enforce strict tenant-level and user-level document access permissions during retrieval.

Key Areas to Cover

1. System Architecture Pipeline

Walk through the ingestion pipeline, offline document indexing, online query execution, re-ranking strategies, final context assembly, and telemetry logging.

2. Processing Deep & Unstructured Ingestion Targets

Detail the chunking strategies, overlapping models, hierarchical indexing (document/section/chunk), parent-child document mapping, and metadata indexing for massive corpus items.

3. Resolving High-Token User Queries

Explain strategies for converting massive user inputs (such as stack traces, long contracts, or dense prose) into targeted retrieval execution plans without dropping critical context.

4. Context Budgeting, Security, & Evaluation

Describe how token allocations are partitioned across system instructions, user context, and retrieved snippets. Address access control enforcement and the metrics used to evaluate retrieval and generation quality.

Hints

Hint 1

Break the architecture down into distinct offline ingestion and online inference execution flows.

Hint 2

Consider hierarchical indexing (parent-child retrieval) where small chunks are matched via vector search, but larger parent context sections are passed to the generation model.

Hint 3

For extremely long user inputs, employ query distillation (using specialized small LLMs or rule-based parsers) to split inputs into structured task descriptors and key entities before executing multi-vector retrieval.