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

# LlamaIndex integration

> Use QWEDQueryEngine wrapper for LlamaIndex to add verification to RAG pipelines. Includes math and fact checking for retrieval-augmented generation workflows.

## Installation

```bash theme={null}
pip install qwed llama-index
```

## Quick start

```python theme={null}
from qwed_sdk.llamaindex import QWEDQueryEngine

# Wrap any query engine with verification
verified_engine = QWEDQueryEngine(base_engine)

response = verified_engine.query("What is 15% of 200?")
print(response.verified)  # True/False
print(response.response)  # The answer
```

## QWEDQueryEngine

Wraps any LlamaIndex query engine to add verification:

```python theme={null}
from llama_index.core import VectorStoreIndex
from qwed_sdk.llamaindex import QWEDQueryEngine

# Create base engine
index = VectorStoreIndex.from_documents(documents)
base_engine = index.as_query_engine()

# Wrap with QWED
verified_engine = QWEDQueryEngine(
    base_engine,
    api_key="qwed_...",
    verify_math=True,
    verify_facts=True,
    auto_correct=False,
)

response = verified_engine.query("Calculate the total cost")
print(response.verified)
```

## QWEDVerificationTransform

Node postprocessor that verifies retrieved content:

```python theme={null}
from qwed_sdk.llamaindex import QWEDVerificationTransform

engine = index.as_query_engine(
    node_postprocessors=[
        QWEDVerificationTransform(
            verify_math=True,
            verify_code=True,
        )
    ]
)
```

## QWEDCallbackHandler

Track verification across all operations:

```python theme={null}
from llama_index.core import Settings
from qwed_sdk.llamaindex import QWEDCallbackHandler

Settings.callback_manager.add_handler(
    QWEDCallbackHandler(log_all=True)
)
```

## QWEDVerifyTool

For LlamaIndex agents:

```python theme={null}
from llama_index.core.agent import ReActAgent
from qwed_sdk.llamaindex import QWEDVerifyTool

tools = [QWEDVerifyTool()]
agent = ReActAgent.from_tools(tools, llm=llm)
```

## VerifiedResponse

```python theme={null}
@dataclass
class VerifiedResponse:
    response: str
    verified: bool
    status: str
    confidence: float
    attestation: Optional[str]
    source_nodes: List[Any]
```
