Metadata-Version: 2.4
Name: thrindex
Version: 0.2.3
Summary: The memory OS for AI agents — persistent memory, semantic search and LLM extraction.
Author-email: Thrindex <hello@thrindex.com>
License: Apache-2.0
Project-URL: Homepage, https://thrindex.com
Project-URL: Documentation, https://docs.thrindex.com
Project-URL: Repository, https://github.com/thrindex/thrindex.git
Keywords: ai,agents,memory,llm,openai,anthropic,langchain,semantic-search,rag
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.28.0
Requires-Dist: pydantic>=2.10.0
Provides-Extra: openai
Requires-Dist: openai>=1.0.0; extra == "openai"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.20.0; extra == "anthropic"
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.2.0; extra == "langchain"
Provides-Extra: llamaindex
Requires-Dist: llama-index-core>=0.10.0; extra == "llamaindex"
Provides-Extra: all
Requires-Dist: openai>=1.0.0; extra == "all"
Requires-Dist: anthropic>=0.20.0; extra == "all"
Requires-Dist: langchain-core>=0.2.0; extra == "all"
Requires-Dist: llama-index-core>=0.10.0; extra == "all"
Provides-Extra: dev
Requires-Dist: ruff>=0.9.0; extra == "dev"
Requires-Dist: mypy>=1.13.0; extra == "dev"
Requires-Dist: pytest>=8.3.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
Requires-Dist: anyio[trio]>=4.0.0; extra == "dev"

# Thrindex Python SDK

**The memory OS for AI agents** — persistent memory, semantic search, and LLM extraction.

Not storage. Not RAG. A cognition engine that ranks, compresses, and evolves agent memory across any model, any framework, at any scale.

[Website](https://thrindex.com) · [Docs](https://docs.thrindex.com) · [Get started](https://app.thrindex.com)

---

## What is Thrindex?

Thrindex is a memory layer for AI agents. Your agent writes what it learns and retrieves what it needs — automatically, at every turn.

- **Persistent memory** across sessions, users, and agents
- **Semantic search** powered by multi-signal fusion ranking
- **Fast retrieval** — designed for sub-100ms p99 on the read path
- **LLM extraction** — send raw conversation turns, get clean facts stored automatically

---

## Install

```bash
pip install thrindex
```

Optional integrations:

```bash
pip install "thrindex[openai]"
pip install "thrindex[anthropic]"
pip install "thrindex[langchain]"
pip install "thrindex[llamaindex]"
pip install "thrindex[all]"
```

---

## Quickstart

Three lines to add memory to any agent.

```python
from thrindex import Thrindex

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

memory_id = client.add(
    "User prefers concise responses and dislikes jargon",
    agent_id="my-agent",
    user_id="user-42",
)

memories = client.search(
    "how should I respond to this user?",
    agent_id="my-agent",
    user_id="user-42",
)

for m in memories:
    print(m.content, m.score)
```

---

## Async client

```python
from thrindex import AsyncThrindex

async with AsyncThrindex(api_key="th_live_...") as client:
    memory_id = await client.add(
        "User is based in Berlin and works in fintech",
        agent_id="my-agent",
        user_id="user-42",
    )
    results = await client.search(
        "where does the user work?",
        agent_id="my-agent",
        user_id="user-42",
    )
```

---

## Integrations

Drop Thrindex into your existing LLM calls with one wrapper. Memories are injected into every request and captured from every response — automatically.

### OpenAI

```python
from openai import OpenAI
from thrindex import Thrindex
from thrindex.integrations.openai import ThrindexOpenAI

client = ThrindexOpenAI(
    thrindex_client=Thrindex(api_key="th_live_..."),
    openai_client=OpenAI(api_key="sk-..."),
    agent_id="my-agent",
    user_id="user-42",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What do you know about me?"}],
)
```

### Anthropic

```python
from anthropic import Anthropic
from thrindex import Thrindex
from thrindex.integrations.anthropic import ThrindexAnthropic

client = ThrindexAnthropic(
    thrindex_client=Thrindex(api_key="th_live_..."),
    anthropic_client=Anthropic(api_key="sk-ant-..."),
    agent_id="my-agent",
    user_id="user-42",
)

response = client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "What are my preferences?"}],
)
```

### LangChain

```python
from thrindex.integrations.langchain import ThrindexChatMemory

memory = ThrindexChatMemory(
    api_key="th_live_...",
    agent_id="my-agent",
    user_id="user-42",
)
```

### LlamaIndex

```python
from thrindex.integrations.llamaindex import ThrindexMemoryPostprocessor

postprocessor = ThrindexMemoryPostprocessor(
    api_key="th_live_...",
    agent_id="my-agent",
    user_id="user-42",
)
```

---

## LLM extraction

By default, the cognition worker runs LLM fact extraction on every write — turning raw text into clean, discrete facts before storage.

```python
client.add(
    "They said they use FastAPI for the backend and Next.js on the frontend.",
    agent_id="my-agent",
    user_id="user-42",
)
```

When you already have a clean fact, bypass extraction:

```python
client.add(
    "User speaks Greek and English",
    agent_id="my-agent",
    user_id="user-42",
    extract=False,
)
```

---

## Memory scoping

Every memory is scoped to an `agent_id` and a `user_id`. The SDK requires both on write and search to keep isolation explicit.

| `agent_id` | `user_id` | Scope |
| ---------- | --------- | ----- |
| set | set | This user with this agent (most common) |

Use `list()` with optional filters to browse memories at broader scope within your org.

---

## API reference

| Method | Description |
| ------ | ----------- |
| `add(content, agent_id, user_id, ...)` | Store a memory |
| `search(query, agent_id, user_id, ...)` | Semantic search with multi-signal ranking |
| `list(agent_id, user_id, ...)` | Paginated list of memories |
| `get(memory_id)` | Fetch a single memory by ID |
| `delete(memory_id, hard=False)` | Soft delete or GDPR erasure |
| `batch_add(memories, agent_id, user_id)` | Store multiple memories |

Full documentation: [docs.thrindex.com](https://docs.thrindex.com)

---

## License

Apache 2.0 — see [LICENSE](https://github.com/thrindex/thrindex/blob/main/LICENSE).
