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

# LlamaIndex

> LlamaIndex components that inject Thrindex memories into query pipelines and load memories as documents.

The LlamaIndex integration provides two Python components that slot into standard LlamaIndex query pipelines.

| Component                     | Interface               | Use case                                                      |
| ----------------------------- | ----------------------- | ------------------------------------------------------------- |
| `ThrindexMemoryPostprocessor` | `BaseNodePostprocessor` | Inject memories as extra nodes before LLM synthesis           |
| `ThrindexMemoryReader`        | `BaseReader`            | Load memories as `Document` objects for indexing or retrieval |

***

## Install

```bash theme={null}
pip install 'thrindex[llamaindex]'
```

***

## `ThrindexMemoryPostprocessor`

Retrieves relevant Thrindex memories and injects them as additional `TextNode` objects at the front of the node list before LLM synthesis. Attach it to any `RetrieverQueryEngine` or `QueryPipeline`.

```python theme={null}
from thrindex import Thrindex
from thrindex.integrations.llamaindex import ThrindexMemoryPostprocessor

client = Thrindex(api_key="th_live_...")

postprocessor = ThrindexMemoryPostprocessor(
    thrindex_client=client,
    agent_id="support-agent",
    user_id="user-42",
    k=5,               # memory nodes to inject per query, default 5
    task_context=None, # optional Thrindex ranking hint
    min_score=0.0,     # only inject memories at or above this score, default 0.0
)
```

Attach to a `RetrieverQueryEngine`:

```python theme={null}
from llama_index.core.query_engine import RetrieverQueryEngine

engine = RetrieverQueryEngine(
    retriever=your_retriever,
    node_postprocessors=[postprocessor],
)
response = engine.query("What are this user's preferences?")
```

Injected `TextNode` metadata includes `source: "thrindex_memory"`, `memory_id`, `agent_id`, `user_id`, `importance`, `level`, and `created_at`.

***

## `ThrindexMemoryReader`

A `BaseReader` that loads Thrindex memories as LlamaIndex `Document` objects. Use it to seed an index with an agent's memory corpus, or to pull memories into a retrieval pipeline.

```python theme={null}
from thrindex.integrations.llamaindex import ThrindexMemoryReader

reader = ThrindexMemoryReader(
    thrindex_client=client,
    agent_id="support-agent",
    user_id="user-42",
    k=10,  # documents per query, default 10
)

documents = reader.load_data(query="user notification preferences")
```

If `query` is empty, the reader searches using `"important context and preferences"` as a default query, returning the most important recent memories.
