The Problem

Retrieval systems built on vector similarity return plausible-sounding answers with no way to verify the reasoning. When a user asks a multi-step question like "Who organized AI events in London in Q1 2024?", a nearest-neighbor match on embeddings gives a guess, not a traceable path. Teams need answers grounded in explicit relationships between entities—who did what, to whom, when—rather than statistical proximity.

What This Does

BrainAPI is a knowledge-graph memory layer that converts unstructured text into an event-centric graph. A swarm of agents (src/core/agents/) reads documents, extracts facts, and writes nodes and relationships into a graph store. Queries return answers plus the result.triples path used to derive them.

The repo is a portfolio of five projects: the core Python service (src/), a TypeScript web console (console/), a TUI installer (tui/), a Rust MCP transport bridge (mcp-stdio-http-bridge/), and deployment scripts. The core service supports Neo4j (src/lib/neo4j/client.py) and PostgreSQL/NetworkX (src/lib/postgresql/), with embedding adapters (src/adapters/embeddings.py) and a caching layer (src/adapters/cache.py).

How It Is Wired

Execution enters through the MCP server (src/services/mcp/main.py). _search_memory_sync (line 263) reaches 55 functions; _search_semantically_sync (line 285) reaches 63; _traverse_graph_sync (line 199) reaches 62. These route through guard_brainpat -> get_brains_list, hitting the database via collection.find in two hops. The API lifespan (src/services/api/app.py:40) reaches 29 functions and publishes errors over the network via client.post.

The highest-blast-radius functions are set (called from 41 places), ensure_database (32), Node (28), and get_brain (25). src/config.py is a hub with 36 modules depending on it; src/adapters/graph.py has 25 dependents and 724 lines. Three modules (src/core/agents/architect_agent.py, src/workers/tasks/ingestion.py, src/core/agents/janitor_agent.py) participate in circular imports, which makes refactoring them risky.

How To Use It

The README documents the TUI workflow:

npm install -g brainapi-tui
brainapi init     # clone, install deps, interactive setup
brainapi start    # backing services + API + MCP + worker + console

Configuration lives in .env.example (copy to .env). The API runs on port 8000, MCP on 8001. A Dockerfile and example-docker-compose.yaml exist for containerized deployment. The Makefile and pyproject.toml imply make and poetry/uv workflows, but the README's TUI path is the documented route.

Real-World Use

Feed the system a sentence: "Emily organized the AI Ethics Meetup in London on March 8, 2024." Later, query: client.retrieveContext("Who organized AI events in London in Q1 2024?"). The response includes the answer and a triples list showing the graph path—Emily → organized → Meetup → located_in → London. That trace is auditable and explainable, which matters for compliance-heavy domains.

Code Health & Issues

Static analysis found 122 findings (30 high, 89 medium, 3 low). Key items:

  • High – Deep nesting (25 cases): src/adapters/graph.py reaches indentation depth 7; control flow is hard to follow.
  • High – Oversized files: src/adapters/graph.py (724 lines), src/core/agents/architect_agent.py—changes ripple widely.
  • High – Hub modules: 36 files depend on src/config.py; churn here is high-blast-radius.
  • High – Import cycles: architect_agent.py, ingestion.py, janitor_agent.py are mutually reachable.
  • Medium – Broad exception handling (16 cases) in src/utils/cleanup.py and others.
  • High – CI never runs the 14 test files; a green check means nothing.
  • High – Unpinned GitHub Actions (@v3 tags) and wildcard CORS (allow_origins=["*"]) in src/services/api/app.py.
  • Hightokio@1 carries CVE-2021-45710; 12 dependencies are multiple majors behind.

The Bottom Line

BrainAPI is a serious attempt at explainable retrieval, with a well-structured core and a real graph-based answer path. The architecture is sound but carries technical debt—deep nesting, hub modules, and circular imports will make changes painful. Use it if you need auditable, relationship-grounded answers and can invest in the CI and dependency hygiene it currently lacks.