AI / LlamaIndex Interview Questions
What happens internally when you call index.as_query_engine()?
Calling index.as_query_engine() looks like a single simple call, but it assembles several components behind the scenes using sensible defaults so you don't have to wire them up manually.
- It constructs a retriever appropriate to the index's type, for example a
VectorIndexRetrieverfor aVectorStoreIndex, configured with any retrieval kwargs you passed, such assimilarity_top_k. - It builds a response synthesizer using the LLM from
Settings.llm(or an explicitllmkwarg) and the requestedresponse_mode, defaulting tocompactif none is specified. - If you passed
node_postprocessors, they're attached to run between retrieval and synthesis. - All of this is wrapped into a query engine object, typically a
RetrieverQueryEngine, that exposes the.query()and.aquery()methods you actually call.
Understanding this matters when defaults stop being good enough: since the pieces are just a retriever, postprocessors, and a synthesizer glued together, you can always drop down to the low-level API and construct a RetrieverQueryEngine yourself with custom versions of any of those three components.
More Related questions...