LlamaIndex: Data Framework for LLM Applications & RAG
LlamaIndex is the leading data framework for building LLM applications over custom data. It excels at the ingestion-to-retrieval pipeline: loading from 100+ data sources, intelligent chunking into Nodes, building vector/summary/keyword indexes, and powering sophisticated query engines for RAG, multi-document Q&A, and agent tool use.
Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
JSON Formatter & Validator
Format, beautify, and validate JSON online. Paste your JSON to instantly pretty-print it with 2-space, 4-space, or tab indentation. Minify JSON too. Free, runs in your browser.
Open free tool →
Regex Tester
Free regex tester. Test regular expressions against multiple strings with expected match/no-match assertions — see instant pass/fail results. Built-in presets for email, URL, IPv4, and phone. Pro: unl
Open free tool →
Base64 Encoder & Decoder
Free Base64 Encoder & Decoder. Convert text, images, and any file to Base64 and back. Supports URL-safe Base64, image data URIs, and file download from Base64. Runs 100% in your browser — no data sent
Open free tool →
More Free Tools
Related Articles
curl 深度使用手冊:API 測試從入門到進階
curl 是每位開發者必備的 CLI 工具。本文涵蓋 GET/POST/PUT/DELETE 請求、認證、header 設定、檔案上傳、除錯技巧,以及 REST API 測試的完整實戰範例。
Best AI Code Review Tools 2026: CodeRabbit, Sourcery, DeepCode & Bito Compared
Compare top AI code review tools for 2026: CodeRabbit, Sourcery, DeepCode, and Bito. Features, pricing, GitHub/GitLab integration, and choosing the right tool for your team.
AI Code Review Tools 2026: GitHub Copilot, CodeRabbit, Qodo Merge Ranked
Compare AI code review tools for 2026: GitHub Copilot code review, CodeRabbit, Qodo Merge, Sourcery, and PR-Agent. Pricing, accuracy, and GitHub integration.
AI Coding Tools Comparison 2026: GitHub Copilot vs Cursor vs Windsurf vs Cline
Comprehensive comparison of the best AI coding tools in 2026: GitHub Copilot, Cursor, Windsurf, and Cline. Pricing, features, model support, and real-world benchmarks.
AI Pair Programming in 2026: GitHub Copilot vs Cursor vs Claude Code
Master AI pair programming in 2026. Compare GitHub Copilot, Cursor, and Claude Code for autocomplete, chat, and agentic workflows. Includes setup guides and productivity tips.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →Core Pipeline: Load, Index, and Query
The fundamental LlamaIndex workflow — load documents, build a VectorStoreIndex, and query with natural language.
pip install llama-index llama-index-embeddings-openai llama-index-llms-openai
from llama_index.core import (
SimpleDirectoryReader,
VectorStoreIndex,
Settings,
StorageContext,
load_index_from_storage
)
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding
# Global settings — applied to all indexes and query engines
Settings.llm = OpenAI(model="gpt-4o-mini", temperature=0)
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
Settings.chunk_size = 1024
Settings.chunk_overlap = 128
# Load documents from a directory (supports PDF, DOCX, MD, TXT, HTML, CSV...)
documents = SimpleDirectoryReader("./data").load_data()
print(f"Loaded {len(documents)} documents")
# Build a VectorStoreIndex (embeddings auto-generated for each chunk)
index = VectorStoreIndex.from_documents(documents, show_progress=True)
# Persist to disk
index.storage_context.persist(persist_dir="./index_storage")
# Later: reload from disk (no re-embedding needed)
storage_context = StorageContext.from_defaults(persist_dir="./index_storage")
loaded_index = load_index_from_storage(storage_context)
# Create a query engine and ask questions
query_engine = loaded_index.as_query_engine(similarity_top_k=4)
response = query_engine.query("What is the main architecture of the system?")
print(response)
# Access source nodes used for the answer
for node in response.source_nodes:
print(f" score={node.score:.3f} | {node.text[:100]}...") Custom Node Parsing & Metadata Enrichment
Control how Documents are split into Nodes and enrich Nodes with metadata for better retrieval.
from llama_index.core.node_parser import (
SentenceSplitter,
SemanticSplitterNodeParser,
HierarchicalNodeParser
)
from llama_index.core.extractors import (
TitleExtractor,
QuestionsAnsweredExtractor,
SummaryExtractor
)
from llama_index.core.ingestion import IngestionPipeline
# Build an ingestion pipeline with custom transformations
pipeline = IngestionPipeline(
transformations=[
# Hierarchical splitter: creates parent (512) + child (128) chunks
HierarchicalNodeParser.from_defaults(chunk_sizes=[512, 128]),
# Auto-extract metadata using LLM
TitleExtractor(nodes=3), # extract document titles
QuestionsAnsweredExtractor(questions=3), # what questions does this answer?
]
)
nodes = pipeline.run(documents=documents)
print(f"Created {len(nodes)} nodes from {len(documents)} documents")
for node in nodes[:2]:
print(f" chars={len(node.text)} | metadata={list(node.metadata.keys())}")
# Auto-merging retriever (retrieves child chunks, merges to parent context)
from llama_index.core.retrievers import AutoMergingRetriever
from llama_index.core.storage.docstore import SimpleDocumentStore
docstore = SimpleDocumentStore()
docstore.add_documents(nodes)
index = VectorStoreIndex(nodes)
base_retriever = index.as_retriever(similarity_top_k=12)
auto_merging_retriever = AutoMergingRetriever(
base_retriever, storage_context=index.storage_context, verbose=True
) Query Routing & Multi-Document Synthesis
Route queries to different indexes automatically, or break complex questions into sub-questions.
from llama_index.core.tools import QueryEngineTool
from llama_index.core.query_engine import SubQuestionQueryEngine, RouterQueryEngine
from llama_index.core.selectors import LLMSingleSelector
# Create specialized indexes for different document sets
qdrant_index = VectorStoreIndex.from_documents(qdrant_docs)
milvus_index = VectorStoreIndex.from_documents(milvus_docs)
# Wrap as tools with descriptions for routing
tools = [
QueryEngineTool.from_defaults(
query_engine=qdrant_index.as_query_engine(),
name="qdrant_guide",
description="Information about Qdrant vector database, payload filtering, and sparse vectors"
),
QueryEngineTool.from_defaults(
query_engine=milvus_index.as_query_engine(),
name="milvus_guide",
description="Information about Milvus distributed database, DiskANN, and billion-scale search"
),
]
# RouterQueryEngine — LLM picks which tool to use
router_engine = RouterQueryEngine(
selector=LLMSingleSelector.from_defaults(),
query_engine_tools=tools,
verbose=True
)
response = router_engine.query("How does Qdrant's payload filtering compare to SQL WHERE clauses?")
print(response)
# SubQuestionQueryEngine — breaks complex queries into sub-questions
sub_engine = SubQuestionQueryEngine.from_defaults(query_engine_tools=tools, verbose=True)
response = sub_engine.query(
"Compare the index types supported by Qdrant and Milvus, and which is better for 1B vectors?"
) LlamaIndex vs LangChain vs Haystack
| Dimension | LlamaIndex | LangChain | Haystack |
|---|---|---|---|
| Primary strength | Data ingestion + RAG | Agents + chaining | NLP pipelines |
| RAG sophistication | Excellent (hierarchical, multi-doc) | Good | Good |
| Agent support | Good | Excellent | Basic |
| Data loaders | 100+ (LlamaHub) | 80+ | 40+ |
| PDF parsing | LlamaParse (best-in-class) | PyPDF2 / Unstructured | Haystack PDF converters |
| Observability | LlamaCloud | LangSmith | Hayhooks |
| Best for | Complex RAG, doc Q&A | General AI apps, agents | Production NLP systems |
Frequently Asked Questions
What is LlamaIndex and what problems does it solve?▼
LlamaIndex (formerly GPT Index) is a data framework for building LLM applications that need to reason over custom data. Its core strength is the ingestion, structuring, and retrieval layer — it handles loading data from 100+ sources, chunking, embedding, storing in vector indexes, and building sophisticated query engines. It is the go-to choice for complex RAG patterns like multi-document synthesis, hierarchical retrieval, and query routing.
What is the difference between Documents, Nodes, and Indexes?▼
Documents are the raw data containers — loaded from files, web pages, or databases. Nodes are the chunked, processed units derived from Documents — each Node has text, metadata, and an embedding. Indexes organize Nodes for retrieval: VectorStoreIndex stores Nodes as embeddings for semantic search, SummaryIndex chains Nodes for sequential processing, KeywordTableIndex enables keyword lookup. The Document → Node → Index pipeline is the core LlamaIndex data model.
What are query engines in LlamaIndex?▼
A QueryEngine is the interface that takes a natural language query and returns a response using the data in an index. VectorIndexQueryEngine does similarity search + LLM synthesis. SummaryIndexQueryEngine iterates through all nodes to synthesize an answer. RouterQueryEngine dynamically selects which sub-engine to use based on the query. SubQuestionQueryEngine breaks complex queries into sub-questions, queries multiple indexes, then synthesizes a combined answer.
How does LlamaIndex integrate with HuggingFace models?▼
LlamaIndex supports HuggingFace for both LLMs and embeddings. For embeddings, use HuggingFaceEmbedding with any sentence-transformer model — the embedding runs locally with no API cost. For LLMs, use HuggingFaceLLM to run open-source models (Llama 3, Mistral, Qwen) locally via transformers. This enables fully local RAG pipelines with zero API costs and complete data privacy.
LlamaIndex vs LangChain: which should I choose for RAG?▼
LlamaIndex excels at sophisticated RAG — advanced chunking strategies, multi-document synthesis, hierarchical indexes, query routing, and retrieval evaluation. LangChain excels at agent orchestration, multi-step tool use, diverse LLM integrations, and general application chains. For pure RAG with complex retrieval requirements, LlamaIndex is the stronger choice. For agentic workflows with tools, LangChain wins. Many teams use both: LlamaIndex for the retrieval layer, LangChain for agent orchestration.
What is LlamaCloud?▼
LlamaCloud is LlamaIndex's managed platform providing hosted parsing (LlamaParse — best-in-class PDF/document parsing), managed indexing pipelines, and observability. LlamaParse handles complex PDFs with tables, images, and multi-column layouts far better than PyPDF2 or pdfminer. It is available on a free tier (1000 pages/day) and paid plans for production use.
Related Products
on GumroadAI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →AI Developer Prompts Pack
55 battle-tested prompt templates for the workflows developers actually use: code review, debugging, architecture, documentation, and testing. Stop writing prompts from scratch.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
AI Hallucination Detector
Scan LLM-generated text for hallucination risk signals: fabricated citations, overconfident claims, suspect statistics, and verification gaps. Risk score 0-100 with highlighted problem spans.
Open free tool →
AI Safety Checklist Generator
Generate a customized AI safety evaluation checklist for your deployment. Covers technical safety, content moderation, security, bias, privacy, and regulatory compliance. Export to Markdown.
Open free tool →
CrewAI Agent Config Generator
Build CrewAI agent configurations visually. Define roles, goals, backstories, and tools. Generate YAML or Python code for multi-agent crews.
Open free tool →
More Free Tools
Related Articles
Building Production RAG Systems with LlamaIndex and Vector Databases 2026
Complete guide to building production-ready RAG systems with LlamaIndex v0.10+. Covers chunking strategies, embedding models, Chroma, Pinecone, Weaviate integration, and advanced retrieval patterns.
Building a Production RAG Pipeline: Complete Implementation Guide 2026
A comprehensive guide to building production-ready RAG pipelines in 2026. Covers chunking strategies, embedding models, vector store selection, retrieval techniques, reranking, evaluation with RAGAS/TruLens, and LangChain vs LlamaIndex vs custom implementations.
Vector Database Comparison 2026: Pinecone vs Weaviate vs Qdrant vs Chroma
In-depth comparison of the top vector databases in 2026. Evaluate Pinecone, Weaviate, Qdrant, and Chroma on performance, scalability, filtering, pricing, and self-hosting for production AI applications.
Vector Databases Explained: Pinecone vs Weaviate vs Qdrant vs Chroma (2026 Guide)
A complete comparison of the best vector databases in 2026: Pinecone, Weaviate, Qdrant, Chroma, and pgvector. Pricing, code examples, performance benchmarks, and a clear decision framework for AI and LLM applications.
Building a RAG Pipeline from Scratch: Embeddings, Vector Databases, and Retrieval
Step-by-step guide to building a production-ready RAG pipeline in Python. Covers embeddings, chunking strategies, Chroma and Pinecone setup, hybrid search, reranking, and evaluation with RAGAS.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →