Skip to main content

ZeroMemory + Context Graph

ZeroMemory gives your AI agents persistent cognitive memory. The Context Graph adds a knowledge graph layer on top for multi-hop reasoning and contextual retrieval.

Quick Start

1. Provision a database

curl -X POST https://api.ainative.studio/api/v1/public/instant-db
# Returns: api_key, project_id, mcp block, database connection

2. Store memories

import requests

BASE = "https://api.ainative.studio/api/v1/public/memory/v2"
HEADERS = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}

# Store a memory
requests.post(f"{BASE}/remember", headers=HEADERS, json={
"content": "Alice is the CTO of AINative Studio. She prefers Python.",
"session_id": "onboarding-session",
"tags": ["person", "preference"]
})

3. Build the knowledge graph

Entities and edges are auto-extracted from memories, or you can create them explicitly:

GRAPH = f"{BASE}/graph"

# Create entities
requests.post(f"{GRAPH}/entity", headers=HEADERS, json={
"canonical_name": "Alice Johnson",
"entity_type": "person",
"aliases": ["alice", "AJ"],
"properties": {"title": "CTO"}
})

requests.post(f"{GRAPH}/entity", headers=HEADERS, json={
"canonical_name": "AINative Studio",
"entity_type": "org"
})

# Create a relationship
requests.post(f"{GRAPH}/edge", headers=HEADERS, json={
"source_name": "Alice Johnson",
"target_name": "AINative Studio",
"predicate": "works_at",
"confidence": 0.95
})

4. Traverse the graph

result = requests.post(f"{GRAPH}/traverse", headers=HEADERS, json={
"entity": "Alice Johnson",
"max_hops": 3
}).json()

# Returns nodes, edges, and paths reachable from Alice
print(f"Found {len(result['nodes'])} connected entities")
results = requests.post(f"{GRAPH}/graphrag", headers=HEADERS, json={
"query": "Who leads the engineering team?",
"limit": 5,
"graph_weight": 0.3 # 70% vector similarity + 30% graph proximity
}).json()

for r in results["results"]:
print(f"Score: {r['score']:.2f} | Vector: {r['vector_score']:.2f} | Graph: {r['graph_boost']:.2f}")
print(f" {r['content'][:100]}...")

Memory Hierarchy

ZeroMemory organizes information in three tiers:

TierPurposeRetention
WorkingCurrent conversation contextSession-scoped, decays fast
EpisodicSpecific interactions and eventsDays to weeks
SemanticConsolidated knowledge and patternsLong-term, low decay

Memories promote upward via the reflect() engine, which clusters related memories and synthesizes insights.


Ontology Setup

Define what types of entities and relationships exist in your domain:

Manual definition

requests.post(f"{GRAPH}/ontology", headers=HEADERS, json={
"project_id": PROJECT_ID,
"entity_types": ["customer", "order", "product"],
"predicates": {
"customer": {"places": "order", "prefers": "product"},
"order": {"contains": "product"}
}
})

Auto-infer from usage

After storing enough data, let ZeroDB detect patterns:

proposed = requests.post(f"{GRAPH}/ontology/infer", headers=HEADERS,
params={"min_entity_count": 5, "min_predicate_count": 3}
).json()

# Review the proposed ontology, then apply it
requests.post(f"{GRAPH}/ontology/apply", headers=HEADERS, json=proposed["proposed_ontology"])

Templates

Skip manual setup with pre-built ontologies:

# List available templates
templates = requests.get(f"{GRAPH}/templates", headers=HEADERS).json()

# Apply one
requests.post(f"{GRAPH}/templates/customer-support/apply", headers=HEADERS,
params={"project_id": PROJECT_ID})

Available templates: customer-support, research, code-review, sales, knowledge-base


Edge Versioning

When relationships change (Alice leaves Company X, joins Company Y), ZeroDB tracks the history:

# This auto-supersedes the old "works_at" edge
requests.post(f"{GRAPH}/edge", headers=HEADERS, json={
"source_name": "Alice Johnson",
"target_name": "New Company",
"predicate": "works_at"
})

# View contradictions
contradictions = requests.get(f"{GRAPH}/contradictions", headers=HEADERS).json()

# Resolve
requests.post(f"{GRAPH}/contradictions/{edge_id}/resolve", headers=HEADERS,
json={"action": "accept_new"}) # or "keep_both" or "reject_new"

MCP Integration

Use the Context Graph via MCP tools in any AI IDE:

# Install the memory MCP (10 tools including graph)
npx ainative-zerodb-memory-mcp

# Or the full server (83 tools)
npx ainative-zerodb-mcp-server

The MCP server exposes zerodb_graph_traverse, zerodb_graphrag_search, zerodb_entity_neighbors, zerodb_entity_list, zerodb_entity_merge, and zerodb_graph_stats tools.