The usual way to give an AI agent memory is to drop in a vector database. Then relational questions keep losing to similarity scores and recalling an abstraction stays unreliable. gbrain is Garry Tan's long term memory and hybrid retrieval engine for agents. It fuses vector, keyword, title, and relation results before reranking them. More unusually, it ships a reproducible offline evaluation ledger, so accuracy is a measured number rather than a claim. MIT licensed, it stays neutral across Claude, Codex, OpenClaw, and Hermes.

What Is gbrain

gbrain stands for Garry's Opinionated OpenClaw/Hermes Agent Brain. Under the name it is a long term memory and hybrid retrieval engine for agents. The repository was created on 2026-04-05, still had commits on 2026-11-10, and has roughly 32,247 stars and 4,774 forks under MIT. The problems it targets are specific. Relational queries get suppressed by a reranker, conceptual recall has gaps, company knowledge bases need a safe path in, skill routing and parsing must stay consistent across harnesses, and structured data such as a database schema belongs in code intelligence. The author also insists on evaluation driven work. A public offline ledger makes retrieval and answer accuracy reproducible and auditable instead of a polished marketing figure. The result is a backend rather than a plugin you drop into a chat window, and that distinction shapes the setup below.

Features

  • Four arm hybrid search. Vector, keyword, title, and relation arms fetch results in parallel before fusion.
  • RRF and reranking. Reciprocal Rank Fusion combines the arms, then a cross encoder scores the merged set.
  • Relational query protection. relational_rerank_pin keeps relation hits, metadata_boost_gate stops hub pages dominating, and autocut truncates.
  • Layered storage. Postgres with a postgres.js TLS pool, embedded PGLite for tests, and bun:sqlite in WAL mode as a content addressed embedding cache.
  • Evaluation ledger. LongMemEval measures recall_all@5 and answer accuracy, with 449 out of 470 or 95.53 percent recall and 86.6 percent answer accuracy published.
  • Multi harness plugins. .claude-plugin, .codex-plugin, and an OpenClaw loader share the same skill routing.
  • Engineering discipline. TLA+ specs in spec/tla, gitleaks secret scanning, an Admin SPA, and 1536 dimension vector columns.
  • Reproducible baselines. Every published number comes with the evaluation command that produced it.

For a lighter cross session memory, see What Is claude-mem and How to Use It. For context capacity, there is What Is billion-context and How to Use It.

How to Use

  1. Install Bun 1.4.4 or newer, clone the repository, and install dependencies per the README.
  2. Start a Postgres instance and set the connection string, or use PGLite locally to skip an external service.
  3. Initialize tables and 1536 dimension vector columns, then import your documents or code index.
  4. Configure an embedding model and a cross encoder reranker, leaving default weights in place.
  5. Install the plugin for your harness, .claude-plugin for Claude, .codex-plugin for Codex, or the OpenClaw loader.
  6. Run LongMemEval and record recall_all@5 and answer accuracy as your baseline.
  7. Tune relational_rerank_pin, metadata_boost_gate, and autocut for your corpus, rerunning the evaluation after each change.

Get the flow working on PGLite before moving to Postgres, so connection pools and TLS do not block the first run.

Supported Platforms

ItemDetail
LanguageTypeScript
RuntimeBun 1.4.4 or newer
StoragePostgres, PGLite, bun:sqlite
Vector dimensions1536
EvaluationLongMemEval, recall_all@5
LicenseMIT

Plugins cover Claude, Codex, and OpenClaw, with Hermes in scope as well. Bun handles the runtime and Postgres the persistence, while PGLite and bun:sqlite are enough for a local trial without standing up a database service. The Admin SPA also runs locally, so no external dashboard account is involved. Bun versions older than 1.4.4 are not supported.

Pricing

It is MIT licensed. Personal use, modification, and commercial use are free, and there is no hosted tier or paid quota. Real costs sit in infrastructure, namely a Postgres instance, embedding calls, and reranker inference, and a local small model removes much of that. There is no cloud service, so data stays in your own database, which is a prerequisite for teams connecting an internal knowledge base. Evaluation scripts are open too, so no separate tooling is needed.

Use Cases

  • Agent long term memory. Store facts and preferences across sessions and make them retrievable.
  • Enterprise knowledge bases. Attach existing documents inside a permission boundary while preserving relational queries.
  • Code intelligence. Bring database schemas and structured data into retrieval where a pure vector setup falls short.
  • Mixed harness teams. Keep skill routing and parsing consistent when Claude, Codex, and OpenClaw are all in use.
  • Retrieval evaluation. Use the LongMemEval ledger for an A/B comparison instead of tuning by intuition.
  • Security sensitive work. TLA+ specs, gitleaks scanning, and local deployment help with review.
  • Debugging recall. Compare which arm found a document another approach missed.

It assumes you already have a retrieval question and an evaluation set. For someone who only wants a quick memory layer, the setup will feel heavy.

How It Works

Y Combinator president Garry Tan leads the project, which brings attention, but developers tend to value the public evaluation and the honest disclosure of what did not meet expectations. Delivery is fast, with roughly 13,935 commits and plenty of bot assisted merges, alongside near obsessive discipline about security isolation and flaky tests. Staying neutral across harnesses lets it serve as a general memory backend rather than an accessory to one product. MIT licensing and complete plugin specs make it straightforward for the community to add another agent framework. That insistence on measurable evaluation is what separates it from the most similar projects. That is unusual for a project with this much daily commit traffic.

Conclusion

If your agent memory has reached the point where recall and reranking strategy matter, gbrain offers not just a library but a reproducible way to measure it. Run an evaluation baseline on a small dataset before committing to Postgres and the full plugin set. The published accuracy is high, and the author also writes plainly about the parts that fell short. Read that section before looking at the star count. A small corpus also makes regressions obvious.

Project https://github.com/garrytan/gbrain