MODULE 14  Β·  Real-World Architectures

How Perplexity Works: The Search Engine That Actually Answers

Google gives you 10 blue links. Perplexity gives you the answer with citations. Here's the architecture behind it.

πŸ“… Mar 2026
⏱ 10 min read
🎯 Episode 94 of 98
PerplexityAI SearchRAGArchitecture
In this episode

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?"

example
code
β”‚
    β–Ό

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Query Understanding β”‚

β”‚ β†’ Classify: needs search? (yes β€” current topic) β”‚

β”‚ β†’ Extract: key entities (India, semiconductor) β”‚

β”‚ β†’ Generate: optimized search queries β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

example
code
β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β–Ό               β–Ό               β–Ό

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Web β”‚ β”‚ News β”‚ β”‚ Index β”‚

β”‚ Search β”‚ β”‚ Search β”‚ β”‚ Search β”‚

β”‚ (Bing) β”‚ β”‚(recent)β”‚ β”‚(cached)β”‚

β””β”€β”€β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜

example
code
β”‚            β”‚             β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β–Ό

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Retrieval & Ranking β”‚

β”‚ β†’ Fetch top 20-30 pages β”‚

β”‚ β†’ Extract relevant passages β”‚

β”‚ β†’ Rank by relevance + recency + authority β”‚

β”‚ β†’ Select top 5-8 sources β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

example
code
β–Ό

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Grounded Generation β”‚

β”‚ β†’ LLM generates answer using ONLY retrieved textβ”‚

β”‚ β†’ Every claim tagged with source [1][2][3] β”‚

β”‚ β†’ Hallucination guardrails β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

example
code
β–Ό

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:

  1. "India semiconductor fabrication plant 2024 latest news"
  2. "India chip manufacturing Tata Micron factory update"
  3. "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):

example
code
results = []
example
code
for url in urls:
        # Fetch the page
        html = await fetch(url, timeout=3000)  # 3s timeout, skip slow sites
example
code
# Extract readable content (strip nav, ads, boilerplate)
        content = extract_article_text(html)  # Similar to Readability.js
example
code
# 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),
        }
example
code
results.append({
            'url': url,
            'content': content[:10000],  # Cap at ~10K chars
            'metadata': metadata,
        })
example
code
return results

The 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):

example
code
all_passages = []
example
code
for page in crawled_pages:
        # Split page into overlapping passages (~200 words each)
        passages = chunk_text(page['content'], chunk_size=200, overlap=50)
example
code
for passage in passages:
            all_passages.append({
                'text': passage,
                'source': page['url'],
                'title': page['metadata']['title'],
                'date': page['metadata']['date'],
            })
example
code
# Embed the query
    query_embedding = embed(query)
example
code
# Embed all passages and rank by similarity
    passage_embeddings = embed_batch([p['text'] for p in all_passages])
example
code
scores = cosine_similarity(query_embedding, passage_embeddings)
example
code
# Rerank with a cross-encoder (more accurate than embedding similarity)
    reranked = cross_encoder_rerank(query, all_passages, scores)
example
code
# Apply diversity filter (don't pick 5 passages from the same source)
    diverse_passages = apply_diversity(reranked, max_per_source=2)
example
code
return diverse_passages[:8]  # Top 8 passages

The 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

example
code
for semiconductor manufacturing. Tata Group plans to build..."

[2] Reuters (Feb 2024): "Micron Technology inaugurated its $2.75 billion

example
code
assembly and test facility in Gujarat..."

[3] Economic Times (Mar 2024): "The Indian government is in talks with

example
code
three more companies for semiconductor fabs..."

[4] Semiconductor Today (Jan 2024): "ISMC (a joint venture) announced

example
code
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:

  1. "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"

  1. "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]

  1. "Outdated citation" β€” citing old information when newer exists

Perplexity addresses this with:

python

Post-generation citation verification

def verify_citations(answer, sources):

example
code
claims = extract_claims(answer)  # NLP to split into individual claims
example
code
for claim in claims:
        cited_source = get_cited_source(claim)
        source_text = sources[cited_source]['text']
example
code
# Check if the source actually supports the claim
        entailment_score = nli_model.predict(
            premise=source_text,
            hypothesis=claim.text
        )
example
code
if entailment_score < 0.7:
            # Citation doesn't support claim β€” flag or remove
            claim.flag_for_review()
example
code
return verified_answer

Natural 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 APIBing API + custom index
Web crawlingCustom crawler (like Common Crawl, but real-time)
Content extractionCustom (similar to Readability/Trafilatura)
Embedding modelCustom fine-tuned (likely based on BGE or E5)
RerankerCross-encoder (likely fine-tuned)
Generation modelMix: GPT-4o, Claude, custom fine-tuned models
Citation modelNLI + custom verification model
InferenceCustom serving stack
InfrastructureAWS + 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 workClick, read, synthesizeRead the answer
FreshnessExcellent (massive crawl)Good (smaller crawl)
Revenue modelAds ($200B+/year)Subscription ($20/mo)
AccuracyUser verifiesMust be accurate (or trust is lost)
Publisher impactSends trafficAbsorbs 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:

example
code
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.
example
code
def answer(self, query):
        # 1. Generate search queries
        search_queries = self.llm.generate_search_queries(query)
example
code
# 2. Search and crawl
        urls = self.search.search(search_queries)
        pages = self.crawler.crawl(urls)
example
code
# 3. Chunk and retrieve
        passages = self.chunk_and_embed(pages)
        relevant = self.reranker.rerank(query, passages, top_k=8)
example
code
# 4. Generate grounded answer
        answer = self.llm.generate(
            system="Answer using ONLY the provided sources. Cite with [1][2]...",
            sources=relevant,
            query=query
        )
example
code
# 5. Verify citations
        verified = self.verify_citations(answer, relevant)
example
code
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.

← Previous Ep 93: How Cursor/Copilot Works: AI Coding Assistants Under th…