MemgraphAI

Quick Start

Get Memgraph running and store your first memory in under 5 minutes.

1Create an account or self-host

Sign up at memgraph.ai/signup to get a hosted account. Or self-host with Docker Compose on your own infrastructure.

When you sign up, you get a tenant (your isolated workspace) and an API key starting with mg_.

2Install the SDK

bash
pip install memgraph-sdk

Requires Python 3.9+. The SDK includes sync client, async client, and CLI.

3Initialize the client

python
from memgraph_sdk import MemgraphClient

client = MemgraphClient(
    api_key="mg_your_api_key_here",
    tenant_id="your-tenant-uuid",
    # base_url defaults to MEMGRAPH_API_URL env var, or https://api.memgraph.ai/v1
)

Find your tenant ID and API key in the Dashboard Settings page, or use the onboard endpoint response.

4Store a memory

python
# remember() creates a belief with vector embedding — immediately searchable
client.remember(
    text="User prefers dark mode and Python 3.12",
    user_id="alice",
    category="preference",
    domain="settings",
    confidence=0.95,
)

# add() ingests a raw event — processed asynchronously via the memory pipeline
client.add(
    text="Alice asked about deployment options for Kubernetes",
    user_id="alice",
)

remember() vs add(): Use remember() when you want the fact stored immediately as a searchable belief. Use add() when you want the raw event to go through the full pipeline (event → episode → belief extraction via Cognitive Dreaming).

5Search memories

python
# Search memories — returns scored results
result = client.search(
    query="What does Alice prefer?",
    user_id="alice",
)

print(result)
# Returns: {
#   "results": [
#     {"content": "preference_dark_mode: prefers dark mode", "score": 0.78, "metadata": {...}},
#     {"content": "preference_kubernetes: prefers Kubernetes", "score": 0.71, "metadata": {...}},
#   ],
#   "total": 2
# }

6Inject context into your agent

python
# Example: Use with any LLM (OpenAI, Anthropic, etc.)
import openai

result = client.search("current task context", user_id="alice")

# Build memory context from search results
memory_lines = [r["content"] for r in result.get("results", [])]
memory_text = "\n".join(f"- {line}" for line in memory_lines)

response = openai.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": f"You are a helpful assistant.\n\nUser Memory:\n{memory_text}"},
        {"role": "user", "content": "What deployment option should I use?"},
    ],
)

# The agent now has Alice's preferences and past interactions as context

Bonus: CLI tool

The SDK includes a command-line tool for quick interactions.

bash
# Initialize (saves config to ~/.memgraph/config.json)
memgraph init --api-key mg_your_key --tenant-id your-tenant-uuid

# Store a memory
memgraph remember "User prefers dark mode" --user alice --category preference

# Search
memgraph recall "What does alice prefer?" --user alice

# Check connection
memgraph status

Next steps