LlamaIndex Best Practices
Ten practices for building LlamaIndex knowledge bases and agents that stay grounded, measurable, and cheap enough to run.
Search across all documentation pages
Ten practices for building LlamaIndex knowledge bases and agents that stay grounded, measurable, and cheap enough to run.
Use this list when starting a RAG agent or when answers drift after a corpus update.
source, stable doc_id, and freshness fields; inherit metadata from Documents through the node parser.similarity_top_k with metrics, not defaults. Plot hit-rate and faithfulness versus k; higher k is not free.QueryEngineTool name/description decide agent routing; include scope and exclusions.| Stage | Habits | Exit criterion |
|---|---|---|
| Design | 1-3 | Corpus layout + versioning story written |
| Implement | 4-6 | Query/tool config matches workloads |
| Launch | 7-8 | Eval gates + access controls live |
| Operate | 9-10 | Ingest/serve split and traces in prod |
"search all company knowledge".# Pattern: explicit chunking + query engine tool + sources logged
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core.tools import QueryEngineTool
docs = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(
docs,
transformations=[SentenceSplitter(chunk_size=1024, chunk_overlap=128)],
)
qe = index.as_query_engine(similarity_top_k=4)
tool = QueryEngineTool.from_defaults(
qe,
name="policy_docs",
description="Internal policies only; not for product how-to questions.",
)
# Agent wiring omitted - log response.source_nodes in your trace layerVersioned ingestion (1), tool/query clarity (5), and eval gates (7). Without them, agents sound confident while drifting.
No. Routers help when partitions need different engines or prompts. A single clean corpus can stay one index.
On corpus change, embed/chunker change, or scheduled freshness jobs for living documents. Measure before/after hit-rate.
Yes at the conceptual level: pin models, metadata, evals, and server-side secrets. APIs differ by language.
After you have baseline hit-rate metrics. Rerankers can improve MRR but add latency and cost.
No. Managed parsing/indexing helps complex docs and ops scale; self-hosted pipelines remain valid.
Detect empty or low-score hits and force refuse/escalate tools instead of free-form generation.
Chunker/embed pins, tool descriptions, eval deltas, and that request paths cannot rebuild indexes inline.
Related: LlamaIndex Basics
Related: The LlamaIndex Mental Model: Documents, Indexes, and Query Engines
Related: Ingesting and Chunking Documents for an Agent's Knowledge Base
Related: Building a Query Engine Agent Over Your Own Data
Related: Evaluating Retrieval Quality in a LlamaIndex Pipeline
Related: Combining Multiple Indexes with Router Query Engines
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026