ThrindexOpenAI wrapper replaces your OpenAI instance. Every chat.completions.create call automatically retrieves relevant memories and injects them into the system prompt before the call, then captures the conversation turn as a new memory after it.
Memory retrieval failures are always silent — if Thrindex is unreachable, the underlying OpenAI call proceeds unaffected.
Install
- Python
- TypeScript
Usage
Options
- Python
- TypeScript
| Parameter | Type | Default | Description |
|---|---|---|---|
thrindex_client | Thrindex | AsyncThrindex | required | A configured Thrindex client instance |
openai_client | OpenAI | AsyncOpenAI | None (auto-creates from env) | Your OpenAI client instance |
agent_id | str | required | Agent identifier for memory scoping |
user_id | str | required | User identifier for memory scoping |
inject_k | int | 5 | Number of memories to retrieve and inject per call |
inject | bool | True | Whether to inject memories before the call |
capture | bool | True | Whether to store conversation turns after the call |
capture_assistant | bool | True | When True, captures both the user message and the assistant reply as a single turn (richer extraction context). Set to False to capture only the user message. |
format_memories | Callable | bullet list | Custom formatter taking a list[SearchHit] and returning a str. |
Custom memory format
You can fully control how memories are formatted in the system prompt. This is useful when you want XML tags, numbered lists, or any format your model responds to best.- Python
- TypeScript