Introduction to LlamaIndex

What is LlamaIndex?

LlamaIndex (formerly GPT Index) is an open-source framework for context-augmented LLM apps, maintained by LlamaIndex. It packages “connect data → parse and chunk → index → retrieve → generate / agent” into Python (and TypeScript) APIs so you can answer questions over private documents, extract structured fields, or let an agent reason over retrieval.

Official building blocks:

  • Data connectors — ingest directories, PDFs, SQL, APIs into Document objects
  • Indexes — intermediate representations the LLM can consume (vector indexes are the default)
  • EnginesQueryEngine for one-shot Q&A, ChatEngine for multi-turn chat
  • Agents — query engines, functions, and APIs as tools
  • Workflows — event-driven multi-step orchestration (retrieve, reflect, correct, HITL)
  • LlamaHub / integrations — hundreds of readers, vector stores, LLMs, embeddings

Enterprises also have LlamaCloud (LlamaParse and managed indexing). This tutorial stays on the open-source Python framework.


Mental model: data in the middle

┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  Your sources │ --> │ LlamaIndex   │ --> │  LLM / Agent │
│  files/DB/API │     │ load·index   │     │  generate    │
└──────────────┘     └──────────────┘     └──────────────┘
flowchart LR
  D[Documents] --> N[Nodes]
  N --> I[Index]
  Q[User question] --> R[Retriever]
  I --> R
  R --> E[QueryEngine / Agent]
  E --> A[Answer]

A Document is a whole source plus metadata. A Node is a chunk that keeps a link to its parent. VectorStoreIndex.from_documents chunks and embeds for you. At query time the retriever fetches Nodes and the query engine synthesizes an answer—classic RAG. When the model should decide whether and what to search, wrap the query as a tool on FunctionAgent.


LlamaIndex vs LangChain vs CrewAI

Three courses on this site cover three common paths—they are not a single “correct” stack:

LlamaIndex (this course)LangChainCrewAI
RoleData / RAG-centric: connectors, indexes, query enginesAgent harness: create_agent, tools, middleware, LangGraphRole crews: agents, tasks, processes
StrengthIngestion, chunking, retrieval compositionTool loops, state, HITL, observabilityWho-does-what collaboration scripts
Typical entryVectorStoreIndex + as_query_enginecreate_agentCrew / Agent / Task
FitKnowledge Q&A, extraction, hybrid searchMulti-tool assistants, graph orchestrationResearch-and-write pipelines

Common composition:

  • Build the index in LlamaIndex; expose as_query_engine() or a retriever as a LangChain / CrewAI tool
  • Learn vocabulary in the RAG tutorial, implement it here, then jump to LangChain or CrewAI for agent orchestration

Skip a framework when you have a one-shot prompt, no private corpus, and no retrieval—call the Chat API directly.


Default models (follow current docs)

Older docs and the starter bundle often say: if you configure nothing, generation uses OpenAI gpt-3.5-turbo and embeddings use text-embedding-ada-002. Official starter samples now use gpt-4o-mini. This tutorial always writes gpt-4o-mini and recommends setting LLM and embeddings on Settings so a silent default change does not surprise your bill or quality. Prefer the current framework docs.


Good fit / caveats

Good fit: Q&A over internal Markdown / PDF / exports with citations; swappable loaders / parsers / vector stores; document agents that mix math, APIs, and retrieval; event workflows that loop and branch.

Watch out: ultra-low latency without embedding caches; OpenAI reachability (swap in Ollama + Hugging Face embeddings); compliance before sending documents to a cloud embedder.


Packages

PackagePurpose
llama-indexStarter bundle: core + OpenAI LLM/embeddings + file readers
llama-index-coreIndexes, querying, agents, workflows
llama-index-llms-* / llama-index-embeddings-*Model providers
llama-index-vector-stores-*Chroma, Postgres, Qdrant, …
llama-index-workflowsStandalone Workflows SDK

GitHub: run-llama/llama_index · connectors: LlamaHub


Next steps

评论