Home/Documentation

LangSmith

ObservabilityPython SDK Integration

Trace MemoAir memory retrieval in LangSmith so you can inspect which memories, graph facts, and reasoning paths were injected before the model answered.

Install

install.sh
BASH
pip install "memoair[langsmith]"

If you already use MemoAir through LangChain, install both optional extras with pip install "memoair[langchain,langsmith]".

LangChain Apps

LangChain automatically traces retrievers, tools, and model calls when LangSmith tracing is enabled. Use MemoAir's existing LangChain primitives and set the LangSmith environment variables.

.env
BASH
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY="lsv2_..."
export LANGSMITH_PROJECT="memoair-agent"
export MEMOAIR_API_KEY="memoair_pk_..."
export MEMOAIR_WORKSPACE_ID="ws_default"
langchain_tracing.py
PYTHON
from langchain_openai import ChatOpenAI
from memoair import MemoAir
from memoair.integrations.langchain import MemoAirMemory
 
client = MemoAir(user_id="alice")
memory = MemoAirMemory(client=client, group_id="user:alice")
 
agent = ChatOpenAI(model="gpt-4o")
context = memory.get_context("What should I remember before answering?")
 
response = agent.invoke([
("system", f"Use this MemoAir context when helpful:\n{context}"),
("user", "Which backend framework should I use?"),
])
 
memory.save_interaction(
user_message="Which backend framework should I use?",
assistant_message=str(response.content),
)

Direct SDK Tracing

For non-LangChain apps, wrap MemoAir search in a LangSmith retriever span. The helper returns LangSmith-compatible documents so retrieved memories get dedicated document rendering in the trace.

direct_sdk_tracing.py
PYTHON
from memoair import MemoAir
from memoair.integrations.langsmith import trace_memoair_search
 
client = MemoAir(
api_key="memoair_pk_...",
workspace_id="ws_default",
user_id="alice",
)
 
documents = trace_memoair_search(
client,
"What does Alice prefer for backend work?",
user_id="alice",
workspace_id="ws_default",
scope="all",
limit=5,
metadata={"environment": "production", "agent": "support-bot"},
)
 
context = "\n".join(doc["page_content"] for doc in documents)

What appears in LangSmith: each MemoAir result is rendered as a retriever document with memory ID, note ID, score, scope, user ID, workspace ID, and graph evidence metadata.

Evaluate Memory Quality

LangSmith RAG evaluations map cleanly onto memory apps. Use retrieved MemoAir documents as the evidence set, then score whether retrieval was relevant and whether the final answer stayed grounded in memory.

memory_eval_notes.py
PYTHON
# Evaluation dimensions to track in LangSmith:
# 1. Retrieval relevance: are the returned memories useful for the user question?
# 2. Groundedness: is the assistant answer supported by retrieved MemoAir context?
# 3. Save quality: should this turn create or update a long-term memory?

What You Get

Retriever Visibility
See every retrieved memory as a LangSmith document with score, source metadata, and scope.
Graph Evidence
Include MemoAir graph facts and reasoning paths in the same trace as memory snippets.
Tagged Runs
Filter traces by memoair, user, workspace, project, profile, or deployment environment.
Memory Evals
Reuse LangSmith RAG evaluation patterns for retrieval relevance, answer groundedness, and save quality.