- 1QueryEngine. The assembled retrieve then synthesize entrypoint
- 2Index. Nodes organized into a queryable structure (vector / keyword / tree)
- 3ResponseSynthesizer. Composes the final answer from retrieved Nodes
- 4Retriever. Pulls candidate Nodes for a query from the Index
- 5Node. Chunk of a Document with metadata (text, hash, source)
- 6Document. Raw file or string loaded from a data source
LlamaIndex flows Document → Node → Index at ingest, then Retriever → ResponseSynthesizer at query, packaged as a QueryEngine for callers.
Picture turning a stack of books into a library you can ask questions of. You start with the books themselves. You cut each book into chapter-sized cards, each card stamped with its book and page number. You file the cards on shelves organized by topic so you can find them fast. When someone asks a question, a librarian pulls the few most relevant cards from the shelves and a writer turns those cards into a single short answer. The whole assembled service, librarian plus writer behind one counter, is what visitors actually use. They never see the cards, the shelves, or the books directly.
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.
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.
LlamaIndex looks intimidating from the outside because the API has so many class names. The trick to learning it quickly is to see that those classes are a small ordered pipeline, not a sprawling library. Knowing the six stages and their boundaries makes the entire framework readable.
This deep dive walks each stage in order, says what input it takes and what output it produces, and names the design choice the stage is asking you to make.
Phase one: ingestion. Document, Node, Index
The ingestion phase turns raw data into a queryable structure. It runs once per data load or on a schedule; the result is the persistent index that query-time stages will read.
Document
A Document is the raw-content wrapper. It carries a text body, a metadata dict, and a source identifier. Loaders produce Documents from filesystems, APIs, databases, and SaaS sources via the LlamaHub ecosystem.
The Document layer is where structural information is preserved. If a PDF has page numbers, the Documents carry them in metadata. If an HTML page has a canonical URL, it travels with the Document. This is what later lets citations point back to the right place.
Node
Nodes are the queryable units. A NodeParser takes Documents and splits them into Nodes according to a chunking strategy. Choices include:
- SentenceWindowNodeParser. Keeps a wide context window per Node while indexing on a narrower retrieval window. Good for long-form QA where the retrieved chunk needs context.
- TokenTextSplitter. Fixed token-count chunks with overlap. The cheap default.
- SemanticSplitter. Splits at embedding-distance changes. Higher quality, slower.
- HierarchicalNodeParser. Produces parent and child Nodes for auto-merging retrieval.
Each Node carries the chunk text, a content hash, parent-document references, and a metadata dict inherited from the Document plus any Node-specific additions. The content hash is the dedup key when you re-ingest.
Index
The Index organizes Nodes into a queryable structure. VectorStoreIndex is the default: each Node gets an embedding, embeddings live in a vector backend (Pinecone, Weaviate, Postgres pgvector, in-memory).
Alternative Index types address non-vector query shapes:
- KeywordTableIndex. Inverted index style keyword retrieval for exact-match workloads.
- TreeIndex. Recursive summary tree; useful for very large corpora where summary-first then drill-down is the right query pattern.
- KnowledgeGraphIndex. Entity-relation graph; useful for structured-query questions over relational corpora.
The Index type is the highest-impact ingestion choice. Picking the wrong one, vector when the query is keyword-shaped, or vector when the corpus has heavy structural relationships, costs more downstream than any later tuning.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.node_parser import SentenceWindowNodeParser
from llama_index.core.response_synthesizers import get_response_synthesizer
# Doc -> Nodes
docs = SimpleDirectoryReader('./data').load_data()
parser = SentenceWindowNodeParser.from_defaults(window_size=3)
nodes = parser.get_nodes_from_documents(docs)
# Nodes -> Index
index = VectorStoreIndex(nodes)
# Retriever + Synthesizer -> QueryEngine
retriever = index.as_retriever(similarity_top_k=5)
synth = get_response_synthesizer(response_mode='tree_summarize')
query_engine = index.as_query_engine(retriever=retriever, response_synthesizer=synth)
response = query_engine.query('What did the postmortem identify as the root cause?')Real products, models, and research that use this idea.
- LlamaIndex 0.13 ships the canonical Document → Node → Index → QueryEngine pipeline as the default RAG flow.
- LlamaParse converts PDFs into Documents with preserved structure before NodeParser chunking, used heavily in enterprise document RAG.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you wire Cohere Rerank into this pipeline without touching the Retriever or Synthesizer?
Add a CohereRerank as a NodePostprocessor on the QueryEngine; the retriever still does first-stage selection, the postprocessor reranks before the synthesizer sees the Nodes.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Trying to query a Document directly without going through Nodes and an Index, then wondering why retrieval quality is poor.
60 second bullets to scan on the way to the call.
The six ordered stages of a LlamaIndex RAG pipeline
What a Document carries versus what a Node carries
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.