Zenaique

What problem does LlamaIndex's `RouterQueryEngine` solve that a single `QueryEngine` cannot?

MCQ·Medium·4.0 · 0·~1 min·Asked atHaptikSigmoidTogether Ai
Attempt it
TL;DR

RouterQueryEngine picks among several sub-engines (vector, SQL, summary) per query so one front door can serve structurally different question types.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture the front desk at a hospital. A single QueryEngine is one specialist with one toolkit. Great for the questions they know, useless for the rest. RouterQueryEngine is a triage nurse. You arrive with any question; she listens, decides whether you need radiology, the pharmacy, or general practice, and sends you to the right room. The departments have completely different tools, X-ray machines, pill counters, stethoscopes, but the patient only sees one front door. The router does not retrieve anything itself. It picks the engine that should retrieve, and that engine handles the rest.

Key concepts

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

RAG starts simple. One corpus, one vector index, one retriever. It stays simple until the questions stop looking alike. As soon as the workload mixes 'summarise this report', 'what does the policy say about overtime', and 'how many incidents matched severity 3', a single Index hits its structural ceiling. Each question shape wants a different Index shape, and no single Index wins all three.

RouterQueryEngine is LlamaIndex's primitive for solving this with composition rather than compromise. This dive walks through the structural problem, the Selector's role, how the two main Selector types differ in production, and how to calibrate descriptions so routing stays reliable as the engine list grows.

Why one Index shape cannot serve all question shapes

Each Index in LlamaIndex has a sweet spot, and each sweet spot is a different question shape.

  • Vector indexes (Pinecone, Weaviate, FAISS, Chroma) embed document chunks and answer 'what does the corpus say about X' via similarity search. Strong on semantic recall over passages. Weak on whole-document questions because chunks lose document-level signal, and weak on structured filter queries.
  • Summary indexes keep a tree summary of each document. Strong on 'summarise the report' or 'what is the gist of this section'. Weak on fine-grained passage retrieval because the tree has already compressed away detail.
  • SQL / structured indexes sit on top of a database or DataFrame. Strong on 'how many rows where status = X'. Useless for free-form semantic search because rows are not embeddings.
  • Keyword / BM25 indexes answer exact-token questions. Strong when the user knows the term; weak when they paraphrase.

A mixed workload forces a choice: build one Index that does everything badly, or build several Indexes that each do their shape well. RouterQueryEngine is the way to do the second without exposing the complexity to the application's caller.

The Selector. The load-bearing component
Descriptions as the tuning surface
How RouterQueryEngine fits the rest of the stack
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • LlamaIndex's official tutorials use RouterQueryEngine to combine a summary index and a vector index over the same documents for 'summarise the report' vs 'what does it say about X' questions.
  • Notion AI's document Q&A combines whole-document summarisation, page-level retrieval, and structured property queries. Exactly the heterogeneous workload RouterQueryEngine targets.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow would you compare RouterQueryEngine to a SubQuestionQueryEngine?
A

SubQuestionQueryEngine decomposes a complex query into sub-questions and answers each against potentially different engines, then synthesises. RouterQueryEngine picks one engine for the whole query. The first composes, the second selects.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Building one fat vector index for every kind of question, summarisation, lookup, structured query, and getting bad answers because the index shape only fits one question type.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • One Index shape per question shape. The structural limit of a single QueryEngine

  • RouterQueryEngine as multi sub engine dispatch

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Defend the call to…
Short answer·Hard