Skip to main content
Brain is configured through a brain.json file at the root of each brain vault, plus environment variables for secrets and global settings.

brain.json

Every brain vault has a brain.json configuration file. Created automatically by brain init, it controls identity, search strategy, and embedding settings.
{
  "id": "user:local:my-brain",
  "slug": "my-brain",
  "name": "My Brain",
  "type": "engineering",
  "owner": {
    "type": "user",
    "id": "local"
  },
  "homePath": ".",
  "strategy": {
    "default": "rag",
    "segments": []
  },
  "embedModel": "gemini-embedding-2-preview",
  "embedDims": 768
}

Fields

FieldTypeRequiredDescription
idstringYesScoped brain ID in format ownerType:ownerId:name
slugstringYesURL-safe identifier, used for database naming
namestringYesHuman-readable display name
typestringNoBrain type: generic, engineering, pm, gtm, research, ops, personal. Default: generic
ownerobjectYesOwner entity with type and id fields
homePathstringNoRelative path to vault root. Default: "."
strategyobjectNoSearch strategy configuration
embedModelstringNoEmbedding model name. Default: gemini-embedding-2-preview
embedDimsnumberNoEmbedding dimensions. Default: 768

Strategy Configuration

The strategy field controls how Brain routes search queries:
{
  "strategy": {
    "default": "rag",
    "segments": [
      {
        "name": "code-lookup",
        "strategy": "bm25",
        "pattern": "function|class|import|export"
      },
      {
        "name": "concepts",
        "strategy": "vector",
        "pattern": "why|how does|explain"
      }
    ]
  }
}
FieldDescription
defaultStrategy used when no segment matches: rag, bm25, or vector
segmentsArray of routing rules evaluated in order. First match wins

Updating Configuration

Use the CLI to update individual fields:
brain config set strategy.default vector --path ./my-brain
brain config set type engineering --path ./my-brain
Or edit brain.json directly — it’s a plain JSON file.

Environment Variables

VariableRequiredDescription
GEMINI_API_KEYYesGoogle Gemini API key for embeddings
GOOGLE_API_KEYNoAlternative to GEMINI_API_KEY (either works)
DATABASE_URLNoPostgres connection URL — selects persistent mode (see below)
BRAIN_DATA_DIRNoDirectory for embedded pgserve to persist to — selects data-dir mode
BRAIN_PG_URLNoExplicit PostgreSQL connection URL override
BRAIN_PG_PORTNopgserve port. Default: 15432
GENIE_PG_AVAILABLENoSet to true when running under Genie with managed Postgres
Never commit API keys to your repository. Use .env files or your system’s secret manager.

Deployment modes

Brain ships with an embedded Postgres (pgserve) so you don’t need to provision a database. Which mode it runs in is chosen by the environment:
ModeTriggerStorageWhen to use
EphemeralNeither DATABASE_URL nor BRAIN_DATA_DIR setpgserve RAM-onlyTests, CI, exploration. State is discarded when the process exits.
Data-dirBRAIN_DATA_DIR=/pathpgserve persists to the local directorySingle-machine personal brain. Survives restarts.
PersistentDATABASE_URL=postgres://…pgserve RAM + WAL sync to remote PostgresProduction, multi-agent, HA. Remote Postgres is the durable store; pgserve acts as a fast local cache.
All three modes use the same binary and the same CLI — only the environment changes. Switching between them is safe as long as the schema versions match (brain update handles migrations).

Embedding Models

Brain uses Gemini’s multimodal embedding model by default. The embedding model determines how content is vectorized for semantic search.
ModelDimensionsModalitiesNotes
gemini-embedding-2-preview768Text, image, audioDefault. Best quality for mixed-modality vaults
Changing the embedding model after indexing requires a full rebuild: brain rebuild --path ./my-brain. Existing embeddings are incompatible with different models.

Vault Structure

Brain expects this directory structure inside a vault:
my-brain/
├── brain.json           # Configuration (required)
├── memory/              # Agent memory files
├── domains/             # Domain knowledge documents
├── decisions/           # Architecture decision records
├── reflections/         # Self-assessment and retrospectives
├── mounts.json          # External mount points (auto-generated)
└── README.md            # Brain overview (optional)
All directories are optional — Brain creates them as needed. You can also add any custom directories; Brain indexes all .md files recursively.

Frontmatter Schema

Brain recognizes YAML frontmatter in markdown files for metadata and scoring:

Standard Fields

---
title: "Document Title"
type: domain | decision | reflection | note
confidence: high | medium | low
tags: [postgres, architecture]
created: 2024-01-15
updated: 2024-03-20
---

Domain Documents

---
title: "Payment Processing"
type: domain
confidence: high
domain: payments
boundary: "Stripe integration, invoice generation, refunds"
---

Decision Records

---
title: "Use PostgreSQL for Search"
type: decision
confidence: high
status: accepted | proposed | deprecated
decided: 2024-01-15
consequences: "Requires pgvector extension, adds ops complexity"
---

Reflection Documents

---
title: "Q1 Architecture Review"
type: reflection
confidence: medium
period: 2024-Q1
scope: architecture
---
Documents with type: decision and confidence: high receive the highest source weight in search results. Use this for authoritative content you want to surface first.

Health Checks

Brain includes a built-in health engine that monitors vault quality:
brain health --brain-id my-brain
── Brain Health: my-brain ──────────────────────
  Documents:     42 indexed, 0 stale
  Embeddings:    42/42 (100%)
  Conflicts:     0 detected
  Duplicates:    2 groups (run brain dedup for details)
  Grade:         A-

  Warnings:
  - 3 documents missing frontmatter type
  - 1 document exceeds 10,000 words (consider splitting)
Health dimensions:
  • Structure — frontmatter completeness, directory organization
  • Retrieval — embedding coverage, search quality
  • Trust — confidence distribution, provenance chains
  • Performance — index freshness, query latency

Auto-Brain (Genie Integration)

When used with Genie CLI, Brain can auto-provision itself for agents:
  1. Agent spawns — Genie detects the agent’s working directory
  2. Brain discovers or creates — checks for existing brain.json, creates one if missing
  3. Auto-index — indexes the agent’s context into the brain
  4. Search available — agent can immediately query its own knowledge
This is fully automatic when @khal-os/brain is installed alongside Genie. No configuration required.
Auto-brain is opt-in. If @khal-os/brain is not installed, Genie works exactly as before with zero behavior change.