A Real Graph Database for GBrain

Replace recursive CTEs with native Neo4j graph traversal. Same GBrain API โ€” pages, links, traversal, search โ€” backed by index-free adjacency.

โ— Live at graphbrain.belweave.ai v0.2.0 MIT

๐Ÿ–ฅ๏ธ Try the Web Dashboard โ†’ โ€” provision brains, browse pages, explore graphs.

What is GraphBrain?

GBrain stores its knowledge graph in Postgres โ€” links are rows in a links table, traversal uses recursive CTEs. GraphBrain swaps the storage layer for Neo4j while keeping the exact same API. Every GBrain operation works unchanged, but now:

โšก Index-Free Traversal

O(1) per hop. BFS to depth 10 completes in single-digit milliseconds.

๐Ÿ—„๏ธ Database-Level Isolation

Each brain is a separate Neo4j database. No shared namespace, no query filtering, no cross-brain leakage.

๐Ÿ”— Native Relationships

Links are real Neo4j relationships. Typed, directed, with context โ€” exactly how you think about them.

๐Ÿš€ Sub-Second Batch Links

Cypher UNWIND creates hundreds of links in one query. No more sequential INSERTs.

๐Ÿ”‘ Per-Brain API Keys

Every brain gets its own sk_* key. Cross-brain access returns 401.

๐ŸŒ Custom Domains

Deploy on your own hardware with Cloudflare Tunnel. Auto-SSL, zero port forwarding.

Connect GBrain to GraphBrain

Already have GBrain? Point it at GraphBrain's REST API in 2 steps.

1 Provision a brain

curl -X POST https://graphbrain.belweave.ai/v1/brains \
  -H "Content-Type: application/json" \
  -d '{"name":"my-brain"}'

You'll get back a brain_id and api_key. Save both.

2 Wire it into GBrain

# Set your API key as an env var
export GBRAIN_GRAPH_API_KEY=sk_your_key_here

# Point GBrain at your GraphBrain instance
gbrain init --engine graphbrain \
  --url https://graphbrain.belweave.ai/v1/brain_YOUR_BRAIN_ID

That's it. GBrain's CLI, MCP server, and all existing scripts now use Neo4j for graph operations.

For AI Agents

If you're an AI agent (Claude, Codex, Cursor, etc.) setting up GraphBrain for your user, copy-paste this:

Setup from scratch (no GBrain yet)

# 1. Install GBrain if not present
git clone https://github.com/garrytan/gbrain ~/gbrain && cd ~/gbrain && bun install

# 2. Create a GraphBrain brain
RESP=$(curl -s -X POST https://graphbrain.belweave.ai/v1/brains \
  -H "Content-Type: application/json" \
  -d '{"name":"my-knowledge-graph"}')
BID=$(echo "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['brain_id'])")
KEY=$(echo "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['api_key'])")

# 3. Initialize GBrain pointing at GraphBrain
cd ~/gbrain
GBRAIN_GRAPH_API_KEY=$KEY gbrain init --engine graphbrain \
  --url "https://graphbrain.belweave.ai/v1/$BID"

# 4. Start using it
echo "Brain ID: $BID"
echo "API Key: $KEY"

Connect existing GBrain

# Already have GBrain set up with Postgres? Just point it at GraphBrain:
export GBRAIN_GRAPH_API_KEY=sk_your_key_here
gbrain init --engine graphbrain \
  --url https://graphbrain.belweave.ai/v1/brain_YOUR_BRAIN_ID

# Your existing scripts, MCP server, and cron jobs work unchanged.
# Graph operations (links, traversal) now use Neo4j.

Run a smoke test

# Verify everything works
BASE="https://graphbrain.belweave.ai"
KEY="sk_your_key"
BID="brain_your_id"

# Health check
curl -s "$BASE/health"

# Create pages
curl -s -X PUT "$BASE/v1/$BID/pages/alice" \
  -H "Content-Type: application/json" -H "X-API-Key: $KEY" \
  -d '{"title":"Alice Chen","type":"person","content":"Engineer"}'

# Create links
curl -s -X POST "$BASE/v1/$BID/links" \
  -H "Content-Type: application/json" -H "X-API-Key: $KEY" \
  -d '{"from_slug":"alice","to_slug":"bob","link_type":"knows"}'

# Traverse
curl -s -X POST "$BASE/v1/$BID/traverse" \
  -H "Content-Type: application/json" -H "X-API-Key: $KEY" \
  -d '{"start_slug":"alice","depth":2}'

# Search
curl -s "$BASE/v1/$BID/search?q=engineer" -H "X-API-Key: $KEY"

API Reference

All brain endpoints require X-API-Key: sk_... header. Cross-brain access returns 401.

MethodPathDescription
POST/v1/brainsCreate a new brain (returns ID + key)
GET/v1/brainsList all brains
PUT/v1/:id/pages/:slugCreate or update a page
GET/v1/:id/pages/:slugGet a page
GET/v1/:id/pagesList pages (?type=person&limit=50)
POST/v1/:id/linksCreate a typed edge
POST/v1/:id/links/batchBatch create edges (UNWIND)
GET/v1/:id/links/:slugOutgoing edges from a page
GET/v1/:id/backlinks/:slugIncoming edges to a page
POST/v1/:id/traverseBFS traversal (depth, direction, type filter)
GET/v1/:id/graphFull graph for visualization
GET/v1/:id/search?q=Full-text search across pages
GET/v1/:id/statsBrain statistics
POST/v1/:id/timelineAdd timeline entry

Full API docs with request/response examples โ†’

Roadmap

VersionItemStatus
v0.1Core engine โ€” pages, links, traversal, search, stats, timelineโœ“ Done
v0.1GBrain adapter โ€” PR #594 accepted, 25/25 tests passโœ“ Done
v0.1One-click server setup scriptโœ“ Done
v0.1Per-brain API keys with cross-brain auth enforcementโœ“ Done
v0.1BrainBench: 258/261 (+10 over stock GBrain)โœ“ Done
v0.2Persistent API key storage (SQLite, survives restarts)โœ“ Done
v0.2Rate limiting โ€” per-brain 100/min + per-IP 10/minโœ“ Done
v0.2Real /health endpoint โ€” Neo4j + keystore checks, 503 on failuresโœ“ Done
v0.2Smoke tests โ€” full pipeline (provision โ†’ CRUD โ†’ traverse โ†’ delete)โœ“ Done
v0.2GBrain CLI plugin โ€” gbrain init --engine graphbrainโœ“ Done
v0.3Web dashboard โ€” browser-based brain management (Vercel)โ—Œ Planned
v0.3Interactive graph visualization (D3/Three.js)โ—Œ Planned
v0.3Migration tooling (Postgres GBrain โ†’ Neo4j)โ—Œ Planned
v0.4Horizontal scaling โ€” multiple API instances + load balancerโ—Œ Planned
v0.4Neo4j read replicasโ—Œ Planned

Deploy Your Own

One-Click Server Setup

curl -fsSL https://raw.githubusercontent.com/pkyanam/graphbrain/main/scripts/setup-server.sh | bash

Works on any Ubuntu/Debian server with Docker. Installs Bun, Docker, Neo4j, GraphBrain, and creates a Cloudflare Tunnel in ~5 minutes.

Docker Compose (Local)

git clone https://github.com/pkyanam/graphbrain
cd graphbrain
docker compose up -d
# GraphBrain: http://localhost:3000
# Neo4j Browser: http://localhost:7474 (neo4j / graphbrain-dev)

Full deployment guide (Railway, AuraDB, custom domains) โ†’