◆ Open Beta

Graph-native memory
for LLM agents.

Drop-in context management API. Models your conversation as a semantic graph and retrieves only the most relevant messages at inference time — cutting token usage without losing coherence.

agent.py
from graphmem import GraphMemClient

gm = GraphMemClient("https://api.graphmem.dev", api_key="gm_sk_...")
conv_id = gm.conversations.create()["conversation_id"]

# Store a message pair
mid = gm.memory.add_prompt(conv_id, user_message)
ctx  = gm.memory.recall(conv_id, query=user_message)
reply = your_llm.chat(ctx["messages"])
gm.memory.add_response(mid, conv_id, reply)

Two retrieval layers.
One API.

Every message is embedded and wired into a semantic graph. At inference time, GraphMem traverses that graph to surface the most relevant context — automatically.

Layer 1 · Message Retrieval — finest granularity
① Ingest
Store
add_prompt() add_response() → pending node → complete node
② Build
Embed & Graph
Jina v4 embed pgvector HNSW Neptune edges cosine ≥ 0.4
③ Retrieve
Recall
recall(query) Set B top-K Set A' threshold Set C 1-hop + R
Layer 2 · Topic Intelligence — refined control
④ Cluster
Detect Topics
Louvain algo every 20 nodes background job
⑤ Label
Understand
Groq llm label + summary coherence score
⑥ Filter
Control Context
status() relevance() retrieve()

Semantic Graph Recall

The default retrieval path. For every query, GraphMem runs a multi-set graph traversal across your conversation history and returns a token-budgeted, timestamp-ordered context window — ready to inject into your LLM.

Set B — strict top-K nodes by cosine similarity via pgvector HNSW index
Set A' — all nodes directly reachable from the query embedding above threshold
Set C — 1-hop Neptune graph expansion from Set B, catching connected context
Set R — always-recent guard, exempt from token budget cuts
Token budgeting: rank by relevance → cut → re-sort by timestamp
recall.py
result = gm.memory.recall(
    conv_id,
    query  = "user's latest message",
    k      = 5,
    strategy = "semantic",
    always_include_recent = 2,
    max_tokens = 2000,
)

# result.messages     → ordered list
# result.total_tokens → token count
# result.strategy_used

# inject directly into your LLM
response = llm.chat(
    context=result.messages,
    query=user_message,
)

Topic Intelligence

As your conversation grows, GraphMem clusters messages into topics using Louvain community detection. These topic APIs give you fine-grained control over what goes into your LLM's context — and how many tokens you spend.

gm.topics.list()
Conversation map
Returns every topic discovered in a conversation — id, label, message count, last active time. The entry point to the entire topic layer.
gm.topics.current()
Conversation state
What topic is the conversation in right now — based on the last complete message node, not the incoming query. Essential for agents that need to track context shifts.
gm.topics.status()
Active · Dormant · Resolved
Filter by topic lifecycle. Exclude resolved topics from context entirely. Keep only active ones. Directly controls how aggressively token savings kick in for your agent.
gm.topics.summary()
Compress a whole topic
One LLM-generated string replaces an entire topic's messages. When a topic is relevant but not the main focus — pass the summary, not 20 raw messages.
gm.topics.relevance()
Score topics by query
For a given prompt, scores all topics by semantic similarity and returns the top-K. Enables two-stage retrieval — topic first, messages second — cutting comparisons from N messages to just T topics.
gm.topics.messages()
Single-topic retrieval
Fetch all nodes that belong to one topic. Narrows context to exactly the slice of the conversation that matters — nothing else.
gm.topics.retrieve()
Full two-stage retrieval
Calls topics.relevance() then topics.messages() for each top-K topic in one call. The most token-efficient retrieval path GraphMem offers. Use when your conversation has matured enough to have multiple distinct topics and you want maximum context precision.
50 messages, 10 topics → compare against 10 centroids, not 50 embeddings
Combine with status() to skip resolved topics entirely
two_stage.py
# Two-stage: topic → messages
ctx = gm.topics.retrieve(
    conv_id,
    query      = user_message,
    top_n      = 3,
    max_tokens = 1500,
)

# Or use summary instead of raw messages
for topic in gm.topics.list(conv_id):
    summary = gm.topics.summary(topic["topic_id"])
    status  = gm.topics.status(topic["topic_id"])

Up in two minutes.

Install the SDK, create a conversation, start storing and recalling.

1 · Install

terminal
pip install graphmem-sdk

2 · Use

quickstart.py
from graphmem import GraphMemClient

gm = GraphMemClient(
    "https://api.graphmem.dev",
    api_key="gm_sk_...",
)

# Create a conversation (one per user session)
conv_id = gm.conversations.create()["conversation_id"]

# Your agent loop
while True:
    user_msg = input("You: ")

    # 1. Store the prompt, get memory_id back
    mid = gm.memory.add_prompt(conv_id, user_msg)

    # 2. Recall relevant context from the graph
    ctx = gm.memory.recall(conv_id, query=user_msg, max_tokens=2000)

    # 3. Call your LLM with the relevant context
    reply = your_llm.chat(context=ctx["messages"], query=user_msg)

    # 4. Store the response to complete the memory node
    gm.memory.add_response(mid, conv_id, reply)
    print(f"Agent: {reply}")
Get your API key → Full API reference