Open Brain is a personal long-term memory layer for AI agents and assistants.
It provides:
- a versioned REST API (
/v1) - a local MCP-style bridge (
stdio) for tool-driven workflows - semantic memory retrieval on Supabase Postgres + pgvector
Implemented:
- Memory CRUD (
create/list/get/update/delete) - Hybrid write flow:
POST /v1/memories/suggest(suggest candidate memories)POST /v1/memories/remember(explicit persist)
- Semantic retrieval:
POST /v1/search- cosine similarity + recency boost + optional filters + score threshold
- light entity boost via memory-entity links
- NDJSON portability:
POST /v1/memories/exportPOST /v1/memories/import(skip_existing/upsert)
- Health endpoints:
GET /health(legacy)GET /v1/healthGET /v1/health/db
- Request IDs + structured error responses
- Alembic migrations (replacing ad-hoc schema bootstrap)
- Embedding provider abstraction:
- OpenAI embeddings
- deterministic local fallback
- Python 3.11+
- FastAPI + Uvicorn
- SQLAlchemy + Alembic
- Supabase Postgres + pgvector
- pytest
python3 -m venv venvvenv/bin/python -m pip install --upgrade pip
venv/bin/python -m pip install -e ".[dev]"cp .env.example .envFill these variables:
SUPABASE_URLSUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEYSUPABASE_DB_URLOPEN_BRAIN_API_TOKENEMBEDDING_PROVIDER(local,openai, orauto)OPENAI_API_KEY(required ifopenaiorautowith OpenAI enabled)OPENAI_EMBED_MODEL(defaulttext-embedding-3-small)
Important for Supabase:
- Use Session Pooler URI when on IPv4-only networks.
SUPABASE_DB_URLshould usepostgresql+psycopg://....- URL-encode DB passwords with special chars (
#,@,!,%).
venv/bin/python scripts/init_db.pyThis runs Alembic upgrade head.
venv/bin/python -m uvicorn app.main:app --reloadvenv/bin/python -m pytest -qmake venv: create virtual environmentmake install: install runtime + dev dependenciesmake init-db: run Alembic migrations to latest versionmake migrate: alias foralembic upgrade headmake run: run FastAPI dev servermake test: run pytestmake mcp-bridge: run local stdio bridge forremember/recall
All protected endpoints require:
Authorization: Bearer <OPEN_BRAIN_API_TOKEN>Create memory:
curl -X POST http://127.0.0.1:8000/v1/memories \
-H "Authorization: Bearer <OPEN_BRAIN_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"content":"I prefer concise explanations","memory_type":"preference","source":"manual","tags":["style"],"confidence":0.9}'Suggest memory (non-persistent):
curl -X POST http://127.0.0.1:8000/v1/memories/suggest \
-H "Authorization: Bearer <OPEN_BRAIN_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"text":"I prefer practical, concise answers"}'Semantic search:
curl -X POST http://127.0.0.1:8000/v1/search \
-H "Authorization: Bearer <OPEN_BRAIN_API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"query":"What are my response preferences?","top_k":5,"recency_weight":0.2,"score_threshold":0.15}'Run:
make mcp-bridgeInput (stdin JSON line):
{"action":"remember","payload":{"content":"I am building Open Brain","memory_type":"project"}}{"action":"recall","payload":{"query":"What project am I building?","top_k":3}}This is a local bridge layer that keeps tool contracts stable while a stricter full MCP protocol adapter is expanded.