Memory that thinks. The cognitive memory layer for AI agents — events, episodes, beliefs, and background dreaming.
Project description
Memgraph SDK
Memory that thinks. The official Python SDK for Memgraph — the cognitive memory layer for AI agents.
Not a vector store with a wrapper. A three-layer cognitive engine that distills raw events into episodes and crystallizes them into beliefs — with background Cognitive Dreaming that improves memory while your agents sleep.
Installation
pip install memgraph-sdk
With optional extras:
pip install "memgraph-sdk[async]" # Async client (httpx)
pip install "memgraph-sdk[mcp]" # MCP server for Claude/Cursor
pip install "memgraph-sdk[all]" # Everything
Quick Start
from memgraph_sdk import MemgraphClient
client = MemgraphClient(api_key="mg_your_api_key")
# Store a memory
client.add("User prefers dark mode and uses PyTorch.", user_id="alice")
# Store a belief directly
client.remember("Prefers PyTorch over TensorFlow", user_id="alice", category="preference")
# Search for relevant context
result = client.search("What does this user prefer?", user_id="alice")
print(result)
That's it. Two lines to set up, then store and recall. The tenant_id is resolved automatically from your API key.
Async Client
from memgraph_sdk import AsyncMemgraphClient
async with AsyncMemgraphClient(api_key="mg_your_api_key") as client:
await client.add("User prefers dark mode", user_id="alice")
result = await client.search("user preferences", user_id="alice")
MCP Server (Claude / Cursor)
One command to give your AI IDE persistent memory:
memgraph setup --key mg_your_api_key
This auto-detects your IDE and writes the MCP config. Or configure manually:
{
"mcpServers": {
"memgraph": {
"command": "python3",
"args": ["-m", "memgraph_sdk.mcp"],
"env": {
"MEMGRAPH_API_KEY": "mg_your_api_key"
}
}
}
}
Memory Intelligence API
# Memory health metrics
health = client.health(user_id="alice")
# Detect contradictions
contradictions = client.contradictions(user_id="alice")
# Evaluate retrieval quality
evaluation = client.evaluate(query="test query", user_id="alice")
# Cognitive Integrity Score (0-100)
score = client.mcis(user_id="alice")
# Run benchmarks
result = client.benchmark(scenario="contradiction_storm")
CLI
# Set up MCP for your IDE (auto-detects Cursor, Claude, VS Code)
memgraph setup --key mg_your_api_key
# Store a memory
memgraph remember "We decided to use PostgreSQL" -c decision
# Search memories
memgraph recall "database choice"
# Check connection
memgraph status
Configuration
Cloud (default)
# Connects to https://api.memgraph.ai/v1 by default
client = MemgraphClient(api_key="mg_your_key")
Self-hosted
client = MemgraphClient(
api_key="mg_your_key",
base_url="http://your-server:8001/v1",
)
Or via environment variable:
export MEMGRAPH_API_URL=http://your-server:8001/v1
export MEMGRAPH_API_KEY=mg_your_key
URL Resolution Priority
base_urlparameter (highest priority)MEMGRAPH_API_URLenvironment variablehttps://api.memgraph.ai/v1(cloud default)
How It Works
Raw Input → Events → Episodes → Beliefs
│ │ │
(short-term) (grouped) (long-term)
- Events: Raw, immutable records with vector embeddings
- Episodes: Auto-grouped sequences with LLM summaries
- Beliefs: Extracted facts, preferences, decisions with confidence scores
- Cognitive Dreaming: Background worker that consolidates, deduplicates, and resolves contradictions while your agents sleep
Integrations
Works with any AI framework:
- LangChain — Memory, Retriever, Toolkit components
- OpenAI — Function-calling agent and Assistants API
- CrewAI — Search and Remember tools
- LlamaIndex — Retriever and ToolSpec
See the examples/ directory for complete integration examples.
Documentation
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memgraph_sdk-0.4.1.tar.gz.
File metadata
- Download URL: memgraph_sdk-0.4.1.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56cbdb875f6065722d38823217e6e531c8091d8617ae0c30e2574306d1ae76c4
|
|
| MD5 |
dff231d59f5dd5a8cbed9eef691fbcbf
|
|
| BLAKE2b-256 |
0bd44da5269fea333c28083b97f6580ab6f8be9f3a32e72537173bf9f19c018e
|
Provenance
The following attestation bundles were made for memgraph_sdk-0.4.1.tar.gz:
Publisher:
publish.yml on shubhamdev0/memgraph-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memgraph_sdk-0.4.1.tar.gz -
Subject digest:
56cbdb875f6065722d38823217e6e531c8091d8617ae0c30e2574306d1ae76c4 - Sigstore transparency entry: 1040536958
- Sigstore integration time:
-
Permalink:
shubhamdev0/memgraph-sdk@16bdb8d1c26fe808624b023a1d96a4b9c1c8ef29 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/shubhamdev0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16bdb8d1c26fe808624b023a1d96a4b9c1c8ef29 -
Trigger Event:
release
-
Statement type:
File details
Details for the file memgraph_sdk-0.4.1-py3-none-any.whl.
File metadata
- Download URL: memgraph_sdk-0.4.1-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41e18f458f387322a0baabc35ef4e087a5a39bb6de6e2b76819bbd715742f2bd
|
|
| MD5 |
a281b081406765403166f08e10d35e46
|
|
| BLAKE2b-256 |
11ba493657bfc51d1ae8ada8e6486e134d88e59f4c90eab7e9258e5aab14cf8e
|
Provenance
The following attestation bundles were made for memgraph_sdk-0.4.1-py3-none-any.whl:
Publisher:
publish.yml on shubhamdev0/memgraph-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memgraph_sdk-0.4.1-py3-none-any.whl -
Subject digest:
41e18f458f387322a0baabc35ef4e087a5a39bb6de6e2b76819bbd715742f2bd - Sigstore transparency entry: 1040537033
- Sigstore integration time:
-
Permalink:
shubhamdev0/memgraph-sdk@16bdb8d1c26fe808624b023a1d96a4b9c1c8ef29 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/shubhamdev0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16bdb8d1c26fe808624b023a1d96a4b9c1c8ef29 -
Trigger Event:
release
-
Statement type: