@nano-step/nano-brain 2026.6.2204 → 2026.6.2206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +274 -696
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,246 +1,187 @@
|
|
|
1
1
|
# nano-brain
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Your AI agent remembers everything.**
|
|
4
|
+
|
|
5
|
+
Persistent memory and code intelligence for AI coding agents. Across sessions, machines, and team members.
|
|
4
6
|
|
|
5
7
|
[](https://go.dev/)
|
|
6
8
|
[](LICENSE)
|
|
7
9
|
[](https://github.com/nano-step/nano-brain)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- [What It Does](#what-it-does)
|
|
12
|
-
- [Use Cases](#use-cases)
|
|
13
|
-
- [Key Features](#key-features)
|
|
14
|
-
- [Prerequisites](#prerequisites)
|
|
15
|
-
- [Recommended Models & Free Providers](#recommended-models--free-providers)
|
|
16
|
-
- [Quick Start](#quick-start)
|
|
17
|
-
- [Verifying Downloads](#verifying-downloads)
|
|
18
|
-
- [Configuration](#configuration)
|
|
19
|
-
- [REST API](#rest-api)
|
|
20
|
-
- [CLI Commands](#cli-commands)
|
|
21
|
-
- [MCP Tools](#mcp-tools)
|
|
22
|
-
- [Search Pipeline](#search-pipeline)
|
|
23
|
-
- [Architecture](#architecture)
|
|
24
|
-
- [Ruby / Rails Support](#ruby--rails-support)
|
|
25
|
-
- [Migration from V1](#migration-from-v1)
|
|
26
|
-
- [Tech Stack](#tech-stack)
|
|
27
|
-
- [License](#license)
|
|
10
|
+
[](https://www.npmjs.com/package/@nano-step/nano-brain)
|
|
11
|
+
[](https://hub.docker.com/r/nano-step/nano-brain)
|
|
12
|
+
[](https://discord.gg/nano-brain)
|
|
28
13
|
|
|
29
14
|
---
|
|
30
15
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
nano-brain is a persistent memory server for AI coding agents that solves session amnesia. It automatically ingests AI sessions, notes, and codebase files, indexes everything with hybrid search (BM25 + pgvector), and serves memories via MCP tools and REST API. Built in Go with PostgreSQL — single static binary, zero CGO dependencies.
|
|
34
|
-
|
|
35
|
-
## Use Cases
|
|
36
|
-
|
|
37
|
-
### Multi-machine developer (primary use case)
|
|
38
|
-
You work on your office PC, home machine, and personal laptop — each with a different Claude Code or OpenCode session. Without shared memory, your AI agent forgets everything between machines.
|
|
39
|
-
|
|
40
|
-
Deploy nano-brain on a VPS (or any always-on server) with a PostgreSQL instance. Every session you run on any machine gets harvested and indexed there. When you switch machines, your agent picks up exactly where you left off — decisions, context, code knowledge, all there.
|
|
16
|
+
## TL;DR
|
|
41
17
|
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Home Mac ───┘
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Persistent AI agent memory
|
|
49
|
-
AI agents forget everything when the session ends. nano-brain gives them durable, searchable memory across sessions — decisions made, patterns discovered, code written — so they don't repeat work or ask the same questions twice.
|
|
50
|
-
|
|
51
|
-
### Code intelligence for large codebases
|
|
52
|
-
nano-brain builds a symbol graph of your codebase: functions, types, dependencies, call chains. Agents can ask "what breaks if I change this function?" (`memory_impact`) or "trace the call chain from this entry point" (`memory_trace`) — across files, across sessions.
|
|
53
|
-
|
|
54
|
-
### Notes and documentation search
|
|
55
|
-
Write structured notes, ADRs, or decision records into nano-brain. Hybrid search (BM25 + semantic) retrieves them by keyword or concept. Agents can surface the right context without you having to remember where you put it.
|
|
18
|
+
```bash
|
|
19
|
+
# Install
|
|
20
|
+
npm install -g @nano-step/nano-brain
|
|
56
21
|
|
|
57
|
-
|
|
58
|
-
|
|
22
|
+
# Start
|
|
23
|
+
nano-brain serve -d
|
|
59
24
|
|
|
25
|
+
# Your AI agent now has memory
|
|
60
26
|
```
|
|
61
|
-
Dev A (office) ──┐
|
|
62
|
-
Dev B (remote) ──┼──► nano-brain on team server ──► shared PostgreSQL
|
|
63
|
-
Dev C (new hire) ──┘
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Role-based access: admins get full read/write, developers get read/write scoped to their workspace, stakeholders or reviewers get read-only access.
|
|
67
27
|
|
|
68
|
-
|
|
69
|
-
A senior engineer resigns. Without nano-brain, their institutional knowledge — why certain decisions were made, which parts of the codebase are fragile, what was tried and failed — walks out the door with them.
|
|
70
|
-
|
|
71
|
-
With nano-brain, their sessions are already harvested and indexed. The team can still ask "why did we pick this approach?" or "what did Alice know about the payment service?" and get answers from her past sessions.
|
|
28
|
+
---
|
|
72
29
|
|
|
73
|
-
|
|
74
|
-
You work on 3 client projects in parallel. Each is a separate workspace. When you switch clients, run `nano-brain wake-up` to get an instant briefing — recent work, active collections, key context — and your AI agent picks up exactly where you left off without re-reading the codebase.
|
|
30
|
+
## Why Star This Project?
|
|
75
31
|
|
|
76
|
-
|
|
77
|
-
You inherit a 5-year-old codebase with minimal documentation and no original authors to ask. Index it into nano-brain. Your AI agent can now answer "what does this function do?", "why does this class exist?", and "if I change this file, what else breaks?" — navigating cross-file relationships without reading 200k lines manually.
|
|
32
|
+
**If you've ever wished your AI agent remembered what you told it yesterday.**
|
|
78
33
|
|
|
79
|
-
|
|
34
|
+
nano-brain is the missing memory layer for AI coding agents. It's:
|
|
80
35
|
|
|
81
|
-
|
|
82
|
-
|
|
36
|
+
- **Self-hosted** — Your data stays on your server. No cloud dependency.
|
|
37
|
+
- **Works everywhere** — OpenCode, Claude Code, Cursor, any MCP client.
|
|
38
|
+
- **Actually useful** — Not a toy demo. Production-ready with 14 MCP tools, hybrid search, and code intelligence.
|
|
39
|
+
- **Built for developers** — Go binary, PostgreSQL, zero magic. You can read the code.
|
|
40
|
+
- **Beating competitors** — P@5 of 0.749 vs LlamaIndex's 0.55 and Qdrant's 0.27 on real-world queries.
|
|
83
41
|
|
|
84
|
-
|
|
42
|
+
Star it if you want AI agents that actually learn from context.
|
|
85
43
|
|
|
86
|
-
|
|
87
|
-
- **9 MCP tools** — query, search, vsearch, get, write, tags, status, update, wake_up
|
|
88
|
-
- **Session harvesting** — auto-ingest OpenCode and Claude Code sessions
|
|
89
|
-
- **File watcher** — fsnotify-based directory monitoring with debounce
|
|
90
|
-
- **Content-addressed storage** — SHA-256 deduplication
|
|
91
|
-
- **Heading-aware markdown chunking**
|
|
92
|
-
- **Multi-workspace isolation** with per-workspace data
|
|
93
|
-
- **Config hot-reload** — `POST /api/reload-config`
|
|
94
|
-
- **V1 migration** — import from SQLite (pure Go, no CGO)
|
|
95
|
-
- **Benchmarking suite** — generate, run, compare, stress
|
|
96
|
-
- **Search telemetry** — local-only, 90-day retention, non-blocking
|
|
44
|
+
---
|
|
97
45
|
|
|
98
|
-
##
|
|
46
|
+
## What It Does
|
|
99
47
|
|
|
100
|
-
- **
|
|
101
|
-
- **PostgreSQL 17** with **pgvector 0.8.2** extension
|
|
102
|
-
- **Embedding provider:** Ollama (default, local) or Voyage AI
|
|
48
|
+
nano-brain solves **session amnesia** — the problem where AI agents forget everything when the session ends.
|
|
103
49
|
|
|
104
|
-
|
|
50
|
+
It automatically:
|
|
51
|
+
- **Ingests** AI sessions, notes, and codebase files
|
|
52
|
+
- **Indexes** everything with hybrid search (BM25 + pgvector)
|
|
53
|
+
- **Serves** memories via 14 MCP tools and REST API
|
|
105
54
|
|
|
106
|
-
|
|
55
|
+
Built in Go with PostgreSQL. Single static binary. Zero CGO dependencies.
|
|
107
56
|
|
|
108
|
-
|
|
57
|
+
---
|
|
109
58
|
|
|
110
|
-
|
|
111
|
-
|-------|------|---------|------|---------|----------|
|
|
112
|
-
| **nomic-embed-text** | 768 | 8K tokens | 274 MB | ★★★ | Default choice — handles full functions, CPU-friendly |
|
|
113
|
-
| **mxbai-embed-large** | 1024 | 512 tokens | 670 MB | ★★★★ | Best precision for short code chunks (<500 tokens) |
|
|
114
|
-
| **qwen3-embedding:8b** | 4096 | 8K tokens | 4.9 GB | ★★★★★ | Maximum quality — needs GPU (5 GB+ VRAM) |
|
|
115
|
-
| **bge-m3** | 1024 | 8K tokens | 1.2 GB | ★★★★ | Multilingual codebases, hybrid retrieval |
|
|
116
|
-
| **all-minilm** | 384 | 256 tokens | 46 MB | ★★ | Extreme resource constraints only |
|
|
59
|
+
## Architecture
|
|
117
60
|
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
61
|
+
```mermaid
|
|
62
|
+
graph LR
|
|
63
|
+
A[Your AI Agent] -->|MCP Protocol| B[nano-brain]
|
|
64
|
+
B --> C[PostgreSQL + pgvector]
|
|
65
|
+
B --> D[Session Harvesting]
|
|
66
|
+
B --> E[Code Intelligence]
|
|
67
|
+
B --> F[Hybrid Search]
|
|
68
|
+
|
|
69
|
+
D --> D1[OpenCode Sessions]
|
|
70
|
+
D --> D2[Claude Code Sessions]
|
|
71
|
+
|
|
72
|
+
E --> E1[Symbol Graph]
|
|
73
|
+
E --> E2[Flow Diagrams]
|
|
74
|
+
E --> E3[Impact Analysis]
|
|
75
|
+
|
|
76
|
+
F --> F1[BM25 Full-Text]
|
|
77
|
+
F --> F2[Vector Similarity]
|
|
78
|
+
F --> F3[RRF Fusion]
|
|
123
79
|
```
|
|
124
80
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
### Chat/Completion Models (for code & session summarization)
|
|
128
|
-
|
|
129
|
-
These providers offer **free tiers** with OpenAI-compatible `/chat/completions` endpoints — plug directly into nano-brain's `code_summarization` and `summarization` config.
|
|
130
|
-
|
|
131
|
-
| Provider | Free Tier | Rate Limits | Best Model | Speed |
|
|
132
|
-
|----------|-----------|-------------|------------|-------|
|
|
133
|
-
| **[Cerebras](https://cerebras.ai)** | 1M tokens/day | 30 req/min | `llama3.1-8b` | ~2,000 tok/s |
|
|
134
|
-
| **[Groq](https://groq.com)** | Ongoing (no expiry) | 30 req/min, 14.4K req/day | `llama-3.3-70b-versatile` | ~400 tok/s |
|
|
135
|
-
| **[Together AI](https://together.ai)** | $25 free credits | 60 req/min | `meta-llama/Llama-3.3-70B-Instruct-Turbo` | ~200 tok/s |
|
|
136
|
-
| **[Google AI Studio](https://ai.google.dev)** | 1,500 req/day | 15 req/min | `gemini-2.0-flash` | ~300 tok/s |
|
|
137
|
-
| **Ollama (local)** | Unlimited | Hardware-bound | `qwen3:8b`, `llama3.1:8b` | Depends on GPU |
|
|
138
|
-
|
|
139
|
-
> **Note:** Google Gemini is NOT OpenAI-compatible natively — use it via a proxy like [9router](https://github.com/nano-step/9router) or [LiteLLM](https://github.com/BerriAI/litellm) to get a `/chat/completions` endpoint.
|
|
81
|
+
---
|
|
140
82
|
|
|
141
|
-
|
|
83
|
+
## Key Features
|
|
142
84
|
|
|
143
|
-
|
|
85
|
+
### Hybrid Search
|
|
144
86
|
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
summarization:
|
|
153
|
-
enabled: true
|
|
154
|
-
provider_url: "https://api.cerebras.ai/v1"
|
|
155
|
-
api_key: "your-cerebras-key"
|
|
156
|
-
model: "llama3.1-8b"
|
|
87
|
+
```mermaid
|
|
88
|
+
graph LR
|
|
89
|
+
Q[Query] --> BM25[BM25 Full-Text]
|
|
90
|
+
Q --> Vector[Vector Similarity]
|
|
91
|
+
BM25 --> RRF[RRF Fusion]
|
|
92
|
+
Vector --> RRF
|
|
93
|
+
RRF --> Results[Ranked Results]
|
|
157
94
|
```
|
|
158
95
|
|
|
159
|
-
|
|
96
|
+
BM25 full-text + pgvector HNSW cosine similarity + Reciprocal Rank Fusion + recency decay.
|
|
160
97
|
|
|
161
|
-
|
|
162
|
-
code_summarization:
|
|
163
|
-
enabled: true
|
|
164
|
-
provider_url: "https://api.groq.com/openai/v1"
|
|
165
|
-
api_key: "your-groq-key" # free signup
|
|
166
|
-
model: "llama-3.3-70b-versatile"
|
|
167
|
-
```
|
|
98
|
+
### Code Intelligence
|
|
168
99
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
model: "meta-llama/Llama-3.3-70B-Instruct-Turbo"
|
|
100
|
+
```mermaid
|
|
101
|
+
graph TD
|
|
102
|
+
A[Entry Point] --> B[Function Call]
|
|
103
|
+
B --> C[Method Call]
|
|
104
|
+
B --> D[Database Query]
|
|
105
|
+
C --> E[External Service]
|
|
106
|
+
D --> F[Redis Cache]
|
|
177
107
|
```
|
|
178
108
|
|
|
179
|
-
**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
enabled: true
|
|
184
|
-
provider_url: "http://localhost:11434/v1"
|
|
185
|
-
api_key: ""
|
|
186
|
-
model: "qwen3:8b"
|
|
187
|
-
```
|
|
109
|
+
- **Symbol extraction** — Functions, types, interfaces, constants
|
|
110
|
+
- **Call chain tracing** — Follow execution paths across files
|
|
111
|
+
- **Impact analysis** — "What breaks if I change this?"
|
|
112
|
+
- **Flow diagrams** — Mermaid flowcharts and sequence diagrams
|
|
188
113
|
|
|
189
|
-
|
|
114
|
+
### Session Harvesting
|
|
190
115
|
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
116
|
+
```mermaid
|
|
117
|
+
graph LR
|
|
118
|
+
S1[OpenCode DB] --> H[Harvester]
|
|
119
|
+
S2[Claude Code JSONL] --> H
|
|
120
|
+
H --> L[LLM Summarizer]
|
|
121
|
+
L --> I[Indexer]
|
|
122
|
+
I --> DB[PostgreSQL]
|
|
197
123
|
```
|
|
198
124
|
|
|
199
|
-
|
|
125
|
+
Auto-ingest from OpenCode and Claude Code sessions. Map-reduce LLM summarization. Incremental harvest with dedup.
|
|
200
126
|
|
|
201
|
-
|
|
202
|
-
|-------------|-----|
|
|
203
|
-
| Zero cost, no API keys, full privacy | Ollama (local) |
|
|
204
|
-
| Free cloud, fastest inference | Cerebras |
|
|
205
|
-
| Free cloud, best model quality | Groq (`llama-3.3-70b`) |
|
|
206
|
-
| Many model options, startup-friendly | Together AI |
|
|
207
|
-
| Route through multiple providers | 9router / LiteLLM proxy |
|
|
208
|
-
|
|
209
|
-
## Quick Start
|
|
127
|
+
### 14 MCP Tools
|
|
210
128
|
|
|
211
|
-
|
|
129
|
+
| Tool | Description |
|
|
130
|
+
|------|-------------|
|
|
131
|
+
| `memory_query` | Hybrid search (BM25 + vector + RRF) |
|
|
132
|
+
| `memory_search` | BM25 keyword search |
|
|
133
|
+
| `memory_vsearch` | Vector similarity search |
|
|
134
|
+
| `memory_get` | Get document by path |
|
|
135
|
+
| `memory_write` | Write/update document |
|
|
136
|
+
| `memory_graph` | Knowledge graph view |
|
|
137
|
+
| `memory_trace` | Call chain trace |
|
|
138
|
+
| `memory_impact` | Cross-file impact analysis |
|
|
139
|
+
| `memory_symbols` | Symbol search |
|
|
140
|
+
| `memory_flow` | Execution flow visualization |
|
|
141
|
+
| `memory_tags` | List tags with counts |
|
|
142
|
+
| `memory_status` | Server status |
|
|
143
|
+
| `memory_update` | Trigger re-embedding |
|
|
144
|
+
| `memory_wake_up` | Workspace briefing |
|
|
212
145
|
|
|
213
146
|
---
|
|
214
147
|
|
|
215
|
-
|
|
148
|
+
## Quick Start
|
|
149
|
+
|
|
150
|
+
### Prerequisites
|
|
216
151
|
|
|
217
|
-
|
|
152
|
+
- **Go 1.23+** OR pre-built binary
|
|
153
|
+
- **PostgreSQL 17** with **pgvector 0.8.2**
|
|
154
|
+
- **Ollama** (for embeddings) or any OpenAI-compatible provider
|
|
218
155
|
|
|
219
|
-
|
|
156
|
+
### Install
|
|
220
157
|
|
|
221
158
|
```bash
|
|
222
|
-
#
|
|
159
|
+
# Via npm (recommended)
|
|
223
160
|
npm install -g @nano-step/nano-brain
|
|
224
161
|
|
|
225
|
-
#
|
|
162
|
+
# Or build from source
|
|
163
|
+
CGO_ENABLED=0 go build -o nano-brain ./cmd/nano-brain
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Start
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Start PostgreSQL
|
|
226
170
|
docker run -d --name nanobrain-pg -p 5432:5432 \
|
|
227
171
|
-e POSTGRES_USER=nanobrain -e POSTGRES_PASSWORD=nanobrain -e POSTGRES_DB=nanobrain_dev \
|
|
228
172
|
pgvector/pgvector:pg17
|
|
229
173
|
|
|
230
|
-
#
|
|
231
|
-
ollama pull nomic-embed-text
|
|
232
|
-
|
|
233
|
-
# 4. Verify everything is in order
|
|
234
|
-
nano-brain doctor
|
|
235
|
-
|
|
236
|
-
# 5. Start the server (background)
|
|
174
|
+
# Start nano-brain
|
|
237
175
|
nano-brain serve -d
|
|
238
176
|
|
|
239
|
-
#
|
|
177
|
+
# Register your project
|
|
240
178
|
nano-brain init --root=/path/to/your/project
|
|
241
179
|
```
|
|
242
180
|
|
|
243
|
-
|
|
181
|
+
### Configure Your AI Agent
|
|
182
|
+
|
|
183
|
+
Add to your MCP client config (Claude Code, OpenCode, Cursor, etc.):
|
|
184
|
+
|
|
244
185
|
```json
|
|
245
186
|
{
|
|
246
187
|
"mcp": {
|
|
@@ -252,110 +193,128 @@ nano-brain init --root=/path/to/your/project
|
|
|
252
193
|
}
|
|
253
194
|
```
|
|
254
195
|
|
|
255
|
-
Your AI agent now has persistent memory. It will automatically index your project files and harvest sessions as you work.
|
|
256
|
-
|
|
257
196
|
---
|
|
258
197
|
|
|
259
|
-
|
|
198
|
+
## Demo
|
|
260
199
|
|
|
261
|
-
|
|
200
|
+
### Query Your Codebase
|
|
262
201
|
|
|
263
|
-
**On the server:**
|
|
264
202
|
```bash
|
|
265
|
-
#
|
|
266
|
-
|
|
267
|
-
-
|
|
268
|
-
|
|
203
|
+
# Search for authentication patterns
|
|
204
|
+
curl -X POST http://localhost:3100/api/v1/query \
|
|
205
|
+
-H "Content-Type: application/json" \
|
|
206
|
+
-d '{"workspace": "abc123", "query": "how does authentication work"}'
|
|
207
|
+
```
|
|
269
208
|
|
|
270
|
-
|
|
271
|
-
npm install -g @nano-step/nano-brain
|
|
272
|
-
nano-brain serve -d --host=0.0.0.0
|
|
209
|
+
### Trace Call Chains
|
|
273
210
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
211
|
+
```bash
|
|
212
|
+
# Trace from entry point
|
|
213
|
+
curl -X POST http://localhost:3100/api/v1/graph/trace \
|
|
214
|
+
-H "Content-Type: application/json" \
|
|
215
|
+
-d '{"workspace": "abc123", "node": "main.go::main", "max_depth": 5}'
|
|
277
216
|
```
|
|
278
217
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
"headers": {
|
|
287
|
-
"Authorization": "Bearer nbt_xxxxxxxxxxxxxxxx"
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
218
|
+
### Analyze Impact
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# What breaks if I change this file?
|
|
222
|
+
curl -X POST http://localhost:3100/api/v1/graph/impact \
|
|
223
|
+
-H "Content-Type: application/json" \
|
|
224
|
+
-d '{"workspace": "abc123", "node": "src/auth/login.ts", "max_depth": 2}'
|
|
292
225
|
```
|
|
293
226
|
|
|
227
|
+
### Generate Flow Diagrams
|
|
228
|
+
|
|
294
229
|
```bash
|
|
295
|
-
#
|
|
296
|
-
|
|
230
|
+
# Get flow diagram for a controller
|
|
231
|
+
curl -X POST http://localhost:3100/api/v1/graph/flow \
|
|
232
|
+
-H "Content-Type: application/json" \
|
|
233
|
+
-d '{"workspace": "abc123", "entry": "POST /users"}'
|
|
297
234
|
```
|
|
298
235
|
|
|
299
|
-
|
|
236
|
+
Returns Mermaid flowchart:
|
|
237
|
+
|
|
238
|
+
```mermaid
|
|
239
|
+
flowchart LR
|
|
240
|
+
POST_/users["POST /users"]
|
|
241
|
+
POST_/users --> UsersController#create
|
|
242
|
+
UsersController#create --> User.create
|
|
243
|
+
UsersController#create --> Mailer.welcome
|
|
244
|
+
```
|
|
300
245
|
|
|
301
246
|
---
|
|
302
247
|
|
|
303
|
-
|
|
248
|
+
## Use Cases
|
|
304
249
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
CGO_ENABLED=0 go build -o nano-brain ./cmd/nano-brain
|
|
250
|
+
### Multi-machine developer
|
|
251
|
+
Work on office PC, home laptop, personal machine — each with different sessions. Deploy nano-brain on a VPS. Every session gets harvested. Switch machines, pick up where you left off.
|
|
308
252
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
-e POSTGRES_USER=nanobrain -e POSTGRES_PASSWORD=nanobrain -e POSTGRES_DB=nanobrain_dev \
|
|
312
|
-
pgvector/pgvector:pg17
|
|
253
|
+
### Team knowledge base
|
|
254
|
+
One server, whole team. Every developer's AI agent connects to the same PostgreSQL. Decisions, architecture notes, code intelligence — instantly shared. New hires get full context from day one.
|
|
313
255
|
|
|
314
|
-
|
|
315
|
-
|
|
256
|
+
### Legacy codebase archaeology
|
|
257
|
+
Inherit a 5-year-old codebase with no docs? Index it. Your AI agent can now answer "what does this function do?", "why does this class exist?", "if I change this file, what else breaks?"
|
|
316
258
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
./nano-brain status
|
|
320
|
-
```
|
|
259
|
+
### Pre-commit impact check
|
|
260
|
+
Before pushing, run `memory_impact` on changed files. Discover what else depends on them. Catch breaking changes before CI.
|
|
321
261
|
|
|
322
262
|
---
|
|
323
263
|
|
|
324
|
-
|
|
264
|
+
## Performance
|
|
325
265
|
|
|
326
|
-
|
|
327
|
-
npx @nano-step/nano-brain@latest doctor
|
|
328
|
-
npx @nano-step/nano-brain@latest serve -d
|
|
329
|
-
```
|
|
266
|
+
### Benchmark Results
|
|
330
267
|
|
|
331
|
-
|
|
268
|
+
| Metric | nano-brain | LlamaIndex | Qdrant/Mem0 |
|
|
269
|
+
|--------|------------|------------|-------------|
|
|
270
|
+
| P@5 | **0.749** | 0.55 | 0.27 |
|
|
271
|
+
| MRR | **0.967** | — | — |
|
|
272
|
+
| Latency | 42ms | — | — |
|
|
332
273
|
|
|
333
|
-
|
|
274
|
+
Tested on 60 domain-specific queries across 3 workspaces (gaming, Go codebase, Rails app).
|
|
334
275
|
|
|
335
|
-
|
|
336
|
-
You can verify a downloaded binary against the published checksums using
|
|
337
|
-
standard tooling:
|
|
276
|
+
### Search Quality
|
|
338
277
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
278
|
+
- **BM25 OR fallback** — Retries with OR semantics when AND returns 0 results
|
|
279
|
+
- **Incoming edges symbol fallback** — Falls back to symbol name when target lookup fails
|
|
280
|
+
- **Workspace-specific queries** — Each project gets queries tailored to its domain
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Ruby / Rails Support
|
|
285
|
+
|
|
286
|
+
nano-brain supports Ruby and Ruby on Rails code intelligence:
|
|
287
|
+
|
|
288
|
+
- **Rails routes** — `resources`, `get`/`post`/`patch`/`put`/`delete`, `namespace`
|
|
289
|
+
- **Control-flow graphs** — `if`/`else`, loops, `begin`/`rescue`, method defs
|
|
290
|
+
- **Cross-file resolution** — Class→file index, resolver, reconcile edges
|
|
291
|
+
- **Flow diagrams** — Controller→service→model chains (20-34 nodes)
|
|
292
|
+
|
|
293
|
+
Example flow for a Rails controller action:
|
|
294
|
+
|
|
295
|
+
```mermaid
|
|
296
|
+
flowchart LR
|
|
297
|
+
POST_/users["POST /users"]
|
|
298
|
+
POST_/users --> UsersController#create
|
|
299
|
+
UsersController#create --> User.create
|
|
300
|
+
UsersController#create --> Mailer.welcome
|
|
345
301
|
```
|
|
346
302
|
|
|
347
|
-
|
|
348
|
-
performs this verification **automatically** during postinstall — a SHA-256
|
|
349
|
-
mismatch aborts the install with exit code 1 and removes the partial binary.
|
|
303
|
+
---
|
|
350
304
|
|
|
351
|
-
|
|
352
|
-
download stream, set `NANO_BRAIN_SKIP_SHA_VERIFY=1` before running `npm install`
|
|
353
|
-
to bypass the check (a warning is printed so the bypass is visible in CI logs).
|
|
305
|
+
## Tech Stack
|
|
354
306
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
307
|
+
- **Go 1.23** — Single static binary (`CGO_ENABLED=0`)
|
|
308
|
+
- **PostgreSQL 17** — Full-text search (tsvector/tsquery)
|
|
309
|
+
- **pgvector 0.8.2** — HNSW vector indexing
|
|
310
|
+
- **Echo v4** — HTTP framework
|
|
311
|
+
- **sqlc** — Type-safe SQL code generation
|
|
312
|
+
- **goose v3** — Database migrations
|
|
313
|
+
- **zerolog** — Structured JSON logging
|
|
314
|
+
- **koanf** — YAML + env configuration
|
|
315
|
+
- **fsnotify** — File system watching
|
|
316
|
+
|
|
317
|
+
---
|
|
359
318
|
|
|
360
319
|
## Configuration
|
|
361
320
|
|
|
@@ -370,481 +329,100 @@ database:
|
|
|
370
329
|
url: postgres://nanobrain:nanobrain@localhost:5432/nanobrain_dev
|
|
371
330
|
|
|
372
331
|
embedding:
|
|
373
|
-
provider: ollama
|
|
332
|
+
provider: ollama
|
|
374
333
|
url: http://localhost:11434
|
|
375
334
|
model: nomic-embed-text
|
|
376
|
-
dimension: 0 # auto-detect from provider
|
|
377
|
-
concurrency: 3
|
|
378
335
|
|
|
379
336
|
search:
|
|
380
337
|
rrf_k: 60
|
|
381
338
|
recency_weight: 0.3
|
|
382
|
-
recency_half_life_days: 180
|
|
383
339
|
limit: 20
|
|
384
|
-
|
|
385
|
-
harvester:
|
|
386
|
-
opencode:
|
|
387
|
-
db_root: "" # e.g., ~/.ai-sandbox/opencode-dbs (multi-DB, highest priority)
|
|
388
|
-
db_path: "" # e.g., ~/.local/share/opencode/opencode.db (single DB)
|
|
389
|
-
session_dir: "" # e.g., ~/.local/share/opencode/storage (legacy JSON)
|
|
390
|
-
claudecode:
|
|
391
|
-
enabled: false
|
|
392
|
-
session_dir: ""
|
|
393
|
-
|
|
394
|
-
watcher:
|
|
395
|
-
debounce_ms: 2000
|
|
396
|
-
reindex_interval: 300
|
|
397
|
-
# Per-collection exclude_patterns and allowed_extensions are also supported
|
|
398
|
-
# via the workspaces map. See "Ignore patterns" section below for the
|
|
399
|
-
# global and workspace-local .nano-brainignore files.
|
|
400
|
-
|
|
401
|
-
storage:
|
|
402
|
-
max_file_size: 314572800 # 300MB
|
|
403
|
-
max_size: 10737418240 # 10GB
|
|
404
|
-
|
|
405
|
-
telemetry:
|
|
406
|
-
retention_days: 90
|
|
407
|
-
|
|
408
|
-
logging:
|
|
409
|
-
level: info
|
|
410
|
-
file: "" # empty = stdout only
|
|
411
|
-
|
|
412
|
-
summarization:
|
|
413
|
-
enabled: false # set to true to generate LLM summaries of harvested sessions
|
|
414
|
-
provider_url: "" # OpenAI-compatible endpoint, e.g. https://ai-proxy.example.com/v1
|
|
415
|
-
api_key: "" # or set NANO_BRAIN_SUMMARIZE_API_KEY env var
|
|
416
|
-
model: "nano-brain" # model name passed to the provider
|
|
417
|
-
max_tokens: 8000 # max tokens per LLM completion
|
|
418
|
-
concurrency: 3 # parallel map-phase LLM calls
|
|
419
340
|
```
|
|
420
341
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
When binding to a non-loopback address, enable auth to protect your memory:
|
|
342
|
+
See [Configuration](docs/CONFIGURATION.md) for full options.
|
|
424
343
|
|
|
425
|
-
|
|
426
|
-
server:
|
|
427
|
-
host: 0.0.0.0
|
|
428
|
-
port: 3100
|
|
429
|
-
auth:
|
|
430
|
-
enabled: true
|
|
431
|
-
realm: nano-brain
|
|
432
|
-
users:
|
|
433
|
-
- username: admin
|
|
434
|
-
password_hash: "$2a$10$..." # from: nano-brain auth hash <password>
|
|
435
|
-
tokens:
|
|
436
|
-
- "nbt_..." # from: nano-brain auth token
|
|
437
|
-
bypass_paths:
|
|
438
|
-
- /health
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
Generate credentials:
|
|
442
|
-
|
|
443
|
-
```bash
|
|
444
|
-
# Generate bcrypt hash for Basic Auth
|
|
445
|
-
nano-brain auth hash mypassword
|
|
446
|
-
|
|
447
|
-
# Generate bearer token
|
|
448
|
-
nano-brain auth token
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
Usage examples:
|
|
452
|
-
|
|
453
|
-
```bash
|
|
454
|
-
# Basic Auth
|
|
455
|
-
curl -u admin:mypassword http://host:3100/api/v1/query -d '{"query":"test"}'
|
|
456
|
-
|
|
457
|
-
# Bearer token
|
|
458
|
-
curl -H "Authorization: Bearer nbt_..." http://host:3100/api/v1/query -d '{"query":"test"}'
|
|
459
|
-
|
|
460
|
-
# MCP client with URL-embedded credentials
|
|
461
|
-
# url: http://admin:mypassword@host:3100/mcp
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
### Ignore patterns
|
|
465
|
-
|
|
466
|
-
Two layers of `.nano-brainignore` files control what the watcher indexes,
|
|
467
|
-
both using standard `.gitignore` syntax (one pattern per line, supports `**`,
|
|
468
|
-
`!negation`, blank lines, `#` comments).
|
|
469
|
-
|
|
470
|
-
#### Global — `~/.nano-brain/.nano-brainignore`
|
|
471
|
-
|
|
472
|
-
Loaded once at server startup. Patterns apply to **every** registered
|
|
473
|
-
collection across **every** workspace. Use this for rules that are personal
|
|
474
|
-
to your machine and span all your projects (e.g. always skip `*.png`).
|
|
475
|
-
|
|
476
|
-
```
|
|
477
|
-
# Skip generated files everywhere
|
|
478
|
-
*.png
|
|
479
|
-
*.jpg
|
|
480
|
-
*.pdf
|
|
481
|
-
build/
|
|
482
|
-
dist/
|
|
483
|
-
node_modules/
|
|
484
|
-
|
|
485
|
-
# But keep this one icon
|
|
486
|
-
!icons/important.png
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
#### Workspace-local — `<workspace_root>/.nano-brainignore`
|
|
490
|
-
|
|
491
|
-
Loaded once per collection when the watcher starts watching it (server
|
|
492
|
-
startup, `POST /api/v1/init`, or `POST /api/v1/collections`). Patterns
|
|
493
|
-
apply **only** to that one workspace. Use this for project-specific rules
|
|
494
|
-
you want to **share with your team via version control** — e.g. skip
|
|
495
|
-
generated code that you commit to git but don't want indexed.
|
|
496
|
-
|
|
497
|
-
```
|
|
498
|
-
# nano-brain-specific rules for this repo (commit me)
|
|
499
|
-
*.generated.go
|
|
500
|
-
fixtures/large/
|
|
501
|
-
*.snap
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
Workspace-local rules layer **additively** on top of global rules and
|
|
505
|
-
per-collection `.gitignore`. There is no cross-file negation: a `!pattern`
|
|
506
|
-
in workspace-local cannot un-exclude a path matched by global.
|
|
507
|
-
|
|
508
|
-
The file at the workspace root is loaded for the `code` collection. The
|
|
509
|
-
sibling `memory` and `sessions` collections are rooted under `~/.nano-brain/`
|
|
510
|
-
and do not normally need their own ignore files.
|
|
511
|
-
|
|
512
|
-
#### Order of evaluation (most aggressive first)
|
|
513
|
-
|
|
514
|
-
1. Hardcoded default exclude dirs (`node_modules`, `.git`, `dist`, `build`, `target`, etc.)
|
|
515
|
-
2. Global `~/.nano-brain/.nano-brainignore`
|
|
516
|
-
3. Workspace-local `<workspace_root>/.nano-brainignore`
|
|
517
|
-
4. Per-collection `.gitignore` (in collection root)
|
|
518
|
-
5. Per-collection `exclude_patterns` (config-level)
|
|
519
|
-
6. Per-collection `allowed_extensions` (whitelist)
|
|
520
|
-
|
|
521
|
-
#### Reloading
|
|
522
|
-
|
|
523
|
-
Both global and workspace-local files are loaded at collection registration
|
|
524
|
-
time. To pick up edits:
|
|
525
|
-
|
|
526
|
-
- **Global**: restart the server.
|
|
527
|
-
- **Workspace-local**: restart the server, OR re-register the workspace
|
|
528
|
-
with `POST /api/v1/init` (this rebuilds the collection's filter and
|
|
529
|
-
re-reads the file).
|
|
530
|
-
|
|
531
|
-
`POST /api/reload-config` does **not** re-read ignore files — only search
|
|
532
|
-
config and log level are reloaded by that endpoint.
|
|
533
|
-
|
|
534
|
-
Issues: #263 (global), #317 (workspace-local).
|
|
535
|
-
|
|
536
|
-
### Session Summarization
|
|
537
|
-
|
|
538
|
-
When `summarization.enabled: true`, nano-brain automatically generates structured markdown summaries of each harvested session using an OpenAI-compatible LLM provider. Summaries are:
|
|
539
|
-
|
|
540
|
-
- Stored in PostgreSQL under collection `session-summary` for semantic search via the standard query/vsearch API (PG is the source of truth)
|
|
541
|
-
- Optionally written to disk as Markdown files for Obsidian-compatible access (see [Disk persistence](#disk-persistence-obsidian-compatible) below)
|
|
542
|
-
- Idempotent — unchanged sessions are skipped; re-harvested sessions overwrite old summaries
|
|
543
|
-
|
|
544
|
-
#### Disk persistence (Obsidian-compatible)
|
|
545
|
-
|
|
546
|
-
By default, summaries are written to disk as Markdown files at the path configured in
|
|
547
|
-
`summarization.output_dir` (default: `~/.nano-brain/summaries`). The file layout is:
|
|
548
|
-
|
|
549
|
-
```
|
|
550
|
-
<output_dir>/<workspace_name>/<source>_<slugified-title>_<YYYY-MM-DD>.md
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
Files are byte-identical to the `documents.content` field in PostgreSQL — disk is a
|
|
554
|
-
derivative view, DB is source of truth. Disk write failures (permission denied, disk
|
|
555
|
-
full) log a WARN but do not roll back the DB transaction.
|
|
556
|
-
|
|
557
|
-
To opt out (DB-only persistence):
|
|
558
|
-
|
|
559
|
-
```yaml
|
|
560
|
-
summarization:
|
|
561
|
-
write_to_disk: false
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
To backfill historical summaries already in the DB:
|
|
565
|
-
|
|
566
|
-
```
|
|
567
|
-
nano-brain backfill-summaries
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
**Quick setup with ai-proxy:**
|
|
571
|
-
|
|
572
|
-
```yaml
|
|
573
|
-
summarization:
|
|
574
|
-
enabled: true
|
|
575
|
-
provider_url: "https://ai-proxy.example.com/v1"
|
|
576
|
-
api_key: "" # set NANO_BRAIN_SUMMARIZE_API_KEY instead
|
|
577
|
-
model: "claude-sonnet-4-5"
|
|
578
|
-
max_tokens: 8000
|
|
579
|
-
concurrency: 3
|
|
580
|
-
```
|
|
581
|
-
|
|
582
|
-
Or via environment variable:
|
|
583
|
-
|
|
584
|
-
```bash
|
|
585
|
-
export NANO_BRAIN_SUMMARIZE_API_KEY="sk-..."
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
Large sessions (100K+ tokens) are handled via map-reduce chunking — no session is too large.
|
|
589
|
-
|
|
590
|
-
### Query Preprocessing (Search Quality)
|
|
591
|
-
|
|
592
|
-
When `search.query_preprocessing.enabled: true`, nano-brain uses an LLM to preprocess search queries before execution — translating non-English queries to English, expanding with related terms, and detecting temporal intent. This improves retrieval quality for natural language queries.
|
|
344
|
+
---
|
|
593
345
|
|
|
594
|
-
|
|
595
|
-
search:
|
|
596
|
-
bm25_language: "english" # "english" (default) or "simple" (language-agnostic)
|
|
597
|
-
query_preprocessing:
|
|
598
|
-
enabled: false # set to true to activate
|
|
599
|
-
provider_url: "" # OpenAI-compatible endpoint (reuse summarization provider)
|
|
600
|
-
api_key: "" # or set NANO_BRAIN_SEARCH_PREPROCESS_API_KEY
|
|
601
|
-
model: "" # model for query preprocessing
|
|
602
|
-
max_latency_ms: 500 # timeout — falls back to raw query on timeout
|
|
603
|
-
|
|
604
|
-
watcher:
|
|
605
|
-
chunk_overlap: 600 # bytes of overlap between adjacent chunks (default: 600)
|
|
606
|
-
```
|
|
346
|
+
## Documentation
|
|
607
347
|
|
|
608
|
-
|
|
348
|
+
- [Getting Started](docs/GETTING_STARTED.md) — Step-by-step setup guide
|
|
349
|
+
- [Configuration](docs/CONFIGURATION.md) — All config options
|
|
350
|
+
- [REST API](docs/API.md) — HTTP endpoints
|
|
351
|
+
- [CLI Commands](docs/CLI.md) — Command reference
|
|
352
|
+
- [MCP Tools](docs/MCP.md) — Tool documentation
|
|
353
|
+
- [Architecture](docs/ARCHITECTURE.md) — System design
|
|
354
|
+
- [Changelog](CHANGELOG.md) — What's new
|
|
355
|
+
- [Roadmap](docs/ROADMAP.md) — What's planned
|
|
356
|
+
- [Feature Showcase](docs/FEATURES.md) — Visual examples
|
|
609
357
|
|
|
610
|
-
|
|
358
|
+
---
|
|
611
359
|
|
|
612
|
-
|
|
360
|
+
## Contributing
|
|
613
361
|
|
|
614
|
-
|
|
615
|
-
|----------|-------------|
|
|
616
|
-
| `NANO_BRAIN_CONFIG` | Path to YAML config file (12-factor; useful in Docker/k8s). Precedence: `--config` flag > `NANO_BRAIN_CONFIG` > `~/.nano-brain/config.yml`. Leading/trailing whitespace is stripped. If the env-pointed file does not exist, a `WARNING:` is printed to stderr and defaults are used (operator can spot typos). |
|
|
617
|
-
| `DATABASE_URL` | PostgreSQL connection string |
|
|
618
|
-
| `VOYAGE_API_KEY` | Voyage AI API key |
|
|
619
|
-
| `OPENCODE_DB_ROOT` | OpenCode per-project DB root directory (multi-DB mode) |
|
|
620
|
-
| `OPENCODE_DB_PATH` | OpenCode single SQLite database path |
|
|
621
|
-
| `OPENCODE_STORAGE_DIR` | OpenCode session directory (legacy) |
|
|
622
|
-
| `NANO_BRAIN_SUMMARIZE_API_KEY` | API key for the summarization LLM provider |
|
|
623
|
-
| `NANO_BRAIN_AUTH_ENABLED` | Enable Basic Auth + Bearer Token (`true`/`false`) |
|
|
624
|
-
| `NANO_BRAIN_AUTH_TOKENS` | Comma-separated bearer tokens |
|
|
625
|
-
| `NANO_BRAIN_*` | Override any config field (e.g., `NANO_BRAIN_SERVER_PORT=3100`) |
|
|
362
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
626
363
|
|
|
627
|
-
|
|
364
|
+
### Development Setup
|
|
628
365
|
|
|
629
366
|
```bash
|
|
630
|
-
#
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
-v /path/to/container-config.yml:/etc/nano-brain/config.yml:ro \
|
|
634
|
-
-p 3100:3100 \
|
|
635
|
-
nano-brain:latest
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
## REST API
|
|
639
|
-
|
|
640
|
-
### Public Endpoints
|
|
641
|
-
|
|
642
|
-
| Method | Path | Description |
|
|
643
|
-
|--------|------|-------------|
|
|
644
|
-
| GET | `/health` | Health check |
|
|
645
|
-
| GET | `/api/status` | Server status with version, uptime, workspace stats |
|
|
646
|
-
| POST | `/api/v1/init` | Register workspace |
|
|
647
|
-
| GET | `/api/v1/workspaces` | List all workspaces (with doc counts) |
|
|
648
|
-
| POST | `/api/v1/workspaces/resolve` | Resolve path → workspace hash + `registered` status (read-only) |
|
|
649
|
-
| DELETE | `/api/v1/workspaces/:hash` | Permanently delete a workspace + cascade docs/chunks/embeddings |
|
|
650
|
-
| GET | `/api/v1/wake-up` | Workspace briefing |
|
|
651
|
-
| POST | `/api/harvest` | Trigger session harvesting |
|
|
652
|
-
| POST | `/api/reload-config` | Hot-reload configuration |
|
|
653
|
-
|
|
654
|
-
### Workspace-Scoped Endpoints
|
|
655
|
-
|
|
656
|
-
Workspace is passed in the JSON body for POST, query param for GET.
|
|
657
|
-
|
|
658
|
-
| Method | Path | Description |
|
|
659
|
-
|--------|------|-------------|
|
|
660
|
-
| POST | `/api/v1/write` | Write/update document |
|
|
661
|
-
| POST | `/api/v1/embed` | Trigger embedding |
|
|
662
|
-
| POST | `/api/v1/search` | BM25 keyword search |
|
|
663
|
-
| POST | `/api/v1/vsearch` | Vector similarity search |
|
|
664
|
-
| POST | `/api/v1/query` | Hybrid search (BM25 + vector + RRF + recency) |
|
|
665
|
-
| POST | `/api/v1/collections` | Add collection |
|
|
666
|
-
| GET | `/api/v1/collections` | List collections |
|
|
667
|
-
| PUT | `/api/v1/collections/:name` | Rename collection |
|
|
668
|
-
| DELETE | `/api/v1/collections/:name` | Remove collection |
|
|
669
|
-
| GET | `/api/v1/tags` | List tags with counts |
|
|
670
|
-
| POST | `/api/v1/get` | Get single document by source_path or id |
|
|
671
|
-
| POST | `/api/v1/multi-get` | Batch fetch documents by paths or ids |
|
|
672
|
-
| POST | `/api/v1/reindex` | Queue reindex (202) |
|
|
673
|
-
| POST | `/api/v1/update` | Queue update (202) |
|
|
674
|
-
| POST | `/api/v1/summarize` | Trigger LLM summarization of harvested sessions |
|
|
675
|
-
| POST | `/api/v1/wake-up` | Workspace briefing with session_dir |
|
|
676
|
-
|
|
677
|
-
### MCP Endpoints
|
|
678
|
-
|
|
679
|
-
| Method | Path | Description |
|
|
680
|
-
|--------|------|-------------|
|
|
681
|
-
| GET/POST | `/mcp` | Streamable HTTP (MCP 2025-03-26) |
|
|
682
|
-
| GET/POST | `/sse` | SSE transport (legacy) |
|
|
683
|
-
|
|
684
|
-
## CLI Commands
|
|
685
|
-
|
|
686
|
-
| Command | Description |
|
|
687
|
-
|---------|-------------|
|
|
688
|
-
| `nano-brain` (no args) | Start HTTP server (default: port 3100) |
|
|
689
|
-
| `nano-brain init --root=<path>` | Register workspace |
|
|
690
|
-
| `nano-brain workspaces list` | List registered workspaces with doc counts |
|
|
691
|
-
| `nano-brain workspaces current [--path=<p>] [--export\|--json\|--check]` | Resolve current/path workspace hash. `--export` prints `export NANO_BRAIN_WORKSPACE=<hash>` for `eval`; `--check` exits 2 if not registered |
|
|
692
|
-
| `nano-brain workspaces remove --workspace=<hash> [--dry-run\|--force]` | Permanently delete a workspace + all its documents/chunks/embeddings |
|
|
693
|
-
| `nano-brain write` | Write document via CLI |
|
|
694
|
-
| `nano-brain query [--scope=all] [--tags=t1,t2]` | Hybrid search (BM25 + vector + RRF + recency) |
|
|
695
|
-
| `nano-brain search [--scope=all] [--tags=t1,t2]` | BM25 keyword search |
|
|
696
|
-
| `nano-brain vsearch [--scope=all] [--tags=t1,t2]` | Vector similarity search |
|
|
697
|
-
| `nano-brain wake-up --workspace=<hash>` | Workspace briefing (collections, stats, recent memories) |
|
|
698
|
-
| `nano-brain get <source_path\|uuid> --workspace=<hash>` | Fetch a single document by source_path or UUID |
|
|
699
|
-
| `nano-brain tags --workspace=<hash>` | List all tags with document counts |
|
|
700
|
-
| `nano-brain multi-get --workspace=<hash> --paths=p1,p2` | Fetch multiple documents in one round-trip |
|
|
701
|
-
| `nano-brain collection add\|remove\|list` | Manage collections |
|
|
702
|
-
| `nano-brain harvest` | Trigger session harvesting |
|
|
703
|
-
| `nano-brain backfill-summaries [--dry-run] [--workspace=] [--since=]` | Export existing DB summaries to disk (.md files for Obsidian etc.) |
|
|
704
|
-
| `nano-brain cleanup-stale-raw [--dry-run]` | Delete pre-#192 raw OpenCode session docs superseded by summaries |
|
|
705
|
-
| `nano-brain cleanup-orphan-workspaces [--dry-run]` | Delete documents/chunks under workspace_hash values not registered in `workspaces`. Run BEFORE migration 00011 (issue #238). |
|
|
706
|
-
| `nano-brain bench generate\|run\|compare\|stress` | Benchmarking suite |
|
|
707
|
-
| `nano-brain db:migrate` | Run pending goose migrations |
|
|
708
|
-
| `nano-brain db:migrate --from-v1 <path>` | Import V1 SQLite data |
|
|
709
|
-
| `nano-brain logs [-n 50] [-f]` | Tail log file |
|
|
710
|
-
| `nano-brain docker start\|stop\|status` | Docker compose management |
|
|
711
|
-
| `nano-brain status [--json]` | Server status |
|
|
712
|
-
| `nano-brain auth hash <password>` | Generate bcrypt password hash for config |
|
|
713
|
-
| `nano-brain auth token` | Generate random bearer token (`nbt_`-prefixed) |
|
|
714
|
-
| `nano-brain doctor [--json]` | Check prerequisites (config, PostgreSQL, pgvector, Ollama, model) |
|
|
715
|
-
|
|
716
|
-
## MCP Tools
|
|
717
|
-
|
|
718
|
-
nano-brain exposes 14 tools via MCP (Model Context Protocol):
|
|
367
|
+
# Clone the repo
|
|
368
|
+
git clone https://github.com/nano-step/nano-brain.git
|
|
369
|
+
cd nano-brain
|
|
719
370
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
| `memory_query` | Hybrid search (BM25 + vector + RRF + recency); supports time-range filters (`created_after`, `created_before`, `updated_after`, `updated_before`) |
|
|
723
|
-
| `memory_search` | BM25 keyword search; supports time-range filters (`created_after`, `created_before`, `updated_after`, `updated_before`) |
|
|
724
|
-
| `memory_vsearch` | Vector similarity search; supports time-range filters (`created_after`, `created_before`, `updated_after`, `updated_before`) |
|
|
725
|
-
| `memory_get` | Get document by path |
|
|
726
|
-
| `memory_write` | Write/update document |
|
|
727
|
-
| `memory_tags` | List tags with counts |
|
|
728
|
-
| `memory_status` | Server and embedding status |
|
|
729
|
-
| `memory_update` | Trigger re-embedding |
|
|
730
|
-
| `memory_wake_up` | Workspace briefing |
|
|
731
|
-
| `memory_graph` | Knowledge graph view (module → function → dep) |
|
|
732
|
-
| `memory_trace` | Call chain trace from entry point |
|
|
733
|
-
| `memory_impact` | Cross-file change impact analysis |
|
|
734
|
-
| `memory_symbols` | Symbol search (functions, types, constants) |
|
|
735
|
-
| `memory_workspaces_resolve` | Resolve filesystem path → workspace hash + registered status (read-only) |
|
|
371
|
+
# Build
|
|
372
|
+
CGO_ENABLED=0 go build -o nano-brain ./cmd/nano-brain
|
|
736
373
|
|
|
737
|
-
|
|
374
|
+
# Run tests
|
|
375
|
+
go test -race -short ./...
|
|
738
376
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
"mcp": {
|
|
742
|
-
"nano-brain": {
|
|
743
|
-
"type": "remote",
|
|
744
|
-
"url": "http://localhost:3100/mcp"
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
}
|
|
377
|
+
# Run integration tests (requires PostgreSQL)
|
|
378
|
+
go test -race -tags=integration ./...
|
|
748
379
|
```
|
|
749
380
|
|
|
750
|
-
|
|
381
|
+
### Project Structure
|
|
751
382
|
|
|
752
383
|
```
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
384
|
+
nano-brain/
|
|
385
|
+
├── cmd/nano-brain/ # CLI dispatcher + server startup
|
|
386
|
+
├── internal/
|
|
387
|
+
│ ├── config/ # Configuration management
|
|
388
|
+
│ ├── server/ # HTTP server + handlers
|
|
389
|
+
│ ├── storage/ # PostgreSQL + sqlc
|
|
390
|
+
│ ├── search/ # Hybrid search pipeline
|
|
391
|
+
│ ├── embed/ # Embedding queue
|
|
392
|
+
│ ├── watcher/ # File system watcher
|
|
393
|
+
│ ├── harvest/ # Session harvesting
|
|
394
|
+
│ ├── mcp/ # MCP protocol tools
|
|
395
|
+
│ ├── graph/ # Code intelligence
|
|
396
|
+
│ └── ...
|
|
397
|
+
├── migrations/ # Database migrations
|
|
398
|
+
└── benchmarks/ # Performance benchmarks
|
|
756
399
|
```
|
|
757
400
|
|
|
758
|
-
|
|
759
|
-
- **Vector:** pgvector HNSW index with cosine distance
|
|
760
|
-
- **RRF:** Reciprocal Rank Fusion (k=60), scores normalized to [0,1]
|
|
761
|
-
- **Recency:** exponential half-life decay (default 180 days, weight 0.3)
|
|
762
|
-
|
|
763
|
-
## Architecture
|
|
764
|
-
|
|
765
|
-
- 15 internal packages: config, server, handlers, storage, sqlc, embed, search, watcher, harvest, mcp, migrate, telemetry, health, bench
|
|
766
|
-
- 7 goose SQL migrations (embedded)
|
|
767
|
-
- Constructor injection (no DI framework)
|
|
768
|
-
- errgroup + context for goroutine lifecycle
|
|
769
|
-
- Echo v4 middleware: workspace extraction, content-type enforcement, version header
|
|
770
|
-
|
|
771
|
-
## Ruby / Rails Support
|
|
772
|
-
|
|
773
|
-
nano-brain supports Ruby and Ruby on Rails code intelligence, including execution flow visualization and control-flow graph (CFG) extraction.
|
|
774
|
-
|
|
775
|
-
### Supported file types
|
|
776
|
-
|
|
777
|
-
- `.rb`
|
|
778
|
-
|
|
779
|
-
### What's extracted
|
|
780
|
-
|
|
781
|
-
- **Rails routes:** `resources`, `get`/`post`/`patch`/`put`/`delete`, `namespace`, `scope`, `mount`, `root`, `devise_for` — each generates an edge from the HTTP entry point (`METHOD /path`) to the corresponding controller action (`ControllerName#action`).
|
|
782
|
-
- **Control-flow graph:** `if`/`else`, loops, `begin`/`rescue` blocks, method definitions, and same-file method calls.
|
|
783
|
-
- **Flow diagrams:** Mermaid flowcharts and sequence diagrams for Rails request cycles.
|
|
784
|
-
|
|
785
|
-
### Example: Flow diagram for a Rails controller action
|
|
786
|
-
|
|
787
|
-
Given a `UsersController` with a `create` action that creates a user and sends a welcome email, `memory_flow` produces a flowchart:
|
|
788
|
-
|
|
789
|
-
```mermaid
|
|
790
|
-
flowchart LR
|
|
791
|
-
POST_/users["POST /users"]
|
|
792
|
-
POST_/users --> UsersController#create
|
|
793
|
-
UsersController#create --> User.create
|
|
794
|
-
UsersController#create --> Mailer.welcome
|
|
795
|
-
```
|
|
796
|
-
|
|
797
|
-
### Example: Sequence diagram for a Rails request
|
|
798
|
-
|
|
799
|
-
With `format: "sequence"`, the same request produces a sequence diagram:
|
|
800
|
-
|
|
801
|
-
```mermaid
|
|
802
|
-
sequenceDiagram
|
|
803
|
-
participant Client
|
|
804
|
-
participant Router
|
|
805
|
-
participant UsersController
|
|
806
|
-
participant User
|
|
807
|
-
participant Mailer
|
|
808
|
-
Client->>Router: POST /users
|
|
809
|
-
Router->>UsersController: create
|
|
810
|
-
UsersController->>User: create(params)
|
|
811
|
-
User-->>UsersController: user
|
|
812
|
-
UsersController->>Mailer: welcome(user)
|
|
813
|
-
Mailer-->>UsersController: email
|
|
814
|
-
UsersController-->>Client: 201 Created
|
|
815
|
-
```
|
|
816
|
-
|
|
817
|
-
### Known limitations (v1)
|
|
818
|
-
|
|
819
|
-
- **Same-file calls only:** Only method calls within the same file are resolved; cross-file caller/callee edges are not yet extracted.
|
|
820
|
-
- **No `before_action` / `after_action`:** Callback chains are not followed or visualized.
|
|
821
|
-
- **No ActiveRecord dynamic methods:** Calls like `find_by_email` or `where_active` are treated as generic method calls, not resolved to AR query targets.
|
|
822
|
-
- **No metaprogramming:** Methods defined via `define_method`, `method_missing`, or `class_eval` are not captured.
|
|
401
|
+
---
|
|
823
402
|
|
|
824
|
-
##
|
|
403
|
+
## Community
|
|
825
404
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
405
|
+
- [GitHub Discussions](https://github.com/nano-step/nano-brain/discussions) — Ask questions, share ideas
|
|
406
|
+
- [Discord](https://discord.gg/nano-brain) — Real-time chat
|
|
407
|
+
- [Twitter](https://twitter.com/nano_brain) — Updates and announcements
|
|
829
408
|
|
|
830
|
-
|
|
831
|
-
# Uses content-addressed SHA-256 hashing
|
|
832
|
-
# Pure Go SQLite reader (modernc.org/sqlite, no CGO)
|
|
833
|
-
```
|
|
409
|
+
---
|
|
834
410
|
|
|
835
|
-
##
|
|
411
|
+
## License
|
|
836
412
|
|
|
837
|
-
|
|
838
|
-
- **PostgreSQL 17** — relational storage + full-text search (tsvector/tsquery)
|
|
839
|
-
- **pgvector 0.8.2** — HNSW vector indexing
|
|
840
|
-
- **Echo v4** — HTTP framework
|
|
841
|
-
- **sqlc** — type-safe SQL code generation
|
|
842
|
-
- **goose v3** — database migrations
|
|
843
|
-
- **zerolog** — structured JSON logging
|
|
844
|
-
- **koanf** — YAML + env configuration
|
|
845
|
-
- **fsnotify** — file system watching
|
|
846
|
-
- **modernc.org/sqlite** — V1 migration reader (pure Go)
|
|
413
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
847
414
|
|
|
848
|
-
|
|
415
|
+
---
|
|
849
416
|
|
|
850
|
-
|
|
417
|
+
## Acknowledgments
|
|
418
|
+
|
|
419
|
+
Built with:
|
|
420
|
+
- [Go](https://go.dev/) — Fast, statically typed language
|
|
421
|
+
- [PostgreSQL](https://www.postgresql.org/) — The world's most advanced open source database
|
|
422
|
+
- [pgvector](https://github.com/pgvector/pgvector) — Open-source vector similarity search
|
|
423
|
+
- [Echo](https://echo.labstack.com/) — High performance, extensible, minimalist Go web framework
|
|
424
|
+
- [sqlc](https://sqlc.dev/) — Generate type-safe code from SQL
|
|
425
|
+
- [goose](https://github.com/pressly/goose) — Database migration tool
|
|
426
|
+
- [zerolog](https://github.com/rs/zerolog) — Zero allocation JSON logger
|
|
427
|
+
- [koanf](https://github.com/knadh/koanf) — Configuration manager
|
|
428
|
+
- [fsnotify](https://github.com/fsnotify/fsnotify) — Cross-platform file system notifications
|