llm-kb 0.2.0 → 0.4.0
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/PHASE3_SPEC.md +245 -0
- package/PHASE4_SPEC.md +358 -0
- package/README.md +182 -61
- package/bin/cli.js +5473 -165
- package/package.json +11 -6
- package/plan.md +248 -3
- package/src/auth.ts +55 -0
- package/src/cli.ts +163 -38
- package/src/config.ts +61 -0
- package/src/eval.ts +548 -0
- package/src/indexer.ts +36 -32
- package/src/md-stream.ts +133 -0
- package/src/query.ts +408 -132
- package/src/session-store.ts +22 -0
- package/src/session-watcher.ts +89 -0
- package/src/trace-builder.ts +168 -0
- package/src/tui-display.ts +281 -0
- package/src/utils.ts +17 -0
- package/src/watcher.ts +5 -2
- package/src/wiki-updater.ts +136 -0
- package/test/auth.test.ts +65 -0
- package/test/config.test.ts +96 -0
- package/test/md-stream.test.ts +98 -0
- package/test/resolve-kb.test.ts +33 -0
- package/test/scan.test.ts +65 -0
- package/test/trace-builder.test.ts +215 -0
- package/vitest.config.ts +8 -0
- package/bin/chunk-MYQ36JJB.js +0 -118
- package/bin/indexer-LSYSZXZX.js +0 -6
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# llm-kb
|
|
2
2
|
|
|
3
|
-
Drop files into a folder. Get a knowledge base you can query.
|
|
3
|
+
Drop files into a folder. Get a knowledge base you can query — with a self-improving wiki that gets smarter every time you ask.
|
|
4
4
|
|
|
5
|
-
Inspired by [Karpathy's LLM Knowledge Bases](https://x.com/karpathy/status/2039805659525644595).
|
|
5
|
+
Inspired by [Karpathy's LLM Knowledge Bases](https://x.com/karpathy/status/2039805659525644595) and [Farzapedia](https://x.com/FarzaTV).
|
|
6
6
|
|
|
7
7
|
## Quick Start
|
|
8
8
|
|
|
@@ -11,121 +11,242 @@ npm install -g llm-kb
|
|
|
11
11
|
llm-kb run ./my-documents
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
That's it.
|
|
14
|
+
That's it. PDFs get parsed, an index is built, and an interactive chat opens — ready for questions.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
## Authentication
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
- **Pi SDK** installed and authenticated (`npm install -g @mariozechner/pi-coding-agent` + run `pi` once to set up auth)
|
|
18
|
+
Two options (you need one):
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
**Option 1 — Pi SDK (recommended)**
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @mariozechner/pi-coding-agent
|
|
23
|
+
pi # run once to authenticate
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Option 2 — Anthropic API key**
|
|
27
|
+
```bash
|
|
28
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If neither is configured, `llm-kb` shows a clear error with setup instructions.
|
|
22
32
|
|
|
23
33
|
## What It Does
|
|
24
34
|
|
|
25
|
-
###
|
|
35
|
+
### Run — scan, parse, index, chat
|
|
26
36
|
|
|
27
37
|
```bash
|
|
28
38
|
llm-kb run ./my-documents
|
|
29
39
|
```
|
|
30
40
|
|
|
31
41
|
```
|
|
32
|
-
llm-kb v0.
|
|
42
|
+
llm-kb v0.3.0
|
|
33
43
|
|
|
34
44
|
Scanning ./my-documents...
|
|
35
45
|
Found 9 files (9 PDF)
|
|
36
46
|
9 parsed
|
|
37
47
|
|
|
38
|
-
Building index...
|
|
48
|
+
Building index... (claude-haiku-4-5)
|
|
39
49
|
Index built: .llm-kb/wiki/index.md
|
|
40
50
|
|
|
41
|
-
|
|
51
|
+
Ready. Ask a question or drop files in to re-index.
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
────────────────────────────────────────────
|
|
54
|
+
> What are the key findings?
|
|
55
|
+
────────────────────────────────────────────
|
|
45
56
|
|
|
46
|
-
|
|
47
|
-
2. **Parses** each PDF to markdown + bounding boxes (using [LiteParse](https://github.com/run-llama/liteparse))
|
|
48
|
-
3. **Builds an index** — Pi SDK agent reads all sources and writes `index.md` with summaries
|
|
49
|
-
4. **Watches** — drop a new PDF in while it's running, it gets parsed and indexed automatically
|
|
57
|
+
⟡ claude-sonnet-4-6
|
|
50
58
|
|
|
51
|
-
|
|
59
|
+
▸ Thinking
|
|
60
|
+
Let me check the relevant source files...
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
llm-kb query "what are the key findings?"
|
|
62
|
+
▸ Reading q3-report.md
|
|
63
|
+
▸ Reading q4-report.md
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
llm-kb query "compare Q3 vs Q4" --folder ./my-documents
|
|
65
|
+
──────────────────────────────────────────────
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
## Key Findings
|
|
68
|
+
Revenue grew 12% QoQ driven by...
|
|
69
|
+
(cited answer with page references)
|
|
70
|
+
|
|
71
|
+
── 8.3s · 2 files read ──────────────────────
|
|
62
72
|
```
|
|
63
73
|
|
|
64
|
-
|
|
74
|
+
**What happens:**
|
|
75
|
+
1. **Scans** — finds all supported files (PDF, DOCX, XLSX, PPTX, MD, TXT, CSV, images)
|
|
76
|
+
2. **Parses** — PDFs converted to markdown + bounding boxes via [LiteParse](https://github.com/run-llama/liteparse)
|
|
77
|
+
3. **Indexes** — Haiku reads sources, writes `index.md` with summary table
|
|
78
|
+
4. **Watches** — drop new files while running, they get parsed and indexed automatically
|
|
79
|
+
5. **Chat** — interactive TUI with Pi-style markdown rendering, thinking display, tool call progress
|
|
80
|
+
6. **Learns** — every answer updates a knowledge wiki; repeated questions answered instantly from cache
|
|
65
81
|
|
|
66
|
-
|
|
67
|
-
**Research mode** (`--save`) — read + write + bash. The agent saves answers to `outputs/`, re-indexes, and can write scripts to read Excel/Word files. Answers compound over time.
|
|
82
|
+
### Continuous conversation
|
|
68
83
|
|
|
69
|
-
|
|
84
|
+
The chat maintains full conversation history. Follow-up questions work naturally:
|
|
70
85
|
|
|
71
86
|
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
└── ...
|
|
87
|
+
> What is BNS 2023?
|
|
88
|
+
(detailed answer)
|
|
89
|
+
|
|
90
|
+
> Tell me more about the mob lynching clause
|
|
91
|
+
(agent remembers context — answers about Clause 101 without re-reading)
|
|
92
|
+
|
|
93
|
+
> How does that compare to the old IPC?
|
|
94
|
+
(continues the thread with full context)
|
|
81
95
|
```
|
|
82
96
|
|
|
83
|
-
|
|
97
|
+
Sessions persist across restarts — run `llm-kb run` again and the conversation continues.
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
### Query — single question from CLI
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Auto-detects .llm-kb/ by walking up from cwd
|
|
103
|
+
llm-kb query "compare Q3 vs Q4"
|
|
104
|
+
|
|
105
|
+
# Explicit folder
|
|
106
|
+
llm-kb query "summarize all revenue data" --folder ./my-documents
|
|
86
107
|
|
|
87
|
-
|
|
108
|
+
# Research mode — saves answer and re-indexes
|
|
109
|
+
llm-kb query "full analysis of lease terms" --save
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Status — KB overview
|
|
88
113
|
|
|
89
|
-
**Local (default when enabled):**
|
|
90
114
|
```bash
|
|
91
|
-
|
|
115
|
+
llm-kb status
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
Knowledge Base Status
|
|
120
|
+
Folder: /path/to/my-documents
|
|
121
|
+
Sources: 12 parsed sources
|
|
122
|
+
Index: 3 min ago
|
|
123
|
+
Outputs: 2 saved answers
|
|
124
|
+
Models: claude-sonnet-4-6 (query) claude-haiku-4-5 (index)
|
|
125
|
+
Auth: Pi SDK
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## The Knowledge Wiki
|
|
129
|
+
|
|
130
|
+
Every query makes the system smarter. After answering, `llm-kb` uses Haiku to update `.llm-kb/wiki/wiki.md` — a structured knowledge wiki organized by topic:
|
|
131
|
+
|
|
132
|
+
```markdown
|
|
133
|
+
## Indian Evidence Act, 1872
|
|
134
|
+
|
|
135
|
+
### Overview
|
|
136
|
+
Foundational legislation covering 167 sections in 3 parts...
|
|
137
|
+
|
|
138
|
+
### Part I — Relevancy of Facts
|
|
139
|
+
Admissions, confessions, dying declarations, expert opinions...
|
|
140
|
+
|
|
141
|
+
### Electronic Records (Section 65B)
|
|
142
|
+
Admissible with certificate from responsible official...
|
|
143
|
+
|
|
144
|
+
*Sources: Indian Evidence Act.md · 2026-04-06*
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Bankers Books Evidence Act, 1891
|
|
149
|
+
|
|
150
|
+
### Key Sections
|
|
151
|
+
Section 4 (core): certified copy = prima facie evidence...
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
When you ask a question already covered by the wiki, the agent answers instantly — no source files read. New questions expand the wiki. The knowledge compounds.
|
|
155
|
+
|
|
156
|
+
## Model Configuration
|
|
157
|
+
|
|
158
|
+
Auto-generated at `.llm-kb/config.json`:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"indexModel": "claude-haiku-4-5",
|
|
163
|
+
"queryModel": "claude-sonnet-4-6"
|
|
164
|
+
}
|
|
92
165
|
```
|
|
93
|
-
Uses Tesseract.js (built-in, slower but works everywhere).
|
|
94
166
|
|
|
95
|
-
**
|
|
167
|
+
- **Haiku** for indexing — cheap, fast, good enough for summaries
|
|
168
|
+
- **Sonnet** for queries — strong reasoning for cited answers
|
|
169
|
+
|
|
170
|
+
Override with env vars:
|
|
96
171
|
```bash
|
|
97
|
-
|
|
172
|
+
LLM_KB_INDEX_MODEL=claude-haiku-4-5 llm-kb run ./docs
|
|
173
|
+
LLM_KB_QUERY_MODEL=claude-sonnet-4-6 llm-kb query "question"
|
|
98
174
|
```
|
|
99
|
-
Routes scanned pages to an Azure Document Intelligence bridge. Native-text pages still processed locally (free).
|
|
100
175
|
|
|
101
176
|
## Non-PDF Files
|
|
102
177
|
|
|
103
|
-
PDFs are parsed at
|
|
178
|
+
PDFs are parsed at scan time. Other file types are read dynamically by the agent at query time using bash:
|
|
104
179
|
|
|
105
|
-
|
|
|
180
|
+
| File type | How it's read |
|
|
106
181
|
|---|---|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
182
|
+
| `.pdf` | Pre-parsed to markdown + bounding boxes (LiteParse) |
|
|
183
|
+
| `.docx` | Agent reads selectively via `adm-zip` (XML structure) |
|
|
184
|
+
| `.xlsx` | Agent reads specific sheets/cells via `exceljs` |
|
|
185
|
+
| `.pptx` | Agent extracts text via `officeparser` |
|
|
186
|
+
| `.md`, `.txt`, `.csv` | Read directly |
|
|
187
|
+
|
|
188
|
+
For large `.docx` files, the agent reads the document structure first, then extracts only the sections relevant to your question — not the whole file.
|
|
189
|
+
|
|
190
|
+
## OCR for Scanned PDFs
|
|
191
|
+
|
|
192
|
+
Most PDFs have native text. For scanned PDFs:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Local Tesseract (built-in, slower)
|
|
196
|
+
OCR_ENABLED=true llm-kb run ./docs
|
|
110
197
|
|
|
111
|
-
|
|
198
|
+
# Remote Azure OCR (faster, better quality)
|
|
199
|
+
OCR_SERVER_URL="http://localhost:8080/ocr?key=KEY" llm-kb run ./docs
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Native-text pages are always processed locally (free). Only scanned pages hit the OCR server.
|
|
203
|
+
|
|
204
|
+
## What It Creates
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
./my-documents/
|
|
208
|
+
├── (your files — untouched)
|
|
209
|
+
└── .llm-kb/
|
|
210
|
+
├── config.json ← model configuration
|
|
211
|
+
├── sessions/ ← conversation history (JSONL)
|
|
212
|
+
├── traces/ ← per-query traces (JSON)
|
|
213
|
+
│ └── .processed ← prevents re-processing on restart
|
|
214
|
+
└── wiki/
|
|
215
|
+
├── index.md ← source summary table
|
|
216
|
+
├── wiki.md ← knowledge wiki (grows over time)
|
|
217
|
+
├── queries.md ← query log (newest first)
|
|
218
|
+
├── sources/ ← parsed markdown + bounding boxes
|
|
219
|
+
└── outputs/ ← saved research answers (--save)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Your original files are never modified. Delete `.llm-kb/` to start fresh.
|
|
112
223
|
|
|
113
|
-
##
|
|
224
|
+
## Display
|
|
114
225
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
226
|
+
The interactive TUI (via `@mariozechner/pi-tui`) shows:
|
|
227
|
+
|
|
228
|
+
| Phase | What you see |
|
|
229
|
+
|---|---|
|
|
230
|
+
| Model | `⟡ claude-sonnet-4-6` |
|
|
231
|
+
| Thinking | `▸ Thinking` + streamed reasoning (dim) |
|
|
232
|
+
| Tool calls | `▸ Reading file.md` / `▸ Running bash` + code block |
|
|
233
|
+
| Answer | Separator line → markdown rendered with tables, code, headers |
|
|
234
|
+
| Done | `── 8.3s · 2 files read ──` |
|
|
235
|
+
|
|
236
|
+
The `llm-kb query` command uses stdout mode — same phases, streams to terminal, works with pipes.
|
|
119
237
|
|
|
120
238
|
## Development
|
|
121
239
|
|
|
122
240
|
```bash
|
|
123
241
|
git clone https://github.com/satish860/llm-kb
|
|
124
242
|
cd llm-kb
|
|
125
|
-
|
|
126
|
-
|
|
243
|
+
npm install
|
|
244
|
+
npm run build
|
|
127
245
|
npm link
|
|
128
246
|
|
|
247
|
+
npm test # 38 tests
|
|
248
|
+
npm run test:watch # vitest watch mode
|
|
249
|
+
|
|
129
250
|
llm-kb run ./test-folder
|
|
130
251
|
```
|
|
131
252
|
|
|
@@ -135,4 +256,4 @@ Building this in public: [themindfulai.dev](https://themindfulai.dev/articles/bu
|
|
|
135
256
|
|
|
136
257
|
## License
|
|
137
258
|
|
|
138
|
-
MIT
|
|
259
|
+
MIT — [Satish Venkatakrishnan](https://deltaxy.ai)
|