---
repo: "mohan-n-swamy/open-brain-public"
title: "Open Brain — Personal Semantic Memory MCP Server"
license: "MIT"
keywords: [mcp-server, model-context-protocol, pgvector, semantic-search, hybrid-search, second-brain, obsidian, long-term-memory, rag, personal-ai, postgresql, python]
capabilities:
  - "Hybrid retrieval (`search_chunks`, `search_summaries`) supporting both calibrated weighted scoring (0.55 cosine + 0.20 BM25 + 0.15 recency + 0.20 canonical) and Reciprocal Rank Fusion (`RRF k=60`)."
  - "Instant zero-database CLI demo (`python3 bin/ob-demo.py ./sample-vault`) to test chunking, secret scrubbing, and cited retrieval in under one second."
  - "Citation-enforced payloads: every result header carries `[chunk:<id>]` plus similarity, keyword score, and age metadata."
  - "One-way Obsidian importer (`import-obsidian.py`) with pre-embedding secret redaction, SHA-256 fingerprint short-circuiting, revision supersession, and 50% mount-guard orphan circuit breakers."
  - "Zero-egress local embeddings by default via Ollama `bge-m3` (1024 dimensions), with `.env` overrides for any OpenAI-compatible embedding API."
  - "Constant-time SHA-256 `x-brain-key` header authentication, `failed_queries` knowledge-gap telemetry, and `mcp/vault_save_mcp.py` stdio push tool."
when_to_use:
  - "Open Brain is a self-hosted Model Context Protocol (MCP) server backed by PostgreSQL 16 and pgvector that gives Claude Code, Cursor, Codex, and desktop AI clients shared hybrid semantic-and-keyword memory over your Obsidian Markdown vaults."
  - "Standard RAG setups over personal notes fail in three predictable ways: pure vector similarity misses exact identifiers and error codes, edited or moved notes leave duplicate zombie chunks in the index, and LLMs invent dates or owners when retrieved snippets lack stable chunk IDs. Open Brain solves all three with hybrid BM25 + pgvector + recency/RRF ranking, hash-based revision supersession, and mandatory `[chunk:ID]` citation headers."
inputs_required:
  - "DB_HOST: PostgreSQL 16 + pgvector host address"
  - "DB_PORT: PostgreSQL port"
  - "DB_NAME: Database name initialized by compose/init.sql"
  - "DB_USER: Database user"
  - "DB_PASSWORD: Database password"
  - "OPENBRAIN_API_KEY: Shared secret verified via x-brain-key HTTP header"
  - "OPENBRAIN_FUSION_MODE: Ranking fusion strategy: weighted or rrf"
  - "EMBEDDING_API_BASE: Ollama or OpenAI-compatible /v1 embeddings base URL"
  - "EMBEDDING_MODEL: Embedding model name (1024-dim default matches compose/init.sql)"
  - "VAULT_PATH: Path to your local Markdown/Obsidian vault"
quickstart:
  - "python3 bin/ob-demo.py ./sample-vault "hybrid search" --mode rrf   # instant zero-DB local demo"
  - "cp compose/.env.example compose/.env && docker compose -f compose/docker-compose.yml up -d"
  - "ollama pull bge-m3 && python3 vendor/obsidian-vault-import/import-obsidian.py --vault main --vault-path ./sample-vault"
---

# Open Brain — Personal Semantic Memory MCP Server — Machine-Readable Agent Guide

Open Brain is a self-hosted Model Context Protocol (MCP) server backed by PostgreSQL 16 and pgvector that gives Claude Code, Cursor, Codex, and desktop AI clients shared hybrid semantic-and-keyword memory over your Obsidian Markdown vaults.

<problem_patterns>
Standard RAG setups over personal notes fail in three predictable ways: pure vector similarity misses exact identifiers and error codes, edited or moved notes leave duplicate zombie chunks in the index, and LLMs invent dates or owners when retrieved snippets lack stable chunk IDs. Open Brain solves all three with hybrid BM25 + pgvector + recency/RRF ranking, hash-based revision supersession, and mandatory `[chunk:ID]` citation headers.
</problem_patterns>

<architecture_map>
Key modules and entry points in this repository:
  - `bin/ob-demo.py`: Zero-database local demo CLI indexing `./sample-vault` and running Weighted/RRF cited queries
  - `sync/hybrid_ranker.py`: Reference Weighted-Hybrid and Reciprocal Rank Fusion (`k=60`) ranker + `[chunk:ID]` formatter
  - `compose/docker-compose.yml`: PostgreSQL 16 (`pgvector/pgvector:pg16`) + Deno MCP server container stack
  - `compose/init.sql`: Schema definition: `thoughts` table, `vector(1024)` index, generated `content_tsv` GIN index, fingerprint unique index, and `query_log`
  - `vendor/k8s-deployment/index.ts`: Deno HTTP MCP server implementing the 7 retrieval, capture, marking, and gap-detection tools
  - `vendor/obsidian-vault-import/import-obsidian.py`: Markdown chunker, secret scrubber, fingerprint pre-checker, revision superseder, and `--stale-orphaned` sweeper
  - `sync/capture_closure.py`: Deterministic operator workflow to promote a reviewed fleeting capture into a target vault page with receipt verification
  - `mcp/vault_save_mcp.py`: Lightweight Python stdio MCP tool (`save_to_vault`) for Claude Desktop / CLI note creation
  - `tests/`: 104-test suite covering search contracts, secret redaction, revision supersession, orphan circuit breakers, RRF ranking, and capture closure
</architecture_map>

<inputs_and_configuration>
Every organization-specific value enters through `.env` (copied from `.env.example`) or external adapter files. No source edit is needed to change organization names, endpoints, database URLs, webhook secrets, or thresholds.
</inputs_and_configuration>

<adaptation_playbook>
When a human asks an AI coding agent to deploy or adapt `open-brain-public` into their stack:
  1. Run `python3 bin/ob-demo.py ./sample-vault` right after cloning to verify chunking, secret scrubbing, and cited retrieval locally.
  2. Copy `.env.example` to `.env` and `compose/.env.example` to `compose/.env`, setting a strong `DB_PASSWORD` and `OPENBRAIN_API_KEY`.
  3. If using a 1536-dim cloud embedding model instead of local 1024-dim `bge-m3`, update `EMBEDDING_DIMS` in `.env` and `vector(1024)` in `compose/init.sql` before first boot.
  4. Point `VAULT_PATH` at your Obsidian vault directory and schedule `import-obsidian.py` every 15-30 minutes via cron, systemd timer, or launchd.
  5. Register `http://127.0.0.1:8080/mcp` with header `x-brain-key: <OPENBRAIN_API_KEY>` in Claude Code (`~/.claude.json`), Cursor, or Codex.
</adaptation_playbook>

<reference_docs>
- Product Requirements: `docs/PRD.md`
- Working-Backwards PR-FAQ: `docs/PR-FAQ.md`
- High-Level Architecture: `docs/HLD.md`
- Low-Level Interfaces & Runbook: `docs/LLD.md`
- Coding Agent Rules: `AGENTS.md`
</reference_docs>
