> ## Documentation Index
> Fetch the complete documentation index at: https://developers.agentx.so/llms.txt
> Use this file to discover all available pages before exploring further.

# LlamaIndex

> Evaluate a LlamaIndex RAG query engine

Install:

```bash theme={null}
pip install agentx-python llama-index llama-index-llms-openai
```

## Usage

```python theme={null}
from agentx import AgentX
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.openai import OpenAI

client = AgentX.from_env()

documents = SimpleDirectoryReader("./docs").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(llm=OpenAI(model="gpt-4o-mini"))

def llamaindex_agent(case):
    response = query_engine.query(case.query)
    return {"output": str(response), "metadata": {"model": "gpt-4o-mini"}}

run_context = (
    client.evaluations
    .run(dataset_id="...", subject={"kind": "custom_agent", "displayName": "Docs RAG Agent", "framework": "llamaindex"})
    .execute(llamaindex_agent)
    .finalize()
)
print(f"Average rating: {run_context.average_rating:.2f}")
```

Returning `metadata: {"model": ...}` records which model produced each response, powering the Sovereignty & Portability breakdown in the report. For a full Execution Timeline, use the [LlamaIndex tracing integration](/sdk/integrations/llamaindex) (its instrumentation handler captures LLM calls, retrievals, and tool calls automatically), or wrap calls in [`tracer.trace(..., sync=True)`](/sdk/tracing#linking-a-trace-to-an-evaluation-result) yourself. `response.source_nodes` (for a query engine) or `response.sources` (for an agent) are worth recording as tool calls or retrieval steps on that span.

A complete working example, with a RAG-vs-ReAct-agent toggle and per-source retrieval tracing, is available as [`llamaindex_eval.py`](https://github.com/AgentX-ai/AgentX-Python/blob/main/examples/evaluations/llamaindex_eval.py) in the AgentX-Python repository.
