Zenaique

How does LlamaIndex ChatEngine differ from QueryEngine?

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

QueryEngine is stateless retrieve and synthesize; ChatEngine adds conversation memory and can rewrite underspecified follow-ups into standalone queries before retrieval.

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

Picture a research assistant at a library. The QueryEngine version is the desk attendant. You walk up, ask one question, they pull a book, read you the relevant page, you leave. Every visit starts fresh; they do not remember you. The ChatEngine version is a personal researcher you book by the hour. They remember what you asked last time. When you say 'and what about its side effects?', they know 'its' means the drug you discussed three minutes ago, and they rewrite the question into something they can actually search before pulling the next book. The difference is memory and follow-up rewriting, not the books or the search.

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 over a Q&A endpoint and RAG inside a chatbot look like the same problem from a distance. From inside the engine, they are not. The chatbot has to handle follow-up turns where the user references earlier context, and the literal turn text often does not carry enough signal for retrieval. LlamaIndex's split between QueryEngine and ChatEngine encodes exactly that distinction.

This dive walks through the stateless primitive, the three ChatEngine modes, the antecedent-resolution bug they each handle differently, and the operational signals that tell you which mode to pick.

QueryEngine. The stateless RAG primitive

QueryEngine is the canonical retrieve and synthesize flow. You construct it from an Index (index.as_query_engine(...)), call .query(q), and the engine handles three steps internally: a Retriever pulls the top-k most similar Nodes for q, NodePostprocessors optionally rerank or filter, and a Response Synthesizer composes the final answer from the Nodes.

No state survives the call. The next .query(q2) starts fresh. This is the right primitive when each query is independent: a search box, a one-shot Q&A endpoint, a 'summarise this document' button, an internal tool that takes a question and returns an answer.

The failure mode is using it for a chatbot. A second turn that says 'and what about its side effects?' has no antecedent. The pronoun 'its' refers to something said in turn one, which QueryEngine never saw. The retriever embeds the literal text, gets a noisy embedding, and pulls Nodes that are at best loosely related to what the user actually meant.

python
query_engine = index.as_query_engine(similarity_top_k=5, response_mode='tree_summarize')
result = query_engine.query('What are the side effects of ibuprofen?')
# Stateless: nothing carries to the next call.
ChatEngine. State plus a turn-handling strategy
Picking a mode and the failure modes of each
How this composes with 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.
AxisQueryEngineChatEngine
StateStateless per callConversation memory across turns
Turn handlingLiteral query → retrieve → synthesizeMode-dependent (condense / context / react)
Follow-up rewritingNoYes in condense_question mode
Tool-calling optionNo (just retrieve)Yes in react mode
Cost per turn1 retrieval + 1 synthesisUp to 1 rewrite + 1 retrieval + 1 synthesis
Best fitSearch box, single-turn Q&AMulti-turn chatbot with referential follow-ups

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

  • LlamaIndex's documentation chatbot uses ChatEngine in `condense_question` mode because doc questions chain into 'how does this interact with X' follow-ups.
  • Notion AI and Linear's assistant patterns rely on the agentic mode equivalent. Retrieval as a tool, not as the default action per turn.
Sign in to see more production examples.

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

QHow would you decide between condense_question and react?
A

If every turn needs retrieval, condense_question is cheaper and just as accurate. If turns mix retrieval-requiring and chit-chat, react avoids the unnecessary rewrite and retrieve on non-retrieval turns at the cost of a tool-calling decision.

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

Using QueryEngine for a chatbot and discovering that follow-up questions like 'and what about its side effects?' retrieve garbage because the pronoun gets embedded with no antecedent.

Sign in to see all red flags and common mistakes.

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

  • What stateless primitive does QueryEngine represent?

  • How does ChatEngine add state on top of that primitive?

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