LlamaIndex 2026:文档Agent与RAG管道详解
文档散落在各处——PDF、Notion、数据库——想要一个统一问答接口。LlamaIndex就是为此而生。
LlamaIndex: The Data Framework for LLM Applications
LlamaIndex (51,277 GitHub stars, MIT license) is the data framework for LLM apps - the piece that connects your documents to your model. It popularized the term RAG in the developer world and has grown into a full platform for building document agents: ingest from 30+ sources, index into vector stores, query with advanced retrieval, and orchestrate agentic loops over your data.
The Core Concepts
Data connectors (LlamaHub). Read from PDFs, Notion, Confluence, Slack, databases, and web pages with one-line loaders. The hub has hundreds of community connectors.
Indexes. Convert documents into searchable structures: VectorStoreIndex (semantic search), SummaryIndex (whole-doc queries), and KnowledgeGraphIndex (relationships).
Query engines. The retrieval + synthesis loop that answers questions. You can compose them: route a question to the vector index or the summary index depending on intent.
Agents. The layer on top: an LLM with tools (query engines, document loaders, arbitrary functions) that decides what to call. A document agent can look at a PDF, find the relevant section, check another doc, and synthesize - multi-step reasoning over your data.
A Minimal Example
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
docs = SimpleDirectoryReader("docs/").load_data()
index = VectorStoreIndex.from_documents(docs)
query_engine = index.as_query_engine()
print(query_engine.query("What is our refund policy?"))
That is a working RAG app in six lines - load, index, query.
When to Reach for Agents
Query engines answer single questions; agents handle workflows - compare across documents, summarize a whole folder, then draft an email. The pattern in 2026: start with a query engine, add agentic tools only when questions become multi-step. Agents cost more tokens and add failure modes; the simpler tool that solves the problem is the better one.
FAQ
Is LlamaIndex free? Yes - MIT licensed open source; LlamaCloud is the paid hosted version.
LlamaIndex vs LangChain? Overlapping but different centers of gravity: LlamaIndex is data/index-first; LangChain is chain/agent-first. Many projects use both.
Does it work with local models? Yes - Ollama, vLLM, and any OpenAI-compatible endpoint.
Can it query SQL and vector stores together? Yes - SQL + vector + document indexes can be composed in one query pipeline.
