aiwcli 0.12.2 → 0.12.3
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/dist/templates/_shared/.claude/commands/handoff.md +44 -78
- package/dist/templates/_shared/hooks-ts/session_end.ts +16 -11
- package/dist/templates/_shared/hooks-ts/session_start.ts +4 -1
- package/dist/templates/_shared/lib-ts/base/inference.ts +72 -23
- package/dist/templates/_shared/lib-ts/base/state-io.ts +12 -7
- package/dist/templates/_shared/lib-ts/context/context-store.ts +35 -74
- package/dist/templates/_shared/lib-ts/types.ts +64 -63
- package/dist/templates/_shared/scripts/resolve_context.ts +14 -5
- package/dist/templates/_shared/scripts/resume_handoff.ts +16 -13
- package/dist/templates/_shared/scripts/save_handoff.ts +30 -31
- package/dist/templates/_shared/workflows/handoff.md +28 -6
- package/dist/templates/cc-native/.claude/commands/rlm/ask.md +136 -0
- package/dist/templates/cc-native/.claude/commands/rlm/index.md +21 -0
- package/dist/templates/cc-native/.claude/commands/rlm/overview.md +56 -0
- package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +4 -4
- package/dist/templates/cc-native/_cc-native/{plan-review.config.json → cc-native.config.json} +12 -0
- package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/config.ts +3 -3
- package/dist/templates/cc-native/_cc-native/lib-ts/review-pipeline.ts +26 -4
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/CLAUDE.md +480 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/embedding-indexer.ts +287 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/hyde.ts +148 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/index.ts +54 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/logger.ts +58 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/ollama-client.ts +208 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/retrieval-pipeline.ts +460 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/transcript-indexer.ts +447 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/transcript-loader.ts +280 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/transcript-searcher.ts +274 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/types.ts +201 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/vector-store.ts +278 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +2 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
# RLM — Retrieval-Augmented Learning Memory
|
|
2
|
+
|
|
3
|
+
## What is RLM?
|
|
4
|
+
|
|
5
|
+
A two-tier retrieval system that lets you ask questions about past Claude Code sessions across all projects. Automatically indexes session transcripts and provides both keyword and semantic search.
|
|
6
|
+
|
|
7
|
+
RLM stands for "Retrieval-augmented Learning Memory" — inspired by RAG (Retrieval-Augmented Generation) patterns but adapted for conversational session history. It turns your entire Claude Code session history into a searchable, queryable knowledge base.
|
|
8
|
+
|
|
9
|
+
## User Guide
|
|
10
|
+
|
|
11
|
+
### Commands
|
|
12
|
+
|
|
13
|
+
**rlm:ask** — Answer a question about past work
|
|
14
|
+
- Auto-builds indexes on first use (one-time setup)
|
|
15
|
+
- Uses semantic search when Ollama + vectors available
|
|
16
|
+
- Falls back to keyword search otherwise
|
|
17
|
+
- Example: `/rlm:ask "How did we implement the plan review system?"`
|
|
18
|
+
|
|
19
|
+
**rlm:overview** — Get a timeline summary
|
|
20
|
+
- Group sessions by date/project/theme
|
|
21
|
+
- Example: `/rlm:overview "hook development this week"`
|
|
22
|
+
|
|
23
|
+
**rlm:index** — Force-rebuild indexes
|
|
24
|
+
- Manual rebuild mechanism when auto-indexing fails
|
|
25
|
+
- Accepts optional flags: `--limit=N`, `--project=<name>`
|
|
26
|
+
- Example: `/rlm:index` or `/rlm:index --project=bridge`
|
|
27
|
+
|
|
28
|
+
### First-Time Setup
|
|
29
|
+
|
|
30
|
+
No manual setup required. On first use, `rlm:ask` will:
|
|
31
|
+
1. **Auto-build JSON indexes** (takes 10-30s per 100 sessions)
|
|
32
|
+
2. **Auto-detect Ollama** and use semantic search if available
|
|
33
|
+
3. **Auto-pull model** if Ollama is running but `nomic-embed-text` is missing
|
|
34
|
+
|
|
35
|
+
The first run might take 30-60 seconds as it builds indexes. Subsequent runs are fast (sub-second for keyword search, 2-5s for semantic search).
|
|
36
|
+
|
|
37
|
+
### When to Use What
|
|
38
|
+
|
|
39
|
+
| Use Case | Command |
|
|
40
|
+
|----------|---------|
|
|
41
|
+
| "How did we solve X?" | `rlm:ask` |
|
|
42
|
+
| "What did we work on this week?" | `rlm:overview` |
|
|
43
|
+
| "Find sessions about Y" | `rlm:ask` (returns sources table) |
|
|
44
|
+
| "Indexes are stale/broken" | `rlm:index` (force rebuild) |
|
|
45
|
+
|
|
46
|
+
### Search Quality: Keyword vs Semantic
|
|
47
|
+
|
|
48
|
+
**Keyword Search** (always available, fast):
|
|
49
|
+
- Uses weighted scoring: summary (3.0x), keywords (2.0x), files touched (1.5x), tool calls (1.0x)
|
|
50
|
+
- Best for: Exact terms, file names, command names, specific error messages
|
|
51
|
+
- Example: "transcript-indexer.ts" or "TaskCreate tool"
|
|
52
|
+
|
|
53
|
+
**Semantic Search** (requires Ollama, higher quality):
|
|
54
|
+
- Uses vector embeddings with KNN similarity
|
|
55
|
+
- Best for: Conceptual queries, "how did we..." questions, approximate matches
|
|
56
|
+
- Example: "error handling patterns" or "plan approval workflow"
|
|
57
|
+
|
|
58
|
+
The system automatically picks the best available method. If Ollama isn't running, it gracefully falls back to keyword search.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Architecture Overview (For Maintainers)
|
|
63
|
+
|
|
64
|
+
### Two-Tier Pipeline
|
|
65
|
+
|
|
66
|
+
**Tier 1: JSON Indexes (Always Available)**
|
|
67
|
+
- Fast keyword-based search
|
|
68
|
+
- Metadata extraction: summary, keywords, files touched, tool calls
|
|
69
|
+
- Scoring with weighted factors (summary: 3.0, keywords: 2.0, files: 1.5, tools: 1.0)
|
|
70
|
+
- Storage: `~/.claude/rlm-index/{project}/{session}.index.json`
|
|
71
|
+
- Builder: `transcript-indexer.ts`
|
|
72
|
+
- Searcher: `transcript-searcher.ts`
|
|
73
|
+
|
|
74
|
+
**Tier 2: Vector Embeddings (Requires Ollama)**
|
|
75
|
+
- Semantic similarity search using KNN
|
|
76
|
+
- HyDE query expansion (optional, 20-45% recall improvement)
|
|
77
|
+
- 6-stage retrieval pipeline: embed → search → summarize → rank → synthesize
|
|
78
|
+
- Storage: `~/.claude/rlm-vectors.db` (SQLite + sqlite-vec)
|
|
79
|
+
- Builder: `embedding-indexer.ts`
|
|
80
|
+
- Pipeline: `retrieval-pipeline.ts`
|
|
81
|
+
|
|
82
|
+
### HyDE (Hypothetical Document Embeddings)
|
|
83
|
+
|
|
84
|
+
**What:** Generates 5 hypothetical responses to the query, embeds them, averages the vectors.
|
|
85
|
+
|
|
86
|
+
**Why:** Improves recall by 20-45% (research-backed). The technique addresses the embedding space mismatch between short queries and long documents by generating synthetic document-like content from the query.
|
|
87
|
+
|
|
88
|
+
**Status:** Opt-in via `cc-native.config.json` (`rlm.hyde.enabled: true`).
|
|
89
|
+
|
|
90
|
+
**Cost:** Uses local Ollama (free) or Claude API (paid fallback).
|
|
91
|
+
|
|
92
|
+
**How It Works:**
|
|
93
|
+
1. User asks: "How did we implement hooks?"
|
|
94
|
+
2. HyDE generates 5 hypothetical answers (e.g., "We implemented hooks using TypeScript...")
|
|
95
|
+
3. Each hypothetical is embedded → 5 vectors
|
|
96
|
+
4. Vectors are averaged → single query vector
|
|
97
|
+
5. KNN search uses this averaged vector (closer to document space than raw query)
|
|
98
|
+
|
|
99
|
+
Configuration in `cc-native.config.json`:
|
|
100
|
+
```json
|
|
101
|
+
"rlm": {
|
|
102
|
+
"hyde": {
|
|
103
|
+
"enabled": false, // Opt-in
|
|
104
|
+
"provider": "ollama", // "ollama" or "claude"
|
|
105
|
+
"ollamaModel": "qwen2.5:1.5b", // Fast model
|
|
106
|
+
"numResponses": 5,
|
|
107
|
+
"fallbackToQuery": true // Graceful degradation
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Code Organization
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
.aiwcli/_cc-native/lib-ts/rlm/
|
|
116
|
+
├── types.ts # All types + constants
|
|
117
|
+
├── transcript-indexer.ts # Build JSON indexes
|
|
118
|
+
├── transcript-searcher.ts # Keyword search
|
|
119
|
+
├── transcript-loader.ts # Load transcript segments
|
|
120
|
+
├── embedding-indexer.ts # Build vector index
|
|
121
|
+
├── vector-store.ts # SQLite + sqlite-vec KNN
|
|
122
|
+
├── retrieval-pipeline.ts # 6-stage semantic pipeline
|
|
123
|
+
├── ollama-client.ts # Ollama API wrapper
|
|
124
|
+
├── hyde.ts # HyDE query expansion
|
|
125
|
+
├── logger.ts # RLM-specific logging
|
|
126
|
+
└── CLAUDE.md # This file
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Data Flow
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
User Query
|
|
133
|
+
↓
|
|
134
|
+
rlm:ask command
|
|
135
|
+
↓
|
|
136
|
+
┌─ Auto-index check
|
|
137
|
+
│ └─ transcript-indexer.ts (if needed)
|
|
138
|
+
├─ Vector DB check
|
|
139
|
+
│ ├─ YES + Ollama running → retrieval-pipeline.ts
|
|
140
|
+
│ │ ├─ hyde.ts (optional query expansion)
|
|
141
|
+
│ │ ├─ ollama-client.ts (embed query)
|
|
142
|
+
│ │ ├─ vector-store.ts (KNN search)
|
|
143
|
+
│ │ ├─ transcript-loader.ts (load segments)
|
|
144
|
+
│ │ ├─ Parallel summarization (Haiku)
|
|
145
|
+
│ │ ├─ AI ranking (Sonnet)
|
|
146
|
+
│ │ └─ Synthesis (Sonnet)
|
|
147
|
+
│ └─ NO Ollama → transcript-searcher.ts
|
|
148
|
+
│ ├─ Load indexes
|
|
149
|
+
│ ├─ Score against query
|
|
150
|
+
│ └─ Return top N
|
|
151
|
+
├─ transcript-loader.ts (load segments)
|
|
152
|
+
├─ Parallel sub-agent analysis (1-5 agents)
|
|
153
|
+
└─ Final synthesis with citations
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Index Schema Version
|
|
157
|
+
|
|
158
|
+
Current: `CURRENT_SCHEMA_VERSION = 1` (in `types.ts`)
|
|
159
|
+
|
|
160
|
+
When schema changes:
|
|
161
|
+
1. Bump version constant
|
|
162
|
+
2. Searcher automatically skips old indexes
|
|
163
|
+
3. Indexer rebuilds on next run
|
|
164
|
+
4. No manual migration needed
|
|
165
|
+
|
|
166
|
+
The schema version is embedded in each `.index.json` file. The searcher checks this version and ignores indexes from older schema versions, forcing a rebuild.
|
|
167
|
+
|
|
168
|
+
### JSON Index Structure
|
|
169
|
+
|
|
170
|
+
Each session gets a `.index.json` file with this structure:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
interface TranscriptIndex {
|
|
174
|
+
schema_version: number; // Current: 1
|
|
175
|
+
session_id: string; // UUID
|
|
176
|
+
project: string; // Project name
|
|
177
|
+
source_path: string; // Path to .jsonl transcript
|
|
178
|
+
created_at: string; // ISO timestamp
|
|
179
|
+
summary: string; // AI-generated summary (1-2 sentences)
|
|
180
|
+
keywords: string[]; // Extracted keywords (5-10 terms)
|
|
181
|
+
files_touched: string[]; // File paths mentioned in session
|
|
182
|
+
tool_calls: string[]; // Tool names used (Read, Edit, Bash, etc.)
|
|
183
|
+
segments: Array<{ // Text chunks with line ranges
|
|
184
|
+
text: string;
|
|
185
|
+
lines: [number, number];
|
|
186
|
+
}>;
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Vector Index Structure
|
|
191
|
+
|
|
192
|
+
SQLite database (`~/.claude/rlm-vectors.db`) with two tables:
|
|
193
|
+
|
|
194
|
+
**embeddings table:**
|
|
195
|
+
```sql
|
|
196
|
+
CREATE TABLE embeddings (
|
|
197
|
+
id INTEGER PRIMARY KEY,
|
|
198
|
+
session_id TEXT NOT NULL,
|
|
199
|
+
project TEXT NOT NULL,
|
|
200
|
+
source_path TEXT NOT NULL,
|
|
201
|
+
segment_index INTEGER NOT NULL,
|
|
202
|
+
text TEXT NOT NULL,
|
|
203
|
+
embedding BLOB NOT NULL, -- Float32Array serialized
|
|
204
|
+
lines_start INTEGER,
|
|
205
|
+
lines_end INTEGER
|
|
206
|
+
);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**metadata table:**
|
|
210
|
+
```sql
|
|
211
|
+
CREATE TABLE metadata (
|
|
212
|
+
session_id TEXT PRIMARY KEY,
|
|
213
|
+
project TEXT NOT NULL,
|
|
214
|
+
summary TEXT,
|
|
215
|
+
indexed_at TEXT NOT NULL
|
|
216
|
+
);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The `sqlite-vec` extension provides KNN search via `vec_distance_cosine(embedding, query_vector)`.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Troubleshooting
|
|
224
|
+
|
|
225
|
+
### "No indexes found"
|
|
226
|
+
- **Cause:** First run, or indexes deleted
|
|
227
|
+
- **Fix:** Auto-builds on next `rlm:ask` run (10-30s delay)
|
|
228
|
+
- **Manual fix:** `/rlm:index`
|
|
229
|
+
|
|
230
|
+
### "Vector search unavailable"
|
|
231
|
+
- **Cause:** Ollama not running or vector DB missing
|
|
232
|
+
- **Impact:** Falls back to keyword search (still works, just less semantic)
|
|
233
|
+
- **Fix:** Start Ollama (`ollama serve`), or let auto-indexing handle it on next semantic query
|
|
234
|
+
|
|
235
|
+
### "Model not found: nomic-embed-text"
|
|
236
|
+
- **Cause:** Ollama running but model not installed
|
|
237
|
+
- **Fix:** Auto-pulls on next `rlm:ask` run (~400MB, 1-2 minutes), or manual: `ollama pull nomic-embed-text`
|
|
238
|
+
|
|
239
|
+
### "HyDE disabled" (in logs)
|
|
240
|
+
- **Cause:** `rlm.hyde.enabled: false` in config
|
|
241
|
+
- **Impact:** Direct query embedding (still works, slightly lower recall ~20%)
|
|
242
|
+
- **Fix:** Enable in `cc-native.config.json` if you want 20-45% recall improvement
|
|
243
|
+
|
|
244
|
+
### Stale indexes
|
|
245
|
+
- **Cause:** New sessions not indexed
|
|
246
|
+
- **Fix:** Indexer checks source `.jsonl` mtime, auto-rebuilds if newer
|
|
247
|
+
- **Manual fix:** `/rlm:index` to force full rebuild
|
|
248
|
+
|
|
249
|
+
### SQLite errors
|
|
250
|
+
- **Cause:** Corrupted `rlm-vectors.db`
|
|
251
|
+
- **Fix:** Delete `~/.claude/rlm-vectors.db`, rebuild via `embedding-indexer.ts --batch`
|
|
252
|
+
|
|
253
|
+
### Empty search results
|
|
254
|
+
- **Possible causes:**
|
|
255
|
+
1. Query too specific (try broader terms)
|
|
256
|
+
2. Sessions not indexed yet (check `~/.claude/rlm-index/` exists)
|
|
257
|
+
3. Searching for recent work not yet persisted (Claude Code writes transcripts on session end)
|
|
258
|
+
- **Fix:** Try different query terms, or run `/rlm:index` to ensure all sessions indexed
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Performance Tuning
|
|
263
|
+
|
|
264
|
+
### Keyword Search (Fast)
|
|
265
|
+
- **Average:** 50-200ms for 100 sessions
|
|
266
|
+
- **No dependencies** (always available)
|
|
267
|
+
- **Use for:** Quick session lookups, file/command searches, exact term matches
|
|
268
|
+
|
|
269
|
+
### Vector Search (Slower, Higher Quality)
|
|
270
|
+
- **Average:** 2-5s end-to-end (with HyDE: +1-3s)
|
|
271
|
+
- **Requires:** Ollama + nomic-embed-text model
|
|
272
|
+
- **Use for:** Semantic questions, "how did we...", "why did we...", conceptual queries
|
|
273
|
+
|
|
274
|
+
### HyDE (Optional Quality Boost)
|
|
275
|
+
- **Adds:** 1-3s (5 hypothetical responses generated)
|
|
276
|
+
- **Improves recall:** 20-45% (research-backed)
|
|
277
|
+
- **Recommended for:** Complex queries, abstract questions, when precision matters
|
|
278
|
+
- **Disable for:** Speed-critical workflows, simple lookups
|
|
279
|
+
|
|
280
|
+
### Parallel Agent Count
|
|
281
|
+
|
|
282
|
+
The `rlm:ask` command spawns 1-5 parallel sub-agents based on search result count:
|
|
283
|
+
- 1 result → 1 agent (minimal latency)
|
|
284
|
+
- 3 results → 3 agents (balanced)
|
|
285
|
+
- 10 results → 5 agents capped (prevents over-parallelization)
|
|
286
|
+
|
|
287
|
+
This dynamic scaling ensures:
|
|
288
|
+
- Fast response for focused queries (1-2 results)
|
|
289
|
+
- Comprehensive analysis for broad queries (5+ results)
|
|
290
|
+
- Bounded latency (never more than 5 concurrent agents)
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Configuration Reference
|
|
295
|
+
|
|
296
|
+
See `cc-native.config.json`:
|
|
297
|
+
|
|
298
|
+
```json
|
|
299
|
+
"rlm": {
|
|
300
|
+
"hyde": {
|
|
301
|
+
"enabled": false, // Opt-in for HyDE (20-45% recall boost)
|
|
302
|
+
"provider": "ollama", // "ollama" (local, free) or "claude" (API, paid)
|
|
303
|
+
"ollamaModel": "qwen2.5:1.5b", // Model for hypothetical generation
|
|
304
|
+
"numResponses": 5, // Hypotheticals to generate (more = better but slower)
|
|
305
|
+
"maxTokens": 200, // Per response (keep short for speed)
|
|
306
|
+
"timeoutMs": 10000, // Per response (fail fast on hung requests)
|
|
307
|
+
"fallbackToQuery": true, // Degrade gracefully on HyDE failure
|
|
308
|
+
"fallbackToClaude": false // Don't burn API credits on fallback (default)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Configuration Trade-offs
|
|
314
|
+
|
|
315
|
+
| Setting | Value | Impact |
|
|
316
|
+
|---------|-------|--------|
|
|
317
|
+
| `hyde.enabled` | `true` | +20-45% recall, +1-3s latency |
|
|
318
|
+
| `hyde.enabled` | `false` | Baseline recall, faster queries |
|
|
319
|
+
| `hyde.numResponses` | `3` | Faster but lower recall boost (~15-25%) |
|
|
320
|
+
| `hyde.numResponses` | `7` | Higher recall boost (~30-50%) but +2s latency |
|
|
321
|
+
| `hyde.provider` | `ollama` | Free, requires local Ollama, ~2-3s for 5 responses |
|
|
322
|
+
| `hyde.provider` | `claude` | Paid, always available, ~1-2s for 5 responses |
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Implementation Details
|
|
327
|
+
|
|
328
|
+
### Auto-Indexing Logic
|
|
329
|
+
|
|
330
|
+
The `rlm:ask` command checks for indexes before search:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
INDEX_DIR="$HOME/.claude/rlm-index"
|
|
334
|
+
if [ ! -d "$INDEX_DIR" ] || [ -z "$(ls -A $INDEX_DIR 2>/dev/null)" ]; then
|
|
335
|
+
# First run: build indexes
|
|
336
|
+
bun transcript-indexer.ts --batch
|
|
337
|
+
fi
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The indexer is **idempotent**:
|
|
341
|
+
- Checks source `.jsonl` mtime vs index mtime
|
|
342
|
+
- Skips up-to-date files
|
|
343
|
+
- Only indexes new/modified sessions
|
|
344
|
+
|
|
345
|
+
This means running `/rlm:index` multiple times is safe and fast (rebuilds only what changed).
|
|
346
|
+
|
|
347
|
+
### Auto-Model-Pull Logic
|
|
348
|
+
|
|
349
|
+
The `rlm:ask` command checks for the embedding model:
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then
|
|
353
|
+
# Ollama running
|
|
354
|
+
if ! ollama list | grep -q "nomic-embed-text"; then
|
|
355
|
+
# Model missing: auto-pull
|
|
356
|
+
ollama pull nomic-embed-text
|
|
357
|
+
fi
|
|
358
|
+
fi
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
The `ollama pull` command:
|
|
362
|
+
- Downloads ~400MB model
|
|
363
|
+
- Shows native Ollama progress bar
|
|
364
|
+
- Blocks until complete (1-2 minutes on typical connection)
|
|
365
|
+
- On failure, falls back to keyword search with warning
|
|
366
|
+
|
|
367
|
+
### Graceful Degradation Path
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
rlm:ask query
|
|
371
|
+
↓
|
|
372
|
+
JSON indexes exist? ────NO──→ Auto-build → Continue
|
|
373
|
+
↓ YES
|
|
374
|
+
Vector DB exists? ────NO──→ transcript-searcher.ts (keyword)
|
|
375
|
+
↓ YES
|
|
376
|
+
Ollama running? ────NO──→ transcript-searcher.ts (keyword)
|
|
377
|
+
↓ YES
|
|
378
|
+
Model present? ────NO──→ Auto-pull → Continue or fallback
|
|
379
|
+
↓ YES
|
|
380
|
+
retrieval-pipeline.ts (semantic)
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Every failure point has a fallback. The system never errors out due to missing infrastructure—it degrades to the best available method.
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Future Enhancements
|
|
388
|
+
|
|
389
|
+
### Short-Term (Next 1-2 Versions)
|
|
390
|
+
- **Auto-embed on session end** — Build vector index incrementally via `SessionEnd` hook
|
|
391
|
+
- **Cross-project search** — Filter by multiple projects: `--projects=aiwcli,bridge-app`
|
|
392
|
+
- **Date range filtering** — Native support: `--since=2025-01-01` or `--last-week`
|
|
393
|
+
|
|
394
|
+
### Medium-Term (Next 3-6 Months)
|
|
395
|
+
- **Reranking** — Use Cohere or Jina rerankers for better precision after KNN recall
|
|
396
|
+
- **Cache summaries** — Avoid re-summarizing the same chunks across queries
|
|
397
|
+
- **Query expansion** — Synonym/related term expansion for keyword search
|
|
398
|
+
- **Incremental indexing** — Watch `.jsonl` files and index on change (file watcher hook)
|
|
399
|
+
|
|
400
|
+
### Long-Term (Research / Experimental)
|
|
401
|
+
- **Multi-modal embeddings** — Embed code, images, browser screenshots separately
|
|
402
|
+
- **Graph-based retrieval** — Track file evolution, tool sequences, error→fix patterns
|
|
403
|
+
- **Personalized ranking** — Learn from user's click/accept signals to improve relevance
|
|
404
|
+
- **Cross-session context** — Link related sessions into threads/projects automatically
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
## FAQ
|
|
409
|
+
|
|
410
|
+
### Why two tiers (JSON + vector)?
|
|
411
|
+
|
|
412
|
+
**Availability:** JSON indexes have zero dependencies and always work. Vector search requires Ollama setup.
|
|
413
|
+
|
|
414
|
+
**Speed:** Keyword search is 10-50x faster than vector search for simple lookups.
|
|
415
|
+
|
|
416
|
+
**Quality:** Semantic search handles synonyms, rephrasing, and conceptual queries that keyword search misses.
|
|
417
|
+
|
|
418
|
+
Having both tiers means the system is useful immediately (keyword) and scales up in quality when you install Ollama (semantic).
|
|
419
|
+
|
|
420
|
+
### Why Ollama instead of OpenAI embeddings?
|
|
421
|
+
|
|
422
|
+
**Cost:** Ollama is free and local. OpenAI charges per token.
|
|
423
|
+
|
|
424
|
+
**Privacy:** Session transcripts stay on your machine.
|
|
425
|
+
|
|
426
|
+
**Speed:** Local embeddings are ~10-30ms vs ~100-300ms for API round-trips.
|
|
427
|
+
|
|
428
|
+
**Offline:** Works without internet once model is pulled.
|
|
429
|
+
|
|
430
|
+
For production systems with budget, OpenAI embeddings (`text-embedding-3-small`) would be faster and higher quality. But for a personal dev tool, Ollama hits the sweet spot.
|
|
431
|
+
|
|
432
|
+
### Why nomic-embed-text model?
|
|
433
|
+
|
|
434
|
+
**Optimized for retrieval:** Trained specifically for semantic search (not chat).
|
|
435
|
+
|
|
436
|
+
**Fast:** 137M parameters (~400MB), embeds in 10-30ms on CPU.
|
|
437
|
+
|
|
438
|
+
**Quality:** Competitive with OpenAI's `text-embedding-ada-002` on MTEB benchmarks.
|
|
439
|
+
|
|
440
|
+
**License:** Apache 2.0 (commercially usable).
|
|
441
|
+
|
|
442
|
+
Alternative models (e.g., `all-MiniLM-L6-v2`) are smaller but lower quality. Larger models (e.g., `gte-large`) are higher quality but slower. `nomic-embed-text` is the best speed/quality trade-off for this use case.
|
|
443
|
+
|
|
444
|
+
### Why SQLite for vector storage?
|
|
445
|
+
|
|
446
|
+
**Simplicity:** Single-file database, no server setup.
|
|
447
|
+
|
|
448
|
+
**Portability:** Copy `rlm-vectors.db` to backup/share entire index.
|
|
449
|
+
|
|
450
|
+
**Performance:** sqlite-vec (KNN extension) is fast enough for 1000s of documents.
|
|
451
|
+
|
|
452
|
+
**Compatibility:** Works everywhere SQLite works (all platforms, no dependencies).
|
|
453
|
+
|
|
454
|
+
For larger deployments (10K+ sessions), consider ChromaDB, Pinecone, or Weaviate. But for personal use, SQLite is simpler and faster to set up.
|
|
455
|
+
|
|
456
|
+
### How accurate is semantic search?
|
|
457
|
+
|
|
458
|
+
**Precision:** ~70-85% (depends on query quality and corpus size)
|
|
459
|
+
|
|
460
|
+
**Recall:** ~60-80% baseline, 80-95% with HyDE enabled
|
|
461
|
+
|
|
462
|
+
**Comparison to keyword:** Semantic search handles paraphrasing better, keyword search handles exact terms better. Best results come from using both (semantic for recall, keyword for precision).
|
|
463
|
+
|
|
464
|
+
The system doesn't expose both simultaneously yet—it auto-picks one. Future versions may support hybrid search (combine both scores).
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
## Changelog
|
|
469
|
+
|
|
470
|
+
### v1.0.0 (2025-02-15)
|
|
471
|
+
- **Command consolidation:** 6 commands → 3 commands (ask, overview, index)
|
|
472
|
+
- **Auto-indexing:** Transparent index building on first use
|
|
473
|
+
- **Auto-model-pull:** Automatic nomic-embed-text download if missing
|
|
474
|
+
- **Unified interface:** Single `rlm:ask` for all Q&A workflows
|
|
475
|
+
- **Documentation:** Comprehensive CLAUDE.md with architecture + user guide
|
|
476
|
+
|
|
477
|
+
### Pre-v1.0 (2025-02-14)
|
|
478
|
+
- Initial implementation with 6 separate commands
|
|
479
|
+
- Manual index building required
|
|
480
|
+
- Separate commands for search/retrieve/recall (confusing UX)
|