Skip to main content

Official LangChain / LangGraph integration for Thrindex — persistent semantic memory for AI agents.

Project description

langchain-thrindex

Official LangChain / LangGraph integration for Thrindex — persistent, semantically-searchable long-term memory for AI agents.

Installation

pip install langchain-thrindex

Components

Class Interface Use case
ThrindexStore langgraph.store.base.BaseStore LangGraph agents — long-term memory across threads
ThrindexRetriever langchain_core.retrievers.BaseRetriever LCEL chains, RAG pipelines

ThrindexStore — LangGraph agents

The primary integration. Pass ThrindexStore to graph.compile(store=store) and your LangGraph agent gets persistent memory that survives restarts and scales across deployments.

from langchain_thrindex import ThrindexStore
from langgraph.prebuilt import create_react_agent

store = ThrindexStore(
    api_key="th_live_...",
    agent_id="customer-support-bot",  # stable identifier for your agent
)

# Compile the agent with persistent memory
agent = create_react_agent(
    model="openai:gpt-4o",
    tools=[...],
    store=store,
)

# The agent now reads and writes long-term memories automatically
result = agent.invoke(
    {"messages": [{"role": "user", "content": "My name is Alice and I prefer dark mode."}]},
    config={"configurable": {"thread_id": "thread-1"}},
)

Manual store operations

# Store a fact
store.put(
    ("memories", "user-42"),  # namespace: (category, user_id)
    "preference-display",     # unique key within the namespace
    {"content": "User prefers dark mode and compact layout"},
)

# Semantic search
results = store.search(
    ("memories", "user-42"),
    query="display preferences",
    limit=5,
)
for item in results:
    print(item.value["content"], item.score)

# Get by key
item = store.get(("memories", "user-42"), "preference-display")

# Delete
store.delete(("memories", "user-42"), "preference-display")

Async

All operations have async counterparts:

await store.aput(namespace, key, value)
item = await store.aget(namespace, key)
results = await store.asearch(namespace, query="...")
await store.adelete(namespace, key)

Namespace → Thrindex mapping

LangGraph Thrindex
agent_id constructor arg agent_id in every API call
"/".join(namespace) user_id in every API call

ThrindexRetriever — LCEL chains

from langchain_thrindex import ThrindexRetriever
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

retriever = ThrindexRetriever(
    api_key="th_live_...",
    agent_id="my-agent",
    user_id="user-42",
    k=5,
    task_context="answering user questions about product settings",
)

prompt = ChatPromptTemplate.from_template(
    "Use the following memories to answer the question.\n\n"
    "Memories:\n{context}\n\n"
    "Question: {question}"
)

chain = (
    {"context": retriever, "question": lambda x: x}
    | prompt
    | ChatOpenAI(model="gpt-4o")
    | StrOutputParser()
)

answer = chain.invoke("What display settings does the user prefer?")

Configuration reference

ThrindexStore

Parameter Type Default Description
api_key str required Thrindex API key
agent_id str "default" Stable agent identifier
base_url str "https://api.thrindex.com" API base URL (override for self-hosted)
timeout float 30.0 Request timeout in seconds
max_retries int 3 Retries on transient failures
extract bool True Run LLM fact extraction on stored memories

ThrindexRetriever

Accepts api_key, agent_id, user_id, k, task_context, base_url, timeout, max_retries. See class docstring for full details.


Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_thrindex-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_thrindex-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_thrindex-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_thrindex-0.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for langchain_thrindex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 edee6a56d33257a463affd9b81f82b245e8550d790648c943c55deb22021df74
MD5 35f94d7ca45359316b2660f857840332
BLAKE2b-256 2ae6ec7b67ecb3dd9881aa6dffa82324b57eac312b7f54158a585b5e4e39e1b2

See more details on using hashes here.

File details

Details for the file langchain_thrindex-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_thrindex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3b9ea15461f72433db40a9029bfb4d75426ff58c49f01cfc9145acbcce0c48c
MD5 a3b4a76f5539b9a1705b05d7394567ae
BLAKE2b-256 e124cedefb386e8b58c4f1aad68243ccf75178bb06f598ac5426b69ce288b52b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page