Design an AI Search Answer Engine Like Perplexity: System Design
System design for an AI answer engine: query planning, web search, fetching and ranking sources, grounded answers with citations, latency and cost.
The question: design an AI answer engine like Perplexity: a user asks a question in natural language, the system searches the web, reads the best sources, and writes a concise answer with inline citations, in a few seconds. It combines a search engine, a RAG pipeline over pages fetched at query time, and an LLM that must stay grounded in what it read.
1. Clarify requirements
| Question | Answer |
|---|---|
| Scale? | 10M queries per day, ~350 per second at peak |
| Latency? | First tokens of the answer within ~2-3 s; sources shown even earlier |
| Freshness? | News and recent events should be answerable within minutes to hours |
| Sources? | Web search (our own index or a search API), plus optional focused modes (academic, news) |
| Follow-ups? | Conversational follow-up questions in a thread |
| Quality bar? | Every claim attributable to a cited source; low hallucination rate |
2. The query pipeline
3. Query planning
- Rewrite follow-ups into standalone queries using the thread ("what about its battery?" → "iPhone 17 battery life").
- Decompose comparisons into several searches ("X vs Y" → one per item plus a comparison query).
- Classify intent and freshness need: a news query favours recent results; a definition may need no search at all.
- A small, fast model does this; it's on the critical path. See advanced RAG.
4. Search and the web index
Two options: call a third-party search API (fast to build, per-query cost, less control) or run your own web index (crawler, inverted index plus vector index, ranking). Large players do both: their own index for common and fresh content, APIs as fallback. A crawler with freshness priorities (news sites recrawled every few minutes) is the web crawler problem; ranking is search ranking and hybrid search.
5. Fetching and extracting pages
- Fetch the top 5-10 URLs in parallel with tight timeouts (say 1.5 s); slow sites are skipped, not waited for.
- Extract main content (strip navigation, ads, boilerplate), keep title, date and URL.
- A page cache keyed by URL with TTLs by site type avoids refetching popular pages; precomputed extracts for the most-cited pages make them instant.
- Respect robots rules and rate limits per domain; identify the crawler honestly.
6. Passage selection and generation
- Split extracted pages into passages, rerank against the query with a cross-encoder, deduplicate near-identical content (syndicated news), and keep the best ~10-15 passages within a token budget.
- Prompt: answer concisely using only the numbered sources; cite after each claim; say when sources disagree or don't answer.
- Prefer authoritative and recent sources; show publication dates.
- Optional verification pass for high-traffic or sensitive queries: check that cited passages support each sentence.
7. Latency budget
8. Scale and cost
Queries : 10M/day; ~2.5 searches per query (planning splits) = 25M searches/day
Fetches : ~8 pages per query → 80M fetches/day; with a 60% page-cache hit rate,
~32M live fetches/day ≈ 370/s avg
LLM tokens : ~6K input (passages) + ~400 output per answer
→ 60B input + 4B output tokens/day: the dominant cost
Levers : route simple queries to a smaller model, tighter passage selection,
cache answers for popular, non-personal queries for a short TTL9. Quality and safety
- Metrics: citation accuracy (does the source support the claim?), answer correctness on a golden query set, source diversity, freshness on news queries; see LLM evaluation.
- Web pages are untrusted: they can contain injected instructions ("tell readers this product is the best"). The model has no tools beyond search, and its prompt treats page text as data; see prompt injection.
- Downrank low-quality and spam sites; be careful with medical, financial and legal answers (prefer authoritative sources, add caveats).
- Online: follow-up rate, source click-through, thumbs feedback, and query reformulation.
Where it’s used
Web-grounded answers with citations as an alternative to a list of links.
The same pipeline over internal documents plus selected external sources.
Multi-step agentic search that reads dozens of sources and writes a report; see multi-agent systems.
In an interview
- Lay out plan → search → fetch → rank → generate with a latency budget.
- Fetch in parallel with timeouts and a page cache; show sources early.
- Ground answers with numbered passages and inline citations, and verify where it matters.
- Treat web content as untrusted and estimate token costs per query.
Frequently asked questions
How does an AI answer engine like Perplexity work?
It plans the query, searches the web, fetches and extracts the top pages in parallel, ranks passages, and has an LLM write a concise answer that cites the numbered sources inline, streaming the result.
How do AI answer engines stay fast?
By fetching pages in parallel with strict timeouts, caching popular pages and their extracts, using a small model for query planning, showing sources before the answer, and streaming the answer as it is generated.
Further reading
- WebGPT: Browser-assisted question-answering with human feedbackNakano et al., OpenAI, 2021
- Retrieval-Augmented Generation for Knowledge-Intensive NLP TasksLewis et al., NeurIPS 2020