LlamaIndex
LlamaIndex is a data framework for ingesting, indexing, and querying private data with LLMs. It handles chunking, embedding, retrieval, and response synthesis.
Search across all documentation pages
LlamaIndex is a data framework for ingesting, indexing, and querying private data with LLMs. It handles chunking, embedding, retrieval, and response synthesis.
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
Settings.llm = OpenAI(model="gpt-4o-mini")
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What is pytest?")"""llamaindex.py - build index and query."""
from llama_index.core import Document, VectorStoreIndex, Settings
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI as LlamaOpenAI
Settings.llm = LlamaOpenAI(model="gpt-4o-mini", temperature=0)
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
documents = [
Document(text="pytest uses fixtures to share test setup.", metadata={"source": "testing"}),
Document(text="FastAPI validates request bodies with Pydantic.", metadata={"source": "web"}),
]
index = VectorStoreIndex.from_documents(documents)
engine = index.as_query_engine(similarity_top_k=2)
response = engine.query("How do pytest fixtures work?")
print(response)
print("sources:", [n.metadata for n in response.source_nodes])SentenceSplitter chunk_size/overlap.response_mode="compact" with source nodes.| Alternative | Use When | Don't Use When |
|---|---|---|
| LlamaIndex | Data-heavy RAG with connectors | Simple one-off chains |
| LangChain | Tool/agent composition | Connector-heavy ingestion |
| Raw SDK | Minimal dependencies | Many data sources |
Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 19, 2026