mBm TUI (mbm2)
Menu

RAG Knowledge Base

You want to In /rag
See whether RAG works for this project Read the summary at the top
Turn RAG on or off for this project Turn RAG on/off for this project
Let sessions search and inject the knowledge base Use RAG in sessions…, then add the snippet it shows
Point RAG at a database or an embedding service A row under Settings
Fill the knowledge base Index this project, later Reindex changed files
Find what the knowledge base knows Search the knowledge base…
Keep it healthy Optimize, Backup now, Sync now, Install git hooks
Start over Full reindex… or Purge this project's data…

RAG (retrieval-augmented generation) keeps your project's files in a knowledge base: a PostgreSQL database with pgvector, filled through an embedding service (Ollama or an OpenAI-compatible API). When a session asks something, the runtime searches it and adds the best matches to the prompt; the answer then shows a Sources block and a ◫ RAG: line. The knowledge base is the one mBm v1 uses, so an existing one keeps working.

/rag (or /rag_setup) opens the panel. It is also in the palette (ctrl+p) as RAG. Everything is set from the panel; you never edit RAG's settings file yourself.

Open The Panel

  1. Type /rag and press return.

  2. The panel opens with a summary over a list:

      RAG                                                                esc
    
      Project    shop-api-1a2b · 3412 chunks · 12 pending files
      RAG        on for this project
      Sessions   tools off · inject off · limit 15 · min score 0
      Knowledge  reachable · PostgreSQL 17.2 · embedder ok
      Sync       every 30 min · next in 12 min
      Job        none running
    
      Search
    
      Actions
      Turn RAG off for this project RAG_ENABLED=0
      Use RAG in sessions… needs mbm.json: the RAG mcp entry and rag_inject
    
  3. Move with ↑/↓ (or type to filter), return runs a row, esc closes.

If the toast says RAG is not available from this runtime: …, the runtime you are connected to does not offer RAG; it needs the mBm runtime with the Go engine.

Summary row Meaning
Project The project id the knowledge base files this folder under, its chunks and files waiting to be indexed
RAG Whether RAG is on for this project (RAG_ENABLED)
Sessions Whether sessions have the RAG search tool and inject results, how many (limit) and the lowest average score kept
Knowledge Whether the database answered, and the embedding service's state; otherwise the error
Sync The background sync: its interval and the next run, idle while RAG is off, off when sessions do not use RAG
Job A long action that is running, with its progress

Set Up A Knowledge Base

Example: the database runs on db.local:25432 and Ollama on a GPU host.

  1. /rag → Settings → Database → type postgresql://rag:[email protected]:25432/mbm_rag → return. The field shows dots while you type; the panel then shows only db.local:25432/mbm_rag.
  2. Embedding URL → http://gpu:11434 → return. Toast Saved RAG_EMBED_URL.
  3. Embedding model → bge-m3:latest; Embedding dimension → 1024.
  4. For an OpenAI-compatible service: Embedding provider → openai, then Embedding API key (typed as dots, shown afterwards only as set (hidden)).
  5. Turn RAG on for this project. Toast RAG is on for this project; the Knowledge row should read reachable.

Changing the model or the dimension says so: the embedding model changed: migrate embeddings or run a full reindex. Existing chunks were embedded with the old model and do not match new queries until then.

Use RAG In Sessions

Use RAG in sessions… shows what the runtime needs in mbm.json (the project's or the global one) and copies it with c:

{
  "mcp": {
    "mbm-rag": { "type": "builtin", "name": "rag", "enabled": true }
  },
  "rag_inject": true
}

Add it, then restart mbm2. The Sessions row reads tools on · inject on. mbm2 does not write the runtime's config for you yet; the runtime has no command for it.

Row What it does Example
Index this project Reads every file of the project into the knowledge base First time in shop-api: a job dialog counts 120 of 340 files
Reindex changed files Only files changed since the last index After a refactor
Search the knowledge base… Runs a query and lists the sources with scores Type auth middleware → 0.9120 Auth middleware · src/auth.ts · code
Sync now One background sync cycle for every project on this device After working offline
Install git hooks Indexes the changed files after each git commit and git merge, by running mbm2 rag index --quiet <files> Toast Git hooks: post-commit: installed …

From a terminal, mbm2 rag index does what Index this project does without opening the TUI: mbm2 rag index indexes the current directory, mbm2 rag index docs/guide.md one file, and mbm2 rag index --quiet a.go b.go several files silently, which is what the git hooks run (CLI reference). The hooks look for mbm2 in MBM2_INSTALL_DIR, then ~/.mbm2/bin, then PATH. Hooks installed before this release still call v1's mbm: choose Uninstall git hooks, then Install git hooks, to replace them.

The panel's other actions have terminal commands too, each with v1's output: mbm2 rag status, mbm2 rag search "<question>", mbm2 rag reindex, mbm2 rag optimize, mbm2 rag purge --confirm yes, mbm2 rag hook install, mbm2 rag enable and the rest in the CLI reference. mbm2 rag setup is still v1's.

A long action opens a job dialog:

  Index this project

  state  running · 120 of 340
  ██████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░   35%

   Cancel job   Close

←/→ choose, return answers. Cancel job stops it; Close (or esc) only hides the dialog, the job goes on and the Job row shows it. Only one job runs at a time: starting another shows the running one and says Another RAG job is running: index.

Maintain

Row Asks first Effect
Optimize no Removes duplicates and stale chunks and vacuums the tables
Backup now no A pg_dump into ~/.mbm/backups; the newest seven are kept
Migrate embeddings… yes, naming the model and dimension Embeds every chunk again with the current model
Full reindex… yes, with the counts it deletes Deletes this project's chunks and indexes again; Backup, then reindex takes a backup first
Purge this project's data… yes, with the counts it deletes Deletes this project's chunks, pending files and compacted sessions; cannot be undone

A confirmation looks like this; the destructive choice is drawn in red when selected:

  Purge this project's data

  Project shop-api-1a2b: 3412 chunks, 12 pending files and 4 compacted sessions
  are deleted. This cannot be undone.

   Purge   Cancel

When Something Is Wrong

You see Do
Knowledge unreachable: … Check Database; the database must be running and reachable from the runtime's host
embedder unreachable Check Embedding URL and that the model is pulled (ollama pull bge-m3)
Sessions tools off after adding the snippet Restart mbm2; the runtime reads mbm.json when it starts
Sync timer off Sessions do not use RAG yet; add the snippet
A job failed The dialog shows the runtime's message; fix the setting it names and run it again

Related: Configuration cookbook, Slash commands, Troubleshooting.

Published from revision f88fc66f 2026-11-30