Skip to main content
The LangChain integration provides two components that plug directly into any chain or agent that uses the standard LangChain interfaces.
ComponentInterfaceUse case
ThrindexChatMemoryBaseMemoryPersist conversation turns and load relevant memories as chat history context
ThrindexRetrieverBaseRetrieverSemantic memory search inside RAG chains, RetrievalQA, agents

Install

pip install 'thrindex[langchain]'

ThrindexChatMemory

A BaseMemory implementation that saves conversation turns to Thrindex after each chain call and retrieves the most relevant memories before the next one.
from thrindex import Thrindex
from thrindex.integrations.langchain import ThrindexChatMemory

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

memory = ThrindexChatMemory(
    thrindex_client=client,
    agent_id="support-agent",
    user_id="user-42",
    memory_key="history",   # key injected into chain inputs, default "history"
    k=10,                   # memories to retrieve per call, default 10
    return_messages=True,   # True = BaseMessage objects, False = plain string
)
Use with any chain that accepts a memory parameter:
from langchain.chains import ConversationChain
from langchain_openai import ChatOpenAI

chain = ConversationChain(
    llm=ChatOpenAI(model="gpt-4o"),
    memory=memory,
)
response = chain.invoke({"input": "What notification style do I prefer?"})

ThrindexRetriever

A BaseRetriever that wraps Thrindex semantic search. Use it anywhere LangChain accepts a retriever — RetrievalQA, LCEL chains, agents, and more.
from thrindex.integrations.langchain import ThrindexRetriever

retriever = ThrindexRetriever(
    thrindex_client=client,
    agent_id="support-agent",
    user_id="user-42",
    k=5,                                            # results to return, default 5
    task_context="answering user preference query", # optional ranking hint
)

docs = retriever.invoke("user notification preferences")
for doc in docs:
    print(doc.page_content, doc.metadata["score"])
Each returned Document has page_content set to the memory text and metadata containing memory_id, agent_id, user_id, score, importance, level, and created_at.