LlamaIndex Cheatsheet: Documents, Retrievers, Agents and RAG
By DevShelfHub
LlamaIndex is a Python data framework for building LLM applications over custom documents: it handles ingestion (SimpleDirectoryReader, PDF, web), chunking, embedding, vector storage, and retrieval in a single opinionated pipeline. This cheatsheet covers Documents, Nodes, VectorStoreIndex, retrievers, query engines, the chat engine pattern, agents, tools, and production configuration.
97 items
◷ 7 min
Indices
Retrievers
QueryEngines
LlamaIndex (formerly GPT Index) is a Python data framework purpose-built for LLM applications that need to reason over custom documents. Its central abstraction is the index: you load documents, LlamaIndex chunks and embeds them, stores the vectors, and wraps the whole pipeline in a query engine that retrieves relevant chunks and synthesises an answer. The framework is deliberately opinionated — the default pipeline works well out of the box with minimal configuration, making it faster to get a RAG application running than with a more modular tool like LangChain.
The data model flows from Documents (raw content + metadata, produced by readers like SimpleDirectoryReader, PyMuPDFReader, or web loaders) through Nodes (chunks with relationships to their source document and neighbours) into an Index (most commonly VectorStoreIndex). A QueryEngine wraps the index for single-turn Q&A; a ChatEngine adds conversation history for multi-turn use. Both can be backed by any vector store — the built-in in-memory store is fine for prototypes, while Qdrant, Pinecone, or Chroma scale to production corpora.
LlamaIndex ships with a growing agents layer: ReActAgent and FunctionCallingAgent follow the standard tool-use loop, and QueryEngineTool wraps any index as a callable tool so agents can route across multiple document collections. The LlamaIndex Hub provides pre-built loaders and tools for dozens of data sources. This cheatsheet covers the everyday surface: ingestion, indexing, retrieval, query and chat engines, agents, tools, and the key configuration knobs for embedding models, LLMs, and vector stores.
LlamaIndex split into ~200 sub-packages around 0.10 — provider integrations now live as
llama-index-llms-*,
llama-index-embeddings-*,
llama-index-vector-stores-*,
llama-index-readers-*. The umbrella
llama-index still works but pulls many. Pin individual sub-packages in
production. Names current as of May 2026.
install · env · defaultsSetup
bash
# Core package + the integrations you'll need
pip install llama-index # umbrella metapackage
pip install llama-index-core # if you want to pick & mix
pip install llama-index-llms-openai \
llama-index-embeddings-openai \
llama-index-readers-file \
llama-index-vector-stores-chroma
# env
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-...
export LLAMA_CLOUD_API_KEY=llx-... # optional, LlamaParse / LlamaCloud
# Global defaults (used by every index/engine unless overridden)
python - <<'PY'
from llama_index.core import Settings
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding
Settings.llm = OpenAI(model="gpt-4o-mini", temperature=0)
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
PY
where things liveCommon imports
Core abstractions sit in llama_index.core. Provider bindings are split into
their own llama_index.{llms,embeddings,readers,vector_stores}.* sub-packages.
from llama_index.core import VectorStoreIndex, SummaryIndex, KeywordTableIndex
Index classes.
from llama_index.core import Document, Settings, StorageContext
Document, global config, storage.
from llama_index.core import SimpleDirectoryReader
Local-file loader.
from llama_index.core.node_parser import SentenceSplitter, MarkdownNodeParser
Chunkers.
from llama_index.core.ingestion import IngestionPipeline
Reusable ETL.
from llama_index.core.retrievers import VectorIndexRetriever, BM25Retriever
Hand-rolled retrievers.
from llama_index.core.query_engine import RetrieverQueryEngine, SubQuestionQueryEngine
Query engines.
from llama_index.core.chat_engine import CondenseQuestionChatEngine, ContextChatEngine
Chat engines.
from llama_index.core.tools import FunctionTool, QueryEngineTool
Tool wrappers for agents.
from llama_index.core.agent.workflow import FunctionAgent, ReActAgent
Agent classes.
from llama_index.llms.openai import OpenAI
OpenAI LLM.
from llama_index.llms.anthropic import Anthropic
Anthropic LLM.
from llama_index.embeddings.openai import OpenAIEmbedding
OpenAI embeddings.
from llama_index.vector_stores.chroma import ChromaVectorStore
Chroma backend.
from llama_index.readers.file import PDFReader, DocxReader
Returns a Response. resp.source_nodes for citations.
engine.stream_query("…")
Stream tokens as they arrive.
python
from llama_index.core import VectorStoreIndex, StorageContext
from llama_index.core.postprocessor import SimilarityPostprocessor
from llama_index.core.response_synthesizers import get_response_synthesizer
# Reload the existing store as an index (no re-embedding)
index = VectorStoreIndex.from_vector_store(store)
# Hand-roll the pipeline: retriever -> postprocessors -> synthesizer
retriever = index.as_retriever(similarity_top_k=6)
postprocessors = [SimilarityPostprocessor(similarity_cutoff=0.7)]
synth = get_response_synthesizer(response_mode="compact")
# Or use the prebuilt query engine
query_engine = index.as_query_engine(
similarity_top_k=6,
response_mode="compact",
node_postprocessors=postprocessors,
)
resp = query_engine.query("What does the onboarding doc say about access?")
print(str(resp))
for n in resp.source_nodes:
print(n.score, n.node.metadata.get("file_name"))
IngestionPipeline bundles transformations (splitting, embedding, extractors)
and writes resulting nodes to a vector store. Hash-based caching skips work on re-runs.
Persistent Chroma store, global defaults, indexed from a folder, answered with a compact response. Replace
the folder and you have a working doc-bot.
python
from llama_index.core import (
SimpleDirectoryReader, VectorStoreIndex, Settings, StorageContext,
)
from llama_index.core.node_parser import SentenceSplitter
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.vector_stores.chroma import ChromaVectorStore
import chromadb
# 1 · Configure global defaults
Settings.llm = OpenAI(model="gpt-4o-mini", temperature=0)
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
Settings.node_parser = SentenceSplitter(chunk_size=800, chunk_overlap=120)
# 2 · Persistent vector store
client = chromadb.PersistentClient(path="./chroma")
store = ChromaVectorStore(chroma_collection=client.get_or_create_collection("docs"))
storage = StorageContext.from_defaults(vector_store=store)
# 3 · Build (or rebuild) the index from a folder
docs = SimpleDirectoryReader("./data", recursive=True).load_data()
index = VectorStoreIndex.from_documents(docs, storage_context=storage)
# 4 · Ask
engine = index.as_query_engine(similarity_top_k=4, response_mode="compact")
print(engine.query("Summarise the access policy in 3 bullets."))
Best practiceGood to know
Configure Settings once at module top.Settings.llm, Settings.embed_model,
Settings.node_parser are picked up by every index / engine. Beats threading
kwargs through.
Hybrid retrieval beats dense-only on FAQ-shaped corpora.
Wire BM25Retriever + VectorIndexRetriever
into QueryFusionRetriever. Cheap accuracy win.
Use IngestionPipeline with a cache.
On repeat ingestion, unchanged chunks skip embedding entirely. Halves dev-loop cost.
Common trapsWatch out for
The umbrella llama-index package shifts heavy deps.
In prod, pin only the sub-packages you import (llama-index-core +
llama-index-llms-openai …). Otherwise you pull TF, torch, and friends
transitively.
Settings is process-global.
Two indices in the same process share the same LLM unless you pass a different one explicitly. Easy to
have an “eval” index silently inherit your prod model.
Persisting a store doesn’t persist Settings.
Reload requires re-setting Settings.embed_model to the same model used at
ingest. Mismatched dims raise on the first query.
LlamaIndex is a Python framework for building retrieval-augmented generation (RAG) and data-aware LLM applications. It provides a standardised pipeline for ingesting documents, splitting and embedding them into nodes, storing them in a vector index, and querying with a query engine or chat engine. It competes with LangChain's retrieval stack and has a more opinionated RAG-first design.
What is the difference between LlamaIndex and LangChain?
LlamaIndex is optimised for structured data ingestion and RAG: it has richer document loaders, node pipelines, and index types (vector, summary, keyword, knowledge graph) out of the box. LangChain is broader, covering agent orchestration, tool use, memory, and LCEL composition. Many teams use LlamaIndex for the retrieval layer and LangGraph or raw model calls for the agent layer.
How do I build a RAG pipeline with LlamaIndex?
Load documents with a reader (SimpleDirectoryReader or a specific loader), parse them into nodes with a node parser, create a VectorStoreIndex from the nodes, then call index.as_query_engine() to get a query engine. Query with engine.query(question) and the engine retrieves the top-k relevant nodes and synthesises a response using your LLM.
What are query engines in LlamaIndex?
A query engine is a high-level interface that combines retrieval and synthesis into a single call. index.as_query_engine() returns the default retriever + response synthesiser pair. You can customise the retriever (top-k, similarity threshold, hybrid), the response mode (compact, refine, tree summarise), and the reranker. For multi-turn conversations, use index.as_chat_engine() instead.
What vector stores does LlamaIndex support?
LlamaIndex ships integration packages for Chroma, Pinecone, Weaviate, Qdrant, pgvector, Redis, Milvus, and many more. Swap stores by passing a different VectorStore object to VectorStoreIndex.from_vector_store(). The default SimpleVectorStore is in-memory and useful for prototyping; move to a persistent store like Chroma or pgvector before going to production.