AI agents often suffer from a form of digital amnesia, resetting to a blank slate every time a session concludes. Developers are frequently forced to rely on massive document dumps or imprecise vector similarity searches to help agents recall past decisions or context. To solve this, Y Combinator president Garry Tan has introduced GBrain, an open-source knowledge layer designed to function as a persistent, structured brain for AI agents like OpenClaw and Hermes.

GBrain v0.38.2.0 and the 140,000-Page Knowledge Layer

GBrain v0.38.2.0 is an MIT-licensed, markdown-first knowledge layer that uses Postgres as its backend to manage structured data. Currently, the instance powering Tan's own agents manages 146,646 pages, 24,585 people, and 5,339 companies. The system maintains this data using 66 autonomous cron jobs that run in the background to ensure the knowledge graph remains current.

What sets GBrain apart is its rejection of LLMs for the extraction process. Instead of relying on expensive, probabilistic model calls, it uses deterministic regex and type inference to map relationships. This approach is optimized for the Bun runtime and can be installed via:

bash
bun install -g @garrytan/gbrain

By running `gbrain init --pglite`, developers can provision a local database using PGLite—a version of Postgres 17 compiled to WebAssembly (WASM)—eliminating the need for complex Docker or server infrastructure. According to the BrainBench benchmark, enabling this knowledge graph layer improves P@5 (Precision at 5) accuracy by 31.4 percentage points, reaching 49.1% compared to a baseline without the graph.

Deterministic Extraction via Regex and PGLite

GBrain treats markdown files as the primary data unit, utilizing wikilinks to define connections. To ensure the graph extractor functions correctly, links must include full paths, such as `[[people/alice-chen]]`, rather than shorthand aliases. The extraction engine follows a strict cascade of priorities: FOUNDED, INVESTED, ADVISES, WORKS_AT, and MENTIONS.

Because this process relies on hard-coded rules rather than LLM inference, it is entirely deterministic and incurs zero API costs. When an agent needs to determine where someone works, it does not calculate a fuzzy similarity score; it performs a typed-edge traversal across the graph. This structural shift moves the paradigm of agent design away from simply using larger models toward building more sophisticated, reliable external memory systems.

Vector Search vs. Structural Search

While GBrain utilizes a hybrid pipeline, the performance gap is driven by the integration of structural search. The system combines `pgvector` HNSW (Hierarchical Navigable Small World) for vector search with BM25 for keyword matching. These results are unified using Reciprocal Rank Fusion (RRF) with the following formula:

score = sum(1 / (60 + rank))

This RRF approach prevents any single algorithm from skewing the results, ensuring that semantic exploration and keyword precision complement one another. In the BrainBench tests, which utilized a 240-page corpus, this hybrid approach achieved an R@5 (Recall at 5) of 97.9%. Users can adjust the balance between cost and quality via three modes: `conservative`, `balanced`, and `tokenmax`, with the `balanced` mode employing a ZeroEntropy reranker to further refine output precision.

Expanding Agent Agency with 74 MCP Tools

Beyond simple retrieval, GBrain enables agents to act on their knowledge through the Model Context Protocol (MCP). By exposing 74 standardized tools, the system grants agents write access to the knowledge store, allowing them to create files, manage tags, and update links autonomously. Integration into IDEs like Cursor or Windsurf is streamlined via the command line:

bash
gbrain mcp add claude-code

These tools, including `get_page`, `put_page`, and `add_link`, allow for direct interaction with the underlying markdown files. By moving from read-only retrieval to active, protocol-based manipulation, GBrain provides a blueprint for agents that can maintain and evolve their own knowledge bases over time.

As these systems move from experimental setups to production environments, the ability to debug and trace the reasoning path through a deterministic graph will likely become a requirement for reliable AI operations.