ModelRefs / LlamaIndex — Tutorial
LlamaIndex — Tutorial
Document loaders, node parsers, indexes, and query engines — LlamaIndex's data-centric approach to RAG. Covers LlamaIndex vs LangChain, The index pipeline.
Overview
Document loaders, node parsers, indexes, and query engines — LlamaIndex's data-centric approach to RAG
Level: Advanced. Estimated reading time: 35 minutes.
LlamaIndex vs LangChain
Both frameworks build LLM applications, but with different emphasis:
LangChain is general-purpose: chains, agents, memory, tools. Great for complex multi-step pipelines and agentic workflows.
LlamaIndex is data-centric: its primary focus is connecting LLMs to your data. It has richer abstractions for loading, parsing, indexing, and querying documents. Better defaults for RAG out of the box, more index types, and deeper support for structured data.
When to use LlamaIndex: document QA, enterprise knowledge bases, research tools — any use case where the primary challenge is getting an LLM to accurately reason over a large corpus.
The two frameworks interoperate — LlamaIndex query engines can be used as LangChain tools.
The index pipeline
LlamaIndex's data pipeline has five stages:
1. Load: SimpleDirectoryReader, PDFReader, WebPageReader, and 100+ loaders return Document objects.
2. Parse: NodeParser splits Documents into Node objects (chunks). SentenceSplitter, TokenTextSplitter, or SemanticSplitterNodeParser.
3. Index: embed Nodes and store. VectorStoreIndex (default), KeywordTableIndex (BM25), TreeIndex (hierarchical), SummaryIndex (sequential).
4. Query: QueryEngine wraps retrieval + response synthesis. RetrieverQueryEngine retrieves top-k then sends context to the LLM.
5. Agents: ReActAgent with QueryEngine as a tool — the agent decides when to query the index.
Advanced retrieval patterns
Sub-question query engine: decomposes a complex question into sub-questions, queries the index for each, synthesises a combined answer. Useful for multi-hop questions.
Hybrid search: combine BM25 keyword retrieval with dense vector retrieval using QueryFusionRetriever with Reciprocal Rank Fusion (RRF).
Metadata filtering: every node stores metadata (file name, page number, section, date). The retriever can filter by metadata before ANN search, dramatically improving precision.
Sentence window retrieval: index individual sentences for precise matching, but retrieve the surrounding window of sentences for context. Better than chunking when answers are single sentences inside longer paragraphs.
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to LlamaIndex — Tutorial.