v2 API — Cognitive Infrastructure
The v2 API adds cognitive primitives on top of v1's memory CRUD: entities, relationships, decisions, graph traversal, and context assembly. All endpoints use API key authentication.
Base URL: https://api.memgraph.ai/v2
Auth: X-API-Key: mg_your_key
Context Graph (Core)
The primary v2 endpoint. Performs 6-stage retrieval: semantic search, entity resolution, graph expansion, temporal filtering, confidence weighting, and context assembly.
/v2/contextAssemble full context for a query with memories, entities, decisions, and graph data.
curl -X POST https://api.memgraph.ai/v2/context \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"query": "What deployment strategy does Alice prefer?",
"user_id": "alice",
"agent_id": "support-bot",
"include_decisions": true,
"include_graph": true,
"create_snapshot": false,
"max_depth": 2
}'Response: memories[] (scored), entities[], relationships[], decisions[], snapshot, debug info
Entities
Named objects in the knowledge graph. Types: person, org, product, place, concept, system, project.
/v2/entitiesCreate a new entity with type, name, properties, and aliases.
curl -X POST https://api.memgraph.ai/v2/entities \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"entity_type": "person",
"name": "Alice Chen",
"properties": {"role": "engineer", "team": "infra"},
"aliases": ["alice", "achen"]
}'/v2/entities/{entity_id}Get entity by ID.
/v2/entitiesList entities. Filter by ?entity_type=person&limit=50.
/v2/entities/searchFuzzy + semantic entity search.
curl -X POST https://api.memgraph.ai/v2/entities/search \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{"query": "Alice", "max_results": 5}'/v2/entities/{entity_id}Delete entity and its relationships.
Relationships
Temporal edges between entities. Support valid_from/valid_to for time-scoped relationships.
/v2/relationshipsCreate a relationship between two entities.
curl -X POST https://api.memgraph.ai/v2/relationships \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"source_entity_id": "entity-uuid-1",
"target_entity_id": "entity-uuid-2",
"relation_type": "works_with",
"confidence": 0.95,
"valid_from": "2025-01-01",
"valid_to": null
}'/v2/relationshipsList relationships. Filter by ?entity_id=...&relation_type=...&limit=50.
/v2/relationships/{relationship_id}Delete a relationship.
Decisions
Agent reasoning traces with goals, steps, tools, beliefs, and outcomes. See the Decisions guide for detailed usage.
/v2/decisionsRecord a decision with reasoning trace.
curl -X POST https://api.memgraph.ai/v2/decisions \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "support-bot",
"user_id": "alice",
"goal": "Recommend deployment strategy",
"reasoning_steps": [
{"step": "Recall preferences", "thought": "Check user history"},
{"step": "Analyze options", "result": "K8s best fit"}
],
"tools_used": [
{"name": "memory_search", "input": "deployment", "output": "K8s preferred"}
],
"beliefs_used": ["belief-uuid-1"],
"confidence": 0.85,
"outcome": "SUCCESS"
}'/v2/decisions/synthesizeAuto-extract a decision from a message exchange.
/v2/decisions/{decision_id}Get decision by ID.
/v2/decisions/{decision_id}/explainFull explanation: beliefs, context snapshot, entity graph at decision time.
/v2/decisions/{decision_id}/outcomeUpdate outcome after the fact. Triggers belief confidence adjustment (LTP/LTD).
/v2/decisions/{decision_id}/outcome-impactSee which beliefs were strengthened/weakened by an outcome.
/v2/outcomes/recordPlatform-friendly outcome recording.
/v2/decisionsList decisions. Filter by ?agent_id, ?user_id, ?outcome, ?limit.
Graph Traversal
/v2/graph/traverseTraverse entity graph from seed entities.
curl -X POST https://api.memgraph.ai/v2/graph/traverse \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{
"entity_ids": ["entity-uuid-1"],
"max_depth": 2,
"temporal_filter": true
}'Contradictions
Memgraph automatically detects when new beliefs contradict existing ones.
/v2/contradictionsList contradictions. Filter by ?status=active&limit=50.
/v2/contradictions/{contradiction_id}Resolve or dismiss a contradiction.
curl -X PATCH https://api.memgraph.ai/v2/contradictions/uuid \
-H "X-API-Key: mg_your_key" \
-H "Content-Type: application/json" \
-d '{"resolution_status": "resolved", "resolved_by": "manual"}'Trust Score
/v2/trust-score/{agent_id}Agent accuracy and track record. Optional ?domain filter.
/v2/trust-score/{agent_id}/failure-analysisWhich beliefs correlate with agent failures.
Analytics
/v2/analyticsDecision success rate, outcome distribution, contradiction rate, avg confidence.
/v2/decisions/belief-usageBelief usage stats: total uses, success count, failure count per belief.
/v2/cache/statsContext cache hit/miss/error statistics.
Domains
/v2/domainsList supported professional domains.
/v2/domains/{domain_name}Get domain configuration: categories, trust threshold, etc.
Using v2 with the Python SDK
from memgraph_sdk import MemgraphClient
client = MemgraphClient(api_key="mg_your_key")
# Context graph (core v2 interface)
context = client.get_context_graph(
query="What does Alice prefer?",
user_id="alice",
include_decisions=True,
include_graph=True,
)
# Entities
entity = client.create_entity(
entity_type="person",
name="Alice Chen",
properties={"role": "engineer"},
aliases=["alice"],
)
results = client.search_entities("Alice", max_results=5)
# Relationships
rel = client.create_relationship(
source_entity_id=entity["id"],
target_entity_id="other-entity-id",
relation_type="works_with",
confidence=0.95,
)
# Decisions
decision = client.record_decision(
goal="Recommend deployment",
agent_id="bot",
user_id="alice",
confidence=0.85,
outcome="SUCCESS",
)
explanation = client.explain_decision(decision["id"])
# Graph traversal
graph = client.traverse_graph(
entity_ids=[entity["id"]],
max_depth=2,
)
# Contradictions
contradictions = client.list_contradictions(status="active")
client.resolve_contradiction(contradictions[0]["id"])Next steps
- v1 API Reference — Memory CRUD, events, beliefs, episodes
- Decisions Guide — Deep dive into the debug loop
- Python SDK — Full SDK method reference
