Building a LlamaIndex RAG on your internal documentation is one of the most worthwhile AI projects for an ops team: runbooks, on-call procedures, post-mortems and wiki pages sit in folders that nobody rereads in the middle of the night. An assistant that can find the right passage, and cite its source, saves precious minutes during an incident.
The trap is well known: a RAG prototype impresses in a demo, then misses the point as soon as you ask it a real question. The difference between the two is not the model, it is measurement. Without a reference set of questions and retrieval metrics, you change the chunk size or the embedding model blindly.
This article shows how to build a self-hosted LlamaIndex RAG on internal documentation, then how to evaluate its quality in a reproducible way. It is part of our comparison of self-hosted open source AI building blocks.
Why LlamaIndex for a RAG on internal documentation?
LlamaIndex is a Python framework (there is also a TypeScript version) focused on connecting data to an LLM. Where other frameworks concentrate on orchestrating agents, LlamaIndex emphasises ingesting, chunking, indexing and querying documents. That is exactly the core of a RAG (Retrieval-Augmented Generation).
Its main building blocks:
- Readers: load files (Markdown, PDF, HTML…) or external sources through connectors;
- Node parsers: split documents into chunks (nodes) with their metadata;
- Index: the most common,
VectorStoreIndex, computes embeddings and stores them in a vector store; - Query engines and retrievers: fetch the relevant chunks and build the answer;
- Evaluation module: ready-made evaluators for faithfulness, relevancy and retrieval quality.
The project is modular: the core is installed with llama-index-core, and each integration (LLM, embeddings, vector database) is a separate package. To keep everything in-house, you can rely on a model served locally by Ollama.
Target architecture
For documentation of a few thousand pages, a simple architecture is enough:
- an export of the documentation as Markdown or HTML in a versioned folder;
- an ingestion script that chunks the content, computes embeddings and persists the index;
- a query service that loads the index and queries a local LLM;
- an evaluation set replayed on every configuration change.
LlamaIndex’s default storage is in memory, and can be persisted to disk. Beyond a certain volume, or to share the index between several instances, a dedicated vector database (Qdrant, pgvector, Chroma, etc.) takes over through the corresponding integration package.
In practice: building a LlamaIndex RAG step by step
Step 1 — Install the packages
Install the core and the Ollama integrations for the LLM and the embeddings. Check the exact names in the documentation, as integrations change.
python -m venv .venv && source .venv/bin/activate
pip install llama-index-core llama-index-llms-ollama llama-index-embeddings-ollama
ollama pull llama3.1
ollama pull nomic-embed-text
Step 2 — Configure the LLM and the embedding model
The Settings object sets the defaults used by every component. The embedding model must stay the same between ingestion and querying.
from llama_index.core import Settings
from llama_index.llms.ollama import Ollama
from llama_index.embeddings.ollama import OllamaEmbedding
Settings.llm = Ollama(model="llama3.1", request_timeout=120.0)
Settings.embed_model = OllamaEmbedding(model_name="nomic-embed-text")
Settings.chunk_size = 512
Settings.chunk_overlap = 64
Step 3 — Ingest and persist the index
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
docs = SimpleDirectoryReader("./docs-internes", recursive=True).load_data()
index = VectorStoreIndex.from_documents(docs, show_progress=True)
index.storage_context.persist(persist_dir="./storage")
The reader keeps the file path in each chunk’s metadata: that is what lets you cite the source in the answer.
Step 4 — Query and display the sources
from llama_index.core import StorageContext, load_index_from_storage
ctx = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(ctx)
engine = index.as_query_engine(similarity_top_k=4)
resp = engine.query("How do I restart the log collector in production?")
print(resp)
for node in resp.source_nodes:
print(round(node.score or 0, 3), node.metadata.get("file_path"))
Always displaying the sources and their score is the first quality measure: an on-call engineer must be able to check with one click.
Step 5 — Build an evaluation set
Two approaches complement each other. The first: write 30 to 50 real questions by hand (taken from tickets or on-call channels) with the expected document. The second: generate question/context pairs from the chunks with a LlamaIndex dataset generator (for example DatasetGenerator from the evaluation module; available helpers vary by version), then review them. Generated questions are often too close to the text; human questions reveal the real gaps.
Step 6 — Measure retrieval and generation
Evaluate the two stages of the RAG separately:
- Retrieval: is the right chunk among the results? The
RetrieverEvaluatorcomputes, among others, the hit rate and the MRR (mean reciprocal rank). - Generation: is the answer faithful to the retrieved context (
FaithfulnessEvaluator) and relevant to the question (RelevancyEvaluator)?
from llama_index.core.evaluation import (
FaithfulnessEvaluator, RelevancyEvaluator, RetrieverEvaluator)
retriever = index.as_retriever(similarity_top_k=4)
ret_eval = RetrieverEvaluator.from_metric_names(
["hit_rate", "mrr"], retriever=retriever)
faith = FaithfulnessEvaluator()
relev = RelevancyEvaluator()
resp = engine.query(question)
print(faith.evaluate_response(response=resp).passing,
relev.evaluate_response(query=question, response=resp).passing)
The generation evaluators themselves use an LLM as a judge. With a small local model, their verdicts are noisy: use them to compare two configurations on the same set, not as an absolute score. Exact signatures may vary by version; the official LlamaIndex documentation is the authority.
How do you measure RAG quality over time?
Offline evaluation is not enough. In production, three families of signals matter:
- Perceived quality: user feedback (thumbs up or down), questions rephrased right after an answer, rate of « I don’t know » answers;
- Retrieval quality: distribution of similarity scores, share of queries whose best score is below a threshold (a sign of an undocumented topic);
- Performance and cost: retrieval and generation latency measured separately, tokens consumed per query, size of the injected context.
LlamaIndex exposes instrumentation points that let you send these steps as OpenTelemetry traces, through libraries such as OpenLLMetry or OpenInference. We detail the set-up in the article Langfuse and OpenLLMetry. To link these traces to the rest of your application, see also end-to-end OpenTelemetry.
Best practices
- Clean the source before indexing: outdated pages, duplicates and drafts degrade quality more than a poor model does.
- Add useful metadata (owning team, last update date, environment) and filter on it at query time.
- Version the index, the embedding model, the chunk size and the evaluation set together.
- Change only one parameter at a time and replay the full evaluation.
- Respect access rights: a RAG must not expose a page the user would not be allowed to read.
- Ask the model to answer « I don’t know » when the context is insufficient, and measure that rate.
Frequently asked questions
LlamaIndex or LangChain for a RAG?
Both can do RAG. LlamaIndex is more specialised in ingesting and indexing documents; LangChain and LangGraph are more geared towards orchestration and agents. Our article LangChain and LangGraph covers that second use case.
Do you need a dedicated vector database?
Not to get started: persisting to disk is enough for a prototype. A dedicated database becomes useful once the index is large, shared between several instances or updated continuously.
How many questions do you need to evaluate a RAG?
A few dozen real, representative questions are enough to compare configurations. What matters is keeping the same set from one version to the next and enriching it with the failures seen in production.
Conclusion
A LlamaIndex RAG on internal documentation takes a few dozen lines of code. What makes it reliable is the discipline around it: clean sources, a versioned evaluation set, retrieval and generation metrics measured separately, then traces in production. With these safeguards, the assistant becomes a credible on-call tool rather than a demo.
span.observer is an independent community blog, not affiliated with Dynatrace LLC or with the projects mentioned. Trademarks belong to their respective owners. Tools change quickly: check commands and options in their official documentation.
Originally published on span.observer. French version: https://span.observer/fr/llamaindex-rag-documentation-interne/.
Top comments (1)
For on-call docs, I'd add a small evaluation slice where two runbooks describe the same symptom but apply to different environments or versions. Count it as a failure if the answer cites a real passage from the wrong environment, even when the wording is faithful to that passage. That catches a gap that retrieval hit rate and faithfulness alone can miss.