Google gives you 10 blue links. You click, read, scroll, click back, try another link, piece together the answer yourself.
Perplexity gives you the answer. With citations. In 3 seconds.
This might be the most important shift in how humans access information since Google itself. And the architecture behind it β combining real-time web search, RAG at massive scale, and citation-grounded generation β is a masterclass in AI engineering.
Let's trace how a single query goes from your question to a cited, sourced answer.
The Architecture: Search Meets RAG Meets LLM
Your Question: "What's the latest on India's semiconductor fab plans?"
β
βΌβββββββββββββββββββββββββββββββββββββββββββββββββββ
β Query Understanding β
β β Classify: needs search? (yes β current topic) β
β β Extract: key entities (India, semiconductor) β
β β Generate: optimized search queries β
βββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌββββββββββ ββββββββββ ββββββββββ
β Web β β News β β Index β
β Search β β Search β β Search β
β (Bing) β β(recent)β β(cached)β
ββββββ¬ββββ βββββ¬βββββ βββββ¬βββββ
β β β
ββββββββββββββΌββββββββββββββ
βΌβββββββββββββββββββββββββββββββββββββββββββββββββββ
β Retrieval & Ranking β
β β Fetch top 20-30 pages β
β β Extract relevant passages β
β β Rank by relevance + recency + authority β
β β Select top 5-8 sources β
βββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
βΌβββββββββββββββββββββββββββββββββββββββββββββββββββ
β Grounded Generation β
β β LLM generates answer using ONLY retrieved textβ
β β Every claim tagged with source [1][2][3] β
β β Hallucination guardrails β
βββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
βΌYour answer (with numbered citations)
Let's dig into each stage.
Stage 1: Query Understanding
Not every question needs web search. Perplexity first classifies the query:
"What's 2+2?" β No search needed (model knowledge)
"What's the weather in Mumbai?" β Needs real-time data
"Latest on India's semiconductor plans?" β Needs web search + news
"Explain quantum computing" β Could use model knowledge, but search adds freshness
For queries that need search, Perplexity generates optimized search queries β not your original question, but what would find the best results:
User query: "What's the latest on India's semiconductor fab plans?"
Generated search queries:
- "India semiconductor fabrication plant 2024 latest news"
- "India chip manufacturing Tata Micron factory update"
- "India semiconductor policy ISMC fab"
Multiple queries are generated to maximize coverage. Each targets a different angle of the topic.
π§
Stage 2: Web Crawling and Indexing
Perplexity maintains its own web index β they don't just rely on Bing's API.
Real-Time Crawling
When search results return URLs, Perplexity crawls and extracts content in real-time:
python
Simplified crawl pipeline
async def fetch_and_extract(urls):
results = []for url in urls:
# Fetch the page
html = await fetch(url, timeout=3000) # 3s timeout, skip slow sites# Extract readable content (strip nav, ads, boilerplate)
content = extract_article_text(html) # Similar to Readability.js# Extract metadata
metadata = {
'title': extract_title(html),
'date': extract_publish_date(html),
'author': extract_author(html),
'domain': urlparse(url).netloc,
'domain_authority': get_domain_score(url),
}results.append({
'url': url,
'content': content[:10000], # Cap at ~10K chars
'metadata': metadata,
})return resultsThe Perplexity Index
Beyond real-time crawling, Perplexity has built a massive pre-crawled index:
Billions of web pages pre-crawled and indexed
Updated continuously β news sources crawled every few minutes
Domain quality scoring β authoritative sources ranked higher
Structured extraction β not just text, but tables, lists, dates
This pre-crawled index is why Perplexity can answer in 3 seconds instead of 30. Most of the crawling is already done.
π
Stage 3: Passage Retrieval and Ranking
Perplexity doesn't dump entire web pages into the LLM context. It retrieves the specific passages that answer your question.
python
Passage retrieval pipeline
def retrieve_relevant_passages(query, crawled_pages):
all_passages = []for page in crawled_pages:
# Split page into overlapping passages (~200 words each)
passages = chunk_text(page['content'], chunk_size=200, overlap=50)for passage in passages:
all_passages.append({
'text': passage,
'source': page['url'],
'title': page['metadata']['title'],
'date': page['metadata']['date'],
})# Embed the query
query_embedding = embed(query)# Embed all passages and rank by similarity
passage_embeddings = embed_batch([p['text'] for p in all_passages])scores = cosine_similarity(query_embedding, passage_embeddings)# Rerank with a cross-encoder (more accurate than embedding similarity)
reranked = cross_encoder_rerank(query, all_passages, scores)# Apply diversity filter (don't pick 5 passages from the same source)
diverse_passages = apply_diversity(reranked, max_per_source=2)return diverse_passages[:8] # Top 8 passagesThe reranking step is crucial. Embedding similarity is fast but rough. A cross-encoder (a model that takes query + passage as input and outputs a relevance score) is slower but much more accurate. Perplexity uses both: embeddings for fast initial filtering, cross-encoder for precise reranking.
Ranking Factors
Relevance score:
40% - Semantic relevance (does the passage answer the question?)
25% - Recency (newer = better for current topics)
20% - Source authority (established media > random blog)
15% - Passage quality (length, specificity, factual density)
Stage 4: Grounded Generation
This is where it all comes together. The LLM generates an answer, but it's grounded in the retrieved passages:
System prompt:
"You are a research assistant. Answer the user's question using ONLY
the provided sources. Cite every claim with [1], [2], etc.
If the sources don't contain the answer, say so.
Do NOT use information not present in the sources."
Sources:
[1] TechCrunch (Jan 2024): "India approved $15.2 billion in incentives
for semiconductor manufacturing. Tata Group plans to build..."[2] Reuters (Feb 2024): "Micron Technology inaugurated its $2.75 billion
assembly and test facility in Gujarat..."[3] Economic Times (Mar 2024): "The Indian government is in talks with
three more companies for semiconductor fabs..."[4] Semiconductor Today (Jan 2024): "ISMC (a joint venture) announced
plans for a 65nm fab in Karnataka..."User: "What's the latest on India's semiconductor fab plans?"
The model generates:
India has been aggressively pursuing semiconductor manufacturing.
The government approved $15.2 billion in incentives [1], attracting
multiple companies. Micron Technology recently inaugurated a $2.75
billion assembly facility in Gujarat [2]. The Tata Group is building
its own fab facility [1], while the government is in active discussions
with three additional companies [3]. ISMC has announced plans for a
65nm fabrication plant in Karnataka [4].
Every claim has a citation. If the model tries to add information not in the sources, the post-processing catches it.
The Citation Verification Problem
Generating citations is easy. Generating correct citations is hard.
Common failure modes:
- "Ghost citation" β [3] doesn't actually support the claim
"India plans to build 10 fabs by 2025 [3]"
β Source [3] never mentions "10 fabs" or "2025"
- "Hallucinated synthesis" β combining facts from different sources incorrectly
"Tata is building a $2.75 billion fab in Karnataka"
β Tata is building a fab [1], $2.75B is Micron [2], Karnataka is ISMC [4]
- "Outdated citation" β citing old information when newer exists
Perplexity addresses this with:
python
Post-generation citation verification
def verify_citations(answer, sources):
claims = extract_claims(answer) # NLP to split into individual claimsfor claim in claims:
cited_source = get_cited_source(claim)
source_text = sources[cited_source]['text']# Check if the source actually supports the claim
entailment_score = nli_model.predict(
premise=source_text,
hypothesis=claim.text
)if entailment_score < 0.7:
# Citation doesn't support claim β flag or remove
claim.flag_for_review()return verified_answerNatural Language Inference (NLI) models check whether each source actually entails (logically supports) the claim it's cited for.
π¬
Perplexity Pro: The "Deep Research" Mode
Perplexity Pro's research mode is more sophisticated β it runs multiple search-read-think cycles:
Cycle 1: Initial search
β "India semiconductor plans"
β Read top results
β Identify gaps: "Who are the specific companies? What timelines?"
Cycle 2: Follow-up search
β "Tata semiconductor fab timeline India"
β "Micron Gujarat facility progress 2024"
β Read, extract new information
Cycle 3: Deep dive
β "India semiconductor policy PLI scheme details"
β "ISMC Karnataka 65nm fab latest update"
β Synthesize all gathered information
Final: Generate comprehensive answer with all sources
This iterative approach β search, read, identify gaps, search again β is essentially agentic RAG (Episode 30 meets Episode 22). The model is acting as a research agent, deciding what to search for next based on what it's already found.
π‘οΈ
The Technical Stack (Best Guess)
Perplexity hasn't published their full architecture, but from their papers, blog posts, and hiring patterns:
Component Likely Technology
| Search API | Bing API + custom index |
|---|---|
| Web crawling | Custom crawler (like Common Crawl, but real-time) |
| Content extraction | Custom (similar to Readability/Trafilatura) |
| Embedding model | Custom fine-tuned (likely based on BGE or E5) |
| Reranker | Cross-encoder (likely fine-tuned) |
| Generation model | Mix: GPT-4o, Claude, custom fine-tuned models |
| Citation model | NLI + custom verification model |
| Inference | Custom serving stack |
| Infrastructure | AWS + custom GPU clusters |
π¦
The Answer Engine vs Search Engine Debate
Perplexity represents a fundamental shift:
Google (Search Engine) Perplexity (Answer Engine)
Output Links to pages Direct answer with citations
| User work | Click, read, synthesize | Read the answer |
|---|---|---|
| Freshness | Excellent (massive crawl) | Good (smaller crawl) |
| Revenue model | Ads ($200B+/year) | Subscription ($20/mo) |
| Accuracy | User verifies | Must be accurate (or trust is lost) |
| Publisher impact | Sends traffic | Absorbs traffic (controversial) |
The publisher problem is real. If Perplexity answers your question so well that you never click through to the source, what incentive do publishers have to create content? This is an unsolved tension.
π
Building Your Own Answer Engine
Want to build a Perplexity-like system for your domain? Here's the stack:
python
Mini answer engine architecture
class AnswerEngine:
def __init__(self):
self.search = SearchAPI() # Bing, Google, or custom
self.crawler = WebCrawler() # Fetch and extract
self.embedder = EmbeddingModel() # BGE-large or similar
self.reranker = CrossEncoder() # ms-marco-MiniLM
self.llm = LLM() # GPT-4o, Claude, etc.def answer(self, query):
# 1. Generate search queries
search_queries = self.llm.generate_search_queries(query)# 2. Search and crawl
urls = self.search.search(search_queries)
pages = self.crawler.crawl(urls)# 3. Chunk and retrieve
passages = self.chunk_and_embed(pages)
relevant = self.reranker.rerank(query, passages, top_k=8)# 4. Generate grounded answer
answer = self.llm.generate(
system="Answer using ONLY the provided sources. Cite with [1][2]...",
sources=relevant,
query=query
)# 5. Verify citations
verified = self.verify_citations(answer, relevant)return verifiedπ
Practical Takeaways
Perplexity is RAG at web scale β the same pattern from Episode 22, but with live web search as the retrieval source
Query optimization matters β transforming user questions into effective search queries is a crucial step
Reranking > embedding similarity β cross-encoders are slower but dramatically more accurate
Citation verification is its own pipeline β generating citations is easy, verifying them is hard
Iterative search (agentic RAG) beats single-shot β search, read, identify gaps, search again
The answer engine model changes the web's economics β if users don't click through, publishers lose traffic
ποΈ
What's Next?
Episode 95: How Midjourney Works β From text to photorealistic images. We'll trace the diffusion pipeline: text encoding, noise prediction, iterative denoising, and upscaling. Plus how Midjourney trains for aesthetics β making images that look good, not just accurate.
β Previous
Ep 93: How Cursor/Copilot Works
Next β
Ep 95: How Midjourney Works
Next: Episode 95 β How Midjourney Works
You type 'a cyberpunk street in Mumbai, neon lights, rain, 8k' and get art that belongs in a gallery. Here's how.
This is part of a 98-episode series covering AI engineering from tokens to production deployment.