Skip to main content

Prerequisites

  • A Thrindex account and organization at app.thrindex.com.
  • An API key with Write (memory:write) and Read (memory:read) scopes. Copy it when shown — it cannot be retrieved again.

Store and search a memory

Install
pip install thrindex
Store a memory
from thrindex import Thrindex

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

memory_id = client.add(
    content="User prefers weekly email digests over push notifications.",
    agent_id="support-agent",
    user_id="user-42",
)
print(memory_id)  # "3f2e1d0c-..."
The call returns immediately with 202 Accepted. The memory is processed in the background and available for search within a few seconds.Search memories
results = client.search(
    query="how does the user want to be contacted",
    agent_id="support-agent",
    user_id="user-42",
)

for hit in results:
    print(f"[{hit.score:.3f}] {hit.content}")
results is a list of SearchHit objects ordered by relevance score. Inject the top results into your system prompt.

Typical agent loop

This is the recommended pattern for using Thrindex in a conversational agent:
from thrindex import Thrindex

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

def handle_turn(agent_id: str, user_id: str, user_message: str) -> str:
    # 1. Retrieve relevant memories before calling the LLM
    memories = client.search(
        query=user_message,
        agent_id=agent_id,
        user_id=user_id,
        k=5,
    )

    # 2. Build system prompt with memory context
    memory_block = "\n".join(f"- {m.content}" for m in memories)
    system_prompt = f"User context from previous sessions:\n{memory_block}"

    # 3. Call your LLM (any provider)
    response = your_llm_call(system_prompt=system_prompt, user_message=user_message)

    # 4. Store the turn as a new memory for future sessions
    client.add(
        content=user_message,
        agent_id=agent_id,
        user_id=user_id,
    )

    return response
Always call the API from your backend. Never put API keys in browser code or mobile clients.

Next steps

How it works

Understand memory levels, processing pipeline, and the search ranking model.

Python SDK

Full method reference, async client, batch operations, and error handling.

TypeScript SDK

Complete TypeScript reference with type definitions for every response.

LLM Integrations

Drop-in wrappers for OpenAI, Anthropic, LangChain, and LlamaIndex.