{"id":962,"date":"2026-05-23T02:23:40","date_gmt":"2026-05-22T18:23:40","guid":{"rendered":"https:\/\/connectword.dpdns.org\/?p=962"},"modified":"2026-05-23T02:23:40","modified_gmt":"2026-05-22T18:23:40","slug":"a-step-by-step-coding-tutorial-to-implement-gbrain-the-self-wiring-memory-layer-built-by-y-combinators-garry-tan-for-ai-agents","status":"publish","type":"post","link":"https:\/\/connectword.dpdns.org\/?p=962","title":{"rendered":"A Step-by-Step Coding Tutorial to Implement GBrain: The Self-Wiring Memory Layer Built by Y Combinator\u2019s Garry Tan for AI Agents"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Your AI agent is smart but forgetful. Every new session starts from zero \u2014 no memory of who you met, what you read, what you decided last Tuesday. <strong><a href=\"https:\/\/github.com\/garrytan\/gbrain\" target=\"_blank\" rel=\"noreferrer noopener\">GBrain<\/a><\/strong> is an open-source fix for that. Built by Garry Tan (President and CEO of Y Combinator) to power his own OpenClaw and Hermes deployments, it\u2019s a markdown-first, Postgres-backed knowledge layer that ingests meetings, emails, tweets, and notes, then auto-wires a typed knowledge graph on top \u2014 with zero LLM calls for the graph extraction. The production brain behind Garry\u2019s actual agents currently holds <strong>146,646 pages, 24,585 people, 5,339 companies, and 66 autonomous cron jobs<\/strong>. On its own benchmark (BrainBench, a 240-page rich-prose corpus), GBrain hits <strong>P@5 49.1% and R@5 97.9%<\/strong>, a +31.4-point P@5 lead over the same codebase with the graph layer disabled.<\/p>\n<p class=\"wp-block-paragraph\">This is a hands-on tutorial. You\u2019ll install GBrain locally, import a small notes folder, run a real search, watch the knowledge graph wire itself, and connect it to Claude Code via MCP. About 20 minutes start to finish. All terminal outputs below were captured from a live install of <strong>GBrain v0.38.2.0<\/strong>. The repository (MIT-licensed) lives at <a href=\"https:\/\/github.com\/garrytan\/gbrain\">github.com\/garrytan\/gbrain<\/a>.<\/p>\n<h2 class=\"wp-block-heading\"><strong>What you\u2019re building<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">By the end of the tutorial, you\u2019ll have:<\/p>\n<ul class=\"wp-block-list\">\n<li>A local <code>~\/.gbrain\/brain.pglite<\/code> database \u2014 embedded <strong>Postgres 17 (via WASM)<\/strong> with pgvector, zero server config.<\/li>\n<li>A small \u201cbrain repo\u201d of markdown notes about people, companies, and concepts.<\/li>\n<li>A working hybrid-search CLI that combines vector + BM25 keyword + Reciprocal Rank Fusion (RRF), with a ZeroEntropy reranker on top by default.<\/li>\n<li>A typed knowledge graph (<code>works_at<\/code>, <code>founded<\/code>, <code>invested_in<\/code>, <code>attended<\/code>, <code>advises<\/code>, <code>mentions<\/code>) auto-extracted from your notes.<\/li>\n<li>An MCP server exposing <strong>74 tools<\/strong> so Claude Code, Cursor, and Windsurf can read and write to the brain directly.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\"><strong>Prerequisites<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li>macOS or Linux (Windows users: use WSL2).<\/li>\n<li>A code editor.<\/li>\n<li>Bun \u2265 1.3.10 (the runtime GBrain ships on; the repo\u2019s <code>package.json<\/code> declares this as the minimum engine). We\u2019ll install it in Step 1.<\/li>\n<li>An embedding API key from <strong>one<\/strong> of: ZeroEntropy (default), OpenAI, or Voyage. Without one, you can still install and run keyword search, but <code>gbrain query<\/code> (hybrid + vector) will return no results.<\/li>\n<li>Optional: an Anthropic API key for multi-query expansion during search.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\"><strong>Step 1 \u2014 Install Bun and GBrain<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">GBrain is written in TypeScript and runs on Bun. Install it first:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">curl -fsSL https:\/\/bun.sh\/install | bash\nexec $SHELL                 # reload shell so `bun` is on PATH\nbun --version<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Now install GBrain. As of v0.38, the canonical install path is a single global Bun install:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">bun install -g github:garrytan\/gbrain\ngbrain --version\n# gbrain 0.38.2.0<\/code><\/pre>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>Step 2 \u2014 Initialize your brain<\/strong><\/h2>\n<p class=\"wp-block-paragraph\"><code>gbrain init --pglite<\/code> provisions a local PGLite database in <code>~\/.gbrain\/<\/code>. PGLite is full Postgres compiled to WASM \u2014 no server, no Docker, ready in roughly two seconds.<\/p>\n<p class=\"wp-block-paragraph\">For this tutorial we\u2019ll defer the embedding provider so you can follow along without an API key right away \u2014 we\u2019ll wire it up in Step 6 when we run hybrid search:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain init --pglite --no-embedding<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">(If you\u2019d rather configure embeddings now, set one of <code>OPENAI_API_KEY<\/code>, <code>ZEROENTROPY_API_KEY<\/code>, or <code>VOYAGE_API_KEY<\/code> in your environment before running plain <code>gbrain init --pglite<\/code>.)<\/p>\n<p class=\"wp-block-paragraph\">Real output captured from a fresh install (truncated for brevity \u2014 there are 81 migrations from schema v1 \u2192 v85):<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">Setting up local brain with PGLite (no server needed)...\n  Schema version 1 \u2192 85 (81 migration(s) pending)\n  [2] slugify_existing_pages...\n  [2] \u2713 slugify_existing_pages\n  [3] unique_chunk_index...\n  [3] \u2713 unique_chunk_index\n  ...\n  Brain ready at \/home\/you\/.gbrain\/brain.pglite\n  0 pages. Engine: PGLite (local Postgres).<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">You now have an empty brain. Confirm:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain stats\n# Pages:     0\n# Chunks:    0\n# Embedded:  0\n# Links:     0\n# Tags:      0\n# Timeline:  0<\/code><\/pre>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>Step 3 \u2014 Create a tiny brain repo<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">The brain repo is just a directory of markdown files. Each file follows GBrain\u2019s <strong>compiled truth + timeline<\/strong> pattern: a current best-understanding section on top, an append-only evidence trail below.<\/p>\n<p class=\"wp-block-paragraph\"><strong>Important:<\/strong> wikilinks must use the full slug path (e.g., <code>[[people\/alice-chen]]<\/code>, not just <code>[[alice-chen]]<\/code>) for the graph extractor to resolve them. This is a real gotcha \u2014 I tested both forms; the short form silently produces zero links.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">mkdir -p ~\/my-brain\/people ~\/my-brain\/companies ~\/my-brain\/concepts\ncd ~\/my-brain<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Create a person page:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">cat &gt; people\/alice-chen.md &lt;&lt;'EOF'\n---\ntype: person\ntitle: Alice Chen\ntags: [founder, ai-infra]\n---\n\nFounder and CEO of [[companies\/acme-ai]]. Previously staff engineer at\nGoogle Brain. Focus area: inference optimization for small language models.\n\n---\n\n- 2024-03-12: Met at AI Engineer Summit. Discussed sparse MoE routing.\n- 2024-09-04: Announced $12M seed led by Sequoia.\n- 2025-01-18: Shipped open-source inference router on GitHub.\nEOF<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">A company page:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">cat &gt; companies\/acme-ai.md &lt;&lt;'EOF'\n---\ntype: company\ntitle: Acme AI\ntags: [startup, inference]\n---\n\nYC W24 inference-optimization startup. Founded by [[people\/alice-chen]].\nBuilding latency-aware routing for sub-7B models.\n\n---\n\n- 2024-09-04: $12M seed, led by Sequoia.\n- 2025-01-18: Open-sourced their inference router.\nEOF<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">And a concept page:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">cat &gt; concepts\/inference-optimization.md &lt;&lt;'EOF'\n---\ntype: concept\ntitle: Inference Optimization\ntags: [ml-systems]\n---\n\nTechniques to reduce latency and cost when serving language models:\nquantization, speculative decoding, KV-cache reuse, and request batching.\nEOF<\/code><\/pre>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>Step 4 \u2014 Import the repo<\/strong><\/h2>\n<p class=\"wp-block-paragraph\"><code>gbrain import<\/code> is idempotent (content-hash deduplicated). We\u2019ll pass <code>--no-embed<\/code> so this step is deterministic for readers who don\u2019t have an embedding key set yet \u2014 embeddings get backfilled in Step 6. Real output:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain import ~\/my-brain\/ --no-embed<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">[gbrain phase] import.collect_files start dir=\/home\/you\/my-brain\/ strategy=markdown\n[gbrain phase] import.collect_files done 2ms files=3\nFound 3 markdown files\n[import.files] 3\/3 (100%) imported=3 skipped=0 errors=0\n\nImport complete (0.3s):\n  3 pages imported\n  0 pages skipped (0 unchanged, 0 errors)\n  3 chunks created<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Confirm:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain list\n# companies\/acme-ai           company   2026-05-22  Acme AI\n# concepts\/inference-optimization  concept  2026-05-22  Inference Optimization\n# people\/alice-chen           person    2026-05-22  Alice Chen<\/code><\/pre>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>Step 5 \u2014 Wire the knowledge graph<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">For a first-time import, run the link extractor explicitly to backfill the graph from your wikilinks. This is pure regex + typed inference \u2014 <strong>zero LLM calls<\/strong>.<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain extract links --source db<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Real output:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">[extract.links_db] 3\/3 (100%) done\nLinks: created 2 from 3 pages (db source)\nDone: 2 links, 0 timeline entries from 3 pages<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Two typed edges were inferred from the wikilinks: <code>alice-chen --works_at--&gt; acme-ai<\/code> (from \u201cFounder and CEO of \u2026\u201d) and <code>acme-ai --founded--&gt; alice-chen<\/code> (from \u201cFounded by \u2026\u201d). The inference cascade fires in order: <code>FOUNDED \u2192 INVESTED \u2192 ADVISES \u2192 WORKS_AT \u2192 MENTIONS<\/code>. No model in the loop.<\/p>\n<p class=\"wp-block-paragraph\">Inspect the graph directly:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain graph-query people\/alice-chen --depth 1\n# [depth 0] people\/alice-chen\n#   --works_at-&gt; companies\/acme-ai (depth 1)<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain backlinks companies\/acme-ai\n# [\n#   {\n#     \"from_slug\": \"people\/alice-chen\",\n#     \"to_slug\": \"companies\/acme-ai\",\n#     \"link_type\": \"works_at\",\n#     \"context\": \"Founder and CEO of [[companies\/acme-ai]]...\",\n#     \"link_source\": \"markdown\",\n#     ...\n#   }\n# ]<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">This is the difference between vector search and structured retrieval. \u201cWho works at Acme AI?\u201d is now a one-hop typed-edge traversal, not a similarity score. That structural channel is what drives the +31.4-point P@5 lift over the graph-disabled variant on BrainBench.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Step 6 \u2014 Run a search<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">GBrain ships two search verbs. <code>gbrain search<\/code> is keyword-only (BM25 on Postgres <code>tsvector<\/code>) and works without embeddings:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain search \"inference\"\n# [0.3648] companies\/acme-ai -- YC W24 inference-optimization startup...\n# [0.3648] people\/alice-chen -- Founder and CEO of [[companies\/acme-ai]]...<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\"><code>gbrain query<\/code> is the full hybrid pipeline: vector (HNSW on pgvector) + BM25 + Reciprocal Rank Fusion + optional multi-query expansion (Anthropic Haiku) + an optional ZeroEntropy reranker. It needs embeddings, which we deferred in Step 2 \u2014 wire them up now:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\"># Set one of: ZEROENTROPY_API_KEY (default), OPENAI_API_KEY, or VOYAGE_API_KEY\nexport OPENAI_API_KEY=sk-...\ngbrain config set embedding_model openai:text-embedding-3-large\ngbrain embed --all          # one-time backfill against your embedding provider\ngbrain query \"who works on small-model inference?\"<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\"># Set one of: ZEROENTROPY_API_KEY (default), OPENAI_API_KEY, or VOYAGE_API_KEY\nexport OPENAI_API_KEY=sk-...\ngbrain config set embedding_model openai:text-embedding-3-large\ngbrain embed --all          # one-time backfill against your embedding provider\ngbrain query \"who works on small-model inference?\"<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Three search modes ship out of the box \u2014 <code>conservative<\/code>, <code>balanced<\/code>, <code>tokenmax<\/code> \u2014 bundling the cost\/quality knobs into one config key. Default is <code>balanced<\/code> with the ZeroEntropy reranker on. RRF formula: <code>score = sum(1 \/ (60 + rank))<\/code>.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Step 7 \u2014 Connect to Claude Code via MCP<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">The brain is more useful when an AI agent can read and write to it directly. GBrain exposes <strong>74 tools<\/strong> over the Model Context Protocol via stdio. The canonical setup is one command (not a hand-edited JSON file):<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">claude mcp add gbrain -- gbrain serve<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Verify the install:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">claude mcp list\n# gbrain  stdio  gbrain serve<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Now ask Claude Code something like <em>\u201csearch the brain for inference optimization\u201d<\/em> and it\u2019ll route through the <code>search<\/code> tool and return your indexed results. The actual MCP tool names are plain snake_case: <code>get_page<\/code>, <code>put_page<\/code>, <code>delete_page<\/code>, <code>list_pages<\/code>, <code>search<\/code>, <code>query<\/code>, <code>add_link<\/code>, <code>get_backlinks<\/code>, <code>add_tag<\/code>, and 65 more.<\/p>\n<p class=\"wp-block-paragraph\"><strong>Cursor and Windsurf<\/strong> use the standard MCP JSON config in their respective settings UIs. The server spec is the same:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">{\n  \"mcpServers\": {\n    \"gbrain\": { \"command\": \"gbrain\", \"args\": [\"serve\"] }\n  }\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\"><strong>Claude Desktop<\/strong> uses <code>claude_desktop_config.json<\/code> for <em>local stdio<\/em> MCP servers with the same JSON spec. <em>Remote<\/em> HTTP MCP servers must be added through Settings \u2192 Integrations with a bearer token. See <code>docs\/mcp\/CLAUDE_DESKTOP.md<\/code> in the repo for the GUI walkthrough.<\/p>\n<p class=\"wp-block-paragraph\">If you want remote access from any machine, swap stdio for HTTP:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain serve --http --port 8787\n# Bearer auth, default-deny CORS, two-bucket rate limit, per-request audit log.\n# Postgres-only by design (PGLite is local-only).<\/code><\/pre>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>Step 8 \u2014 Let the brain run itself<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">GBrain ships an autopilot loop. As of v0.36.4, one command computes a dependency-ordered remediation plan, submits each step as a Minion job, re-checks the brain\u2019s health score between steps, and refuses to spend past your cost cap:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain doctor --remediate --yes --target-score 90 --max-usd 5<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Or run it as a daemon:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain autopilot --install        # cron-driven, 5-minute tick<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">Healthy brains sleep for 60 minutes between ticks. Unhealthy ones get the full overnight cycle: sync, extract, embed, consolidate, synthesize. Three phases (<code>synthesize<\/code>, <code>patterns<\/code>, <code>consolidate<\/code>) are protected so an MCP-connected agent can\u2019t silently burn API credits.<\/p>\n<p class=\"wp-block-paragraph\">For ad-hoc background work, the <strong>Minions<\/strong> queue takes shell jobs and LLM subagent jobs side by side:<\/p>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">gbrain jobs submit sync --params '{}' --follow\ngbrain jobs stats\ngbrain jobs work --queue default<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\"><strong>One PGLite caveat:<\/strong> <code>gbrain jobs supervisor<\/code> (the auto-restarting worker daemon) is <strong>Postgres-only<\/strong>. PGLite\u2019s exclusive file lock blocks the separate worker process \u2014 the CLI rejects with a clear error if <code>config.engine === 'pglite'<\/code>. If you\u2019re on PGLite, stick with inline <code>--follow<\/code> jobs for the tutorial, or run <code>gbrain migrate --to supabase<\/code> before standing up a persistent worker.<\/p>\n<p class=\"wp-block-paragraph\">Routing rule: deterministic work (pull tweets, parse JSON, write a page) goes to Minions; judgment work (triage an inbox, assess priority) goes to LLM sub-agents.<\/p>\n<h2 class=\"wp-block-heading\"><strong>What just happened, in one diagram<\/strong><\/h2>\n<div class=\"dm-code-snippet dark dm-normal-version default no-background-mobile\">\n<div class=\"control-language\">\n<div class=\"dm-buttons\">\n<div class=\"dm-buttons-left\">\n<div class=\"dm-button-snippet red-button\"><\/div>\n<div class=\"dm-button-snippet orange-button\"><\/div>\n<div class=\"dm-button-snippet green-button\"><\/div>\n<\/div>\n<div class=\"dm-buttons-right\"><a><span class=\"dm-copy-text\">Copy Code<\/span><span class=\"dm-copy-confirmed\">Copied<\/span><span class=\"dm-error-message\">Use a different Browser<\/span><\/a><\/div>\n<\/div>\n<pre class=\" no-line-numbers\"><code class=\" no-wrap language-php\">markdown files  \u2500\u2500&gt;  PGLite + pgvector  &lt;\u2500\u2500&gt;  43 skills\n(your repo,           (hybrid retrieval +     (HOW to use the brain;\n source of truth)      typed graph)           RESOLVER.md routes intent)\n       \u25b2                                              \u2502\n       \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500  agent reads\/writes  \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/code><\/pre>\n<\/div>\n<\/div>\n<p class=\"wp-block-paragraph\">The markdown repo is the system of record. GBrain is the retrieval + graph layer over it. The agent reads and writes through both, and humans can always open any <code>.md<\/code> file and edit it directly \u2014 <code>gbrain sync<\/code> picks up the change.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Where to go next<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><strong>One-line capture<\/strong> (new in v0.38): <code>gbrain capture \"the thought I want to remember\"<\/code> lands directly in <code>inbox\/YYYY-MM-DD-&lt;hash&gt;<\/code>. Also accepts <code>--file<\/code>, <code>--stdin<\/code>, and webhook ingestion via <code>gbrain serve --http \/ingest<\/code>.<\/li>\n<li><strong>Migrate to Supabase<\/strong> when your brain outgrows local (PGLite is good up to ~50K pages): <code>gbrain migrate --to supabase<\/code>.<\/li>\n<li><strong>Ingest real data<\/strong> with one of the recipes: voice (Twilio + OpenAI Realtime), email + calendar, 16 embedding providers, credential gateway.<\/li>\n<li><strong>Run the benchmarks<\/strong> in the sibling repo <a href=\"https:\/\/github.com\/garrytan\/gbrain-evals\">gbrain-evals<\/a>: BrainBench (synthetic) and <code>gbrain eval longmemeval<\/code> (the public LongMemEval benchmark).<\/li>\n<li><strong>Author your own skills.<\/strong> A skill is a fat markdown file that encodes a workflow \u2014 triggers, checks, quality gate. <code>gbrain check-resolvable<\/code> validates the skill tree for reachability \/ MECE \/ DRY.<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\">The deeper bet behind GBrain is that <strong>thin harness, fat skills<\/strong> beats thin skills behind a fat agent. The runtime stays small; the intelligence lives in markdown files the agent reads at decision time. Each commit you make to your brain repo is permanent context your agent inherits the next time it wakes up. The longer you run it, the smarter it gets.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Marktechpost\u2019s Visual Explainer<\/strong><\/h2>\n<div>\n<div class=\"gbs-header\">\n<div class=\"gbs-brand\">GBrain v0.38 Tutorial<\/div>\n<div class=\"gbs-counter\"><span>01<\/span> \/ 11<\/div>\n<\/div>\n<div class=\"gbs-track\">\n<p>    <!-- Slide 1: Hero --><\/p>\n<div class=\"gbs-slide gbs-active\">\n<div class=\"gbs-step\">Step-by-Step Tutorial<\/div>\n<h2 class=\"gbs-title\">Implementing GBrain: The Self-Wiring Memory Layer for AI Agents<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">A hands-on walkthrough of <strong>Garry Tan\u2019s open-source agent brain<\/strong>: install, import, hybrid search, graph wiring, and MCP integration in ~20 minutes.<\/p>\n<div class=\"gbs-grid\">\n<div class=\"gbs-stat\"><span class=\"v\">v0.38.2<\/span><span class=\"l\">Latest release<\/span><\/div>\n<div class=\"gbs-stat\"><span class=\"v\">43<\/span><span class=\"l\">Skills shipped<\/span><\/div>\n<div class=\"gbs-stat\"><span class=\"v\">98%<\/span><span class=\"l\">TypeScript<\/span><\/div>\n<div class=\"gbs-stat\"><span class=\"v\">MIT<\/span><span class=\"l\">License<\/span><\/div>\n<\/div>\n<\/div>\n<p>    <!-- Slide 2: Problem --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">The Problem<\/div>\n<h2 class=\"gbs-title\">AI Agents Are Smart But Forgetful<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">Every session starts from zero. No memory of who you met, what you read, or what you decided last week.<\/p>\n<ul class=\"gbs-list\">\n<li><strong>Vector DBs alone miss exact phrases and structural questions<\/strong><\/li>\n<li><strong>Keyword search alone misses conceptual matches<\/strong><\/li>\n<li><strong>Most memory layers can\u2019t answer \u201cwho works at X?\u201d<\/strong><\/li>\n<li><strong>Sub-agents are slow and expensive for deterministic work<\/strong><\/li>\n<\/ul><\/div>\n<p>    <!-- Slide 3: What is GBrain --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">What Is GBrain<\/div>\n<h2 class=\"gbs-title\">The Brain Powering Y Combinator\u2019s CEO<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">Production stats from Garry Tan\u2019s personal OpenClaw\/Hermes deployment, current as of v0.38.2.0.<\/p>\n<div class=\"gbs-grid\">\n<div class=\"gbs-stat\"><span class=\"v\">146,646<\/span><span class=\"l\">Pages indexed<\/span><\/div>\n<div class=\"gbs-stat\"><span class=\"v\">24,585<\/span><span class=\"l\">People tracked<\/span><\/div>\n<div class=\"gbs-stat\"><span class=\"v\">5,339<\/span><span class=\"l\">Companies<\/span><\/div>\n<div class=\"gbs-stat\"><span class=\"v\">66<\/span><span class=\"l\">Cron jobs<\/span><\/div>\n<\/div>\n<p class=\"gbs-sub\">Hybrid search on BrainBench: <strong>P@5 49.1%, R@5 97.9%<\/strong> \u2014 a +31.4-point P@5 lead over the same code with the graph layer disabled.<\/p>\n<\/div>\n<p>    <!-- Slide 4: Install --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Step 1 \u2014 Install<\/div>\n<h2 class=\"gbs-title\">Install Bun, Then GBrain<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">As of v0.38, the canonical install is <strong>a single global Bun install<\/strong>.<\/p>\n<pre><code><span class=\"gbs-cmt\"># Install Bun<\/span>\ncurl -fsSL https:\/\/bun.sh\/install | bash\nexec $SHELL\n\n<span class=\"gbs-cmt\"># Install GBrain<\/span>\nbun install -g github:garrytan\/gbrain\n\ngbrain --version\n<span class=\"gbs-dim\">gbrain 0.38.2.0<\/span><\/code><\/pre>\n<\/div>\n<p>    <!-- Slide 5: Init --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Step 2 \u2014 Initialize<\/div>\n<h2 class=\"gbs-title\">Create a Local Brain in Two Seconds<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\"><strong>PGLite<\/strong> is full Postgres 17 compiled to WASM. No Docker, no server.<\/p>\n<pre><code><span class=\"gbs-cmt\"># Defer embedding setup until search step<\/span>\ngbrain init --pglite --no-embedding\n<span class=\"gbs-dim\">Setting up local brain with PGLite...\n  Schema version 1 \u2192 85 (81 migration(s) pending)\n  [2] slugify_existing_pages... <span class=\"gbs-grn\">\u2713<\/span>\n  [3] unique_chunk_index...     <span class=\"gbs-grn\">\u2713<\/span>\n  ...\nBrain ready at ~\/.gbrain\/brain.pglite\n0 pages. Engine: PGLite.<\/span><\/code><\/pre>\n<\/div>\n<p>    <!-- Slide 6: Brain Repo --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Step 3 \u2014 Brain Repo<\/div>\n<h2 class=\"gbs-title\">Compiled Truth + Timeline Pattern<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">Every page is one markdown file. <strong>Wikilinks need full slug paths<\/strong> \u2014 <code>[[people\/alice-chen]]<\/code>, not <code>[[alice-chen]]<\/code>.<\/p>\n<pre><code><span class=\"gbs-cmt\">--- people\/alice-chen.md ---<\/span>\ntype: person\ntitle: Alice Chen\ntags: [founder, ai-infra]\n\u2014\u2014\u2014\n\nFounder\/CEO of [[companies\/acme-ai]].\nPreviously staff engineer at Google Brain.\n\n\u2014\u2014\u2014\n\n- 2024-09-04: $12M seed, Sequoia led\n- 2025-01-18: Open-sourced router<\/code><\/pre>\n<\/div>\n<p>    <!-- Slide 7: Import --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Step 4 \u2014 Import<\/div>\n<h2 class=\"gbs-title\">Import is Idempotent (SHA-256 Dedup)<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">Captured from a real run. <strong>Pass <code>--no-embed<\/code><\/strong> to defer embeddings until the search step.<\/p>\n<pre><code>gbrain import ~\/my-brain\/ --no-embed\n<span class=\"gbs-dim\">Found 3 markdown files\n[import.files] 3\/3 (100%) imported=3 skipped=0 errors=0\n\nImport complete (0.3s):\n  3 pages imported\n  3 chunks created<\/span><\/code><\/pre>\n<\/div>\n<p>    <!-- Slide 8: Graph --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Step 5 \u2014 Graph<\/div>\n<h2 class=\"gbs-title\">Wire the Graph with Zero LLM Calls<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">Regex inference cascade: <strong>FOUNDED \u2192 INVESTED \u2192 ADVISES \u2192 WORKS_AT \u2192 MENTIONS<\/strong>.<\/p>\n<pre><code>gbrain extract links --source db\n<span class=\"gbs-dim\">Links: created 2 from 3 pages\nDone: 2 links, 0 timeline entries<\/span>\n\ngbrain graph-query people\/alice-chen --depth 1\n<span class=\"gbs-dim\">[depth 0] people\/alice-chen\n  <span class=\"gbs-grn\">--works_at-&gt;<\/span> companies\/acme-ai (depth 1)<\/span><\/code><\/pre>\n<\/div>\n<p>    <!-- Slide 9: Search --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Step 6 \u2014 Search<\/div>\n<h2 class=\"gbs-title\">Hybrid: Vector + BM25 + RRF + Reranker<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">Three modes ship out of the box: <strong>conservative, balanced, tokenmax<\/strong>. RRF formula: <code>score = sum(1 \/ (60 + rank))<\/code>.<\/p>\n<pre><code>gbrain search \"inference\"\n<span class=\"gbs-dim\">[0.3648] companies\/acme-ai \u2014 YC W24\n        inference-optimization startup...\n[0.3648] people\/alice-chen \u2014 Founder\/CEO of\n        [[companies\/acme-ai]]...<\/span>\n\ngbrain query \"who works on small-model inference?\"\n<span class=\"gbs-cmt\"># Hybrid: vector + BM25 + RRF + ZeroEntropy rerank<\/span><\/code><\/pre>\n<\/div>\n<p>    <!-- Slide 10: MCP --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Step 7 \u2014 MCP<\/div>\n<h2 class=\"gbs-title\">Wire Into Claude Code in One Command<\/h2>\n<div class=\"gbs-line\"><\/div>\n<p class=\"gbs-sub\">GBrain exposes <strong>74 tools<\/strong> over MCP via stdio. The canonical setup is one CLI call \u2014 not a hand-edited JSON file.<\/p>\n<pre><code>claude mcp add gbrain -- gbrain serve\n\n<span class=\"gbs-cmt\"># For Cursor \/ Windsurf, use the standard JSON config:<\/span>\n{\n  \"mcpServers\": {\n    \"gbrain\": {\n      \"command\": \"gbrain\",\n      \"args\": [\"serve\"]\n    }\n  }\n}<\/code><\/pre>\n<p class=\"gbs-sub\">Tool names are plain snake_case: <strong>get_page, put_page, search, query, add_link, get_backlinks<\/strong>, and 68 more.<\/p>\n<\/div>\n<p>    <!-- Slide 11: Takeaways --><\/p>\n<div class=\"gbs-slide\">\n<div class=\"gbs-step\">Key Takeaways<\/div>\n<h2 class=\"gbs-title\">What You Just Built<\/h2>\n<div class=\"gbs-line\"><\/div>\n<ul class=\"gbs-list\">\n<li><strong>Markdown-first memory<\/strong> \u2014 humans can always read and edit the source of truth<\/li>\n<li><strong>Self-wiring graph<\/strong> \u2014 typed edges extracted on every save, zero LLM cost<\/li>\n<li><strong>Hybrid search<\/strong> \u2014 vector + BM25 + RRF + ZeroEntropy reranker, three preset modes<\/li>\n<li><strong>Local Postgres<\/strong> \u2014 PGLite by default (up to ~50K pages), Supabase on demand<\/li>\n<li><strong>MCP-native<\/strong> \u2014 74 tools across Claude Code, Cursor, Windsurf<\/li>\n<\/ul><\/div>\n<\/div>\n<div class=\"gbs-footer\">\n<div class=\"gbs-nav\">\n      <button class=\"gbs-btn\" disabled>\u2190 Prev<\/button><br \/>\n      <button class=\"gbs-btn\">Next \u2192<\/button>\n    <\/div>\n<div class=\"gbs-dots\"><\/div>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>Key Takeaways<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li>GBrain (v0.38.2.0) gives AI agents a persistent, markdown-first memory layer \u2014 built by Garry Tan to power his own OpenClaw\/Hermes deployments holding 146,646 pages and 24,585 people.<\/li>\n<li>Install runs locally in ~30 minutes on PGLite (Postgres 17 compiled to WASM, zero server) and scales to Supabase or self-hosted Postgres when needed.<\/li>\n<li>Every wikilink is parsed by a regex inference cascade (<code>FOUNDED \u2192 INVESTED \u2192 ADVISES \u2192 WORKS_AT<\/code>) that writes typed graph edges with zero LLM calls.<\/li>\n<li>Hybrid search (vector + BM25 + RRF + ZeroEntropy reranker) hits P@5 49.1% \/ R@5 97.9% on BrainBench \u2014 a +31.4-point P@5 lift over the graph-disabled variant.<\/li>\n<li>Exposes 74 tools over MCP \u2014 wire it into Claude Code with a single <code>claude mcp add gbrain -- gbrain serve<\/code> and your agent can read\/write the brain directly.<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\">\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<\/p><p class=\"wp-block-paragraph\">\n<\/p><p class=\"wp-block-paragraph\">Check out\u00a0the\u00a0<a href=\"https:\/\/github.com\/garrytan\/gbrain\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>GitHub<\/strong> <strong>Repo <\/strong><\/a>and<strong> <a href=\"https:\/\/github.com\/Marktechpost\/AI-Agents-Projects-Tutorials\/blob\/main\/Agentic%20AI%20Codes\/gbrain-tutorial.ipynb\" target=\"_blank\" rel=\"noreferrer noopener\">Implementation Codes<\/a>.\u00a0<\/strong>Also,\u00a0feel free to follow us on\u00a0<strong><a href=\"https:\/\/x.com\/intent\/follow?screen_name=marktechpost\" target=\"_blank\" rel=\"noreferrer noopener\"><mark>Twitter<\/mark><\/a><\/strong>\u00a0and don\u2019t forget to join our\u00a0<strong><a href=\"https:\/\/www.reddit.com\/r\/machinelearningnews\/\" target=\"_blank\" rel=\"noreferrer noopener\">150k+ ML SubReddit<\/a><\/strong>\u00a0and Subscribe to\u00a0<strong><a href=\"https:\/\/www.aidevsignals.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">our Newsletter<\/a><\/strong>. Wait! are you on telegram?\u00a0<strong><a href=\"https:\/\/t.me\/machinelearningresearchnews\" target=\"_blank\" rel=\"noreferrer noopener\">now you can join us on telegram as well.<\/a><\/strong><\/p>\n<p class=\"wp-block-paragraph\">Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.?\u00a0<strong><a href=\"https:\/\/forms.gle\/MTNLpmJtsFA3VRVd9\" target=\"_blank\" rel=\"noreferrer noopener\"><mark>Connect with us<\/mark><\/a><\/strong><\/p>\n<p>The post <a href=\"https:\/\/www.marktechpost.com\/2026\/05\/22\/a-step-by-step-coding-tutorial-to-implement-gbrain-the-self-wiring-memory-layer-built-by-y-combinators-garry-tan-for-ai-agents\/\">A Step-by-Step Coding Tutorial to Implement GBrain: The Self-Wiring Memory Layer Built by Y Combinator\u2019s Garry Tan for AI Agents<\/a> appeared first on <a href=\"https:\/\/www.marktechpost.com\/\">MarkTechPost<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Your AI agent is smart but for&hellip;<\/p>\n","protected":false},"author":1,"featured_media":29,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-962","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/962","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=962"}],"version-history":[{"count":0,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/962\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=\/wp\/v2\/media\/29"}],"wp:attachment":[{"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/connectword.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}