@robthepcguy/rag-vault 1.0.1 → 1.1.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.
Files changed (73) hide show
  1. package/README.md +441 -421
  2. package/dist/errors/index.d.ts +2 -6
  3. package/dist/errors/index.d.ts.map +1 -1
  4. package/dist/errors/index.js +8 -16
  5. package/dist/errors/index.js.map +1 -1
  6. package/dist/explainability/index.d.ts +2 -0
  7. package/dist/explainability/index.d.ts.map +1 -0
  8. package/dist/explainability/index.js +8 -0
  9. package/dist/explainability/index.js.map +1 -0
  10. package/dist/explainability/keywords.d.ts +18 -0
  11. package/dist/explainability/keywords.d.ts.map +1 -0
  12. package/dist/explainability/keywords.js +237 -0
  13. package/dist/explainability/keywords.js.map +1 -0
  14. package/dist/flywheel/feedback.d.ts +105 -0
  15. package/dist/flywheel/feedback.d.ts.map +1 -0
  16. package/dist/flywheel/feedback.js +219 -0
  17. package/dist/flywheel/feedback.js.map +1 -0
  18. package/dist/flywheel/index.d.ts +2 -0
  19. package/dist/flywheel/index.d.ts.map +1 -0
  20. package/dist/flywheel/index.js +9 -0
  21. package/dist/flywheel/index.js.map +1 -0
  22. package/dist/index.js +1 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/server/index.d.ts +40 -0
  25. package/dist/server/index.d.ts.map +1 -1
  26. package/dist/server/index.js +113 -0
  27. package/dist/server/index.js.map +1 -1
  28. package/dist/server/raw-data-utils.d.ts.map +1 -1
  29. package/dist/server/raw-data-utils.js.map +1 -1
  30. package/dist/utils/config.d.ts +15 -0
  31. package/dist/utils/config.d.ts.map +1 -1
  32. package/dist/utils/config.js +84 -0
  33. package/dist/utils/config.js.map +1 -1
  34. package/dist/utils/math.d.ts +0 -7
  35. package/dist/utils/math.d.ts.map +1 -1
  36. package/dist/utils/math.js +0 -14
  37. package/dist/utils/math.js.map +1 -1
  38. package/dist/vectordb/index.d.ts +57 -2
  39. package/dist/vectordb/index.d.ts.map +1 -1
  40. package/dist/vectordb/index.js +255 -33
  41. package/dist/vectordb/index.js.map +1 -1
  42. package/dist/web/api-routes.d.ts.map +1 -1
  43. package/dist/web/api-routes.js +120 -7
  44. package/dist/web/api-routes.js.map +1 -1
  45. package/dist/web/config-routes.d.ts.map +1 -1
  46. package/dist/web/config-routes.js +84 -2
  47. package/dist/web/config-routes.js.map +1 -1
  48. package/dist/web/database-manager.d.ts +119 -1
  49. package/dist/web/database-manager.d.ts.map +1 -1
  50. package/dist/web/database-manager.js +339 -51
  51. package/dist/web/database-manager.js.map +1 -1
  52. package/dist/web/http-server.d.ts.map +1 -1
  53. package/dist/web/http-server.js +12 -2
  54. package/dist/web/http-server.js.map +1 -1
  55. package/dist/web/index.js +4 -1
  56. package/dist/web/index.js.map +1 -1
  57. package/dist/web/middleware/error-handler.d.ts +0 -16
  58. package/dist/web/middleware/error-handler.d.ts.map +1 -1
  59. package/dist/web/middleware/error-handler.js +0 -18
  60. package/dist/web/middleware/error-handler.js.map +1 -1
  61. package/dist/web/middleware/request-logger.d.ts +2 -1
  62. package/dist/web/middleware/request-logger.d.ts.map +1 -1
  63. package/package.json +129 -136
  64. package/skills/rag-vault/SKILL.md +111 -111
  65. package/web-ui/dist/assets/index-BcRp9-z9.js +120 -0
  66. package/web-ui/dist/assets/index-ej8i4PGl.css +1 -0
  67. package/web-ui/dist/index.html +2 -2
  68. package/dist/utils/logger.d.ts +0 -36
  69. package/dist/utils/logger.d.ts.map +0 -1
  70. package/dist/utils/logger.js +0 -64
  71. package/dist/utils/logger.js.map +0 -1
  72. package/web-ui/dist/assets/index-0kBxUnZc.css +0 -1
  73. package/web-ui/dist/assets/index-CaUT0xZD.js +0 -59
package/README.md CHANGED
@@ -1,421 +1,441 @@
1
- # RAG Vault
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
5
- [![MCP Registry](https://img.shields.io/badge/MCP-Registry-green.svg)](https://registry.modelcontextprotocol.io/servers/io.github.RobThePCGuy/rag-vault)
6
-
7
- **Your documents. Your machine. Your control.**
8
-
9
- RAG Vault gives AI coding assistants instant access to your private documents—API specs, research papers, internal docs—without ever sending data to the cloud. One command, zero configuration, complete privacy.
10
-
11
- ## Why RAG Vault?
12
-
13
- | Pain Point | RAG Vault Solution |
14
- |------------|-------------------|
15
- | "I don't want my docs on someone else's server" | Everything stays local. No API calls after setup. |
16
- | "Semantic search misses exact code terms" | Hybrid search: meaning + exact matches like `useEffect` |
17
- | "Setup requires Docker, Python, databases..." | One `npx` command. Done. |
18
- | "Cloud APIs charge per query" | Free forever. No subscriptions. |
19
-
20
- ## Security
21
-
22
- RAG Vault includes security features for production deployment:
23
- - **API Authentication** — Optional API key via `RAG_API_KEY`
24
- - **Rate Limiting** — Configurable request throttling
25
- - **CORS Control** — Restrict allowed origins
26
- - **Security Headers** — Helmet.js protection
27
-
28
- See [SECURITY.md](SECURITY.md) for complete documentation.
29
-
30
- ## Get Started in 30 Seconds
31
-
32
- ### For Cursor
33
-
34
- Add to `~/.cursor/mcp.json`:
35
-
36
- ```json
37
- {
38
- "mcpServers": {
39
- "local-rag": {
40
- "type": "stdio",
41
- "command": "npx",
42
- "args": ["-y", "github:RobThePCGuy/rag-vault"],
43
- "env": {
44
- "BASE_DIR": "/path/to/your/documents"
45
- }
46
- }
47
- }
48
- }
49
- ```
50
-
51
- ### For Claude Code
52
-
53
- Add to `.mcp.json` in your project directory:
54
-
55
- ```json
56
- {
57
- "mcpServers": {
58
- "local-rag": {
59
- "type": "stdio",
60
- "command": "npx",
61
- "args": ["-y", "github:RobThePCGuy/rag-vault"],
62
- "env": {
63
- "BASE_DIR": "./documents",
64
- "DB_PATH": "./documents/.rag-db",
65
- "CACHE_DIR": "./.cache",
66
- "RAG_HYBRID_WEIGHT": "0.6",
67
- "RAG_GROUPING": "related"
68
- }
69
- }
70
- }
71
- }
72
- ```
73
-
74
- Or add inline via CLI:
75
-
76
- ```bash
77
- claude mcp add local-rag --scope user --env BASE_DIR=/path/to/your/documents -- npx -y github:RobThePCGuy/rag-vault
78
- ```
79
-
80
- ### For Codex
81
-
82
- Add to `~/.codex/config.toml`:
83
-
84
- ```toml
85
- [mcp_servers.local-rag]
86
- command = "npx"
87
- args = ["-y", "github:RobThePCGuy/rag-vault"]
88
-
89
- [mcp_servers.local-rag.env]
90
- BASE_DIR = "/path/to/your/documents"
91
- ```
92
-
93
- ### Install Skills (Optional)
94
-
95
- For enhanced AI guidance on query formulation and result interpretation, install the RAG Vault skills:
96
-
97
- ```bash
98
- # Claude Code (project-level - recommended for team projects)
99
- npx github:RobThePCGuy/rag-vault skills install --claude-code
100
-
101
- # Claude Code (user-level - available in all projects)
102
- npx github:RobThePCGuy/rag-vault skills install --claude-code --global
103
-
104
- # Codex (user-level)
105
- npx github:RobThePCGuy/rag-vault skills install --codex
106
-
107
- # Custom location
108
- npx github:RobThePCGuy/rag-vault skills install --path /your/custom/path
109
- ```
110
-
111
- Skills teach Claude best practices for:
112
- - Query formulation and expansion strategies
113
- - Score interpretation (< 0.3 = good match, > 0.5 = skip)
114
- - When to use `ingest_file` vs `ingest_data`
115
- - HTML ingestion and URL handling
116
-
117
- Restart your AI tool, and start talking:
118
-
119
- ```
120
- You: "Ingest api-spec.pdf"
121
- AI: Successfully ingested api-spec.pdf (47 chunks)
122
-
123
- You: "How does authentication work?"
124
- AI: Based on section 3.2, authentication uses OAuth 2.0 with JWT tokens...
125
- ```
126
-
127
- That's it. No Docker. No Python. No servers.
128
-
129
- ## Web Interface
130
-
131
- RAG Vault includes a full-featured web UI for managing your documents without the command line.
132
-
133
- ### Launch the Web UI
134
-
135
- ```bash
136
- npx github:RobThePCGuy/rag-vault web
137
- ```
138
-
139
- Open [http://localhost:3000](http://localhost:3000) in your browser.
140
-
141
- ### What You Can Do
142
-
143
- - **Upload documents** — Drag and drop PDFs, Word docs, Markdown, text files
144
- - **Search instantly** — Type queries and see results with relevance scores
145
- - **Preview content** — Click any result to see the full chunk in context
146
- - **Manage files** — View all indexed documents, delete what you don't need
147
- - **Switch databases** — Create and switch between multiple knowledge bases
148
- - **Monitor status** — See document counts, database size, system health
149
-
150
- ### REST API
151
-
152
- The web server exposes a REST API for programmatic access. Set `RAG_API_KEY` to require authentication:
153
-
154
- ```bash
155
- # With authentication (when RAG_API_KEY is set)
156
- curl -X POST "http://localhost:3000/api/v1/search" \
157
- -H "Authorization: Bearer your-api-key" \
158
- -H "Content-Type: application/json" \
159
- -d '{"query": "authentication", "limit": 5}'
160
-
161
- # Search documents (no auth required if RAG_API_KEY is not set)
162
- curl -X POST "http://localhost:3000/api/v1/search" \
163
- -H "Content-Type: application/json" \
164
- -d '{"query": "authentication", "limit": 5}'
165
-
166
- # List all files
167
- curl "http://localhost:3000/api/v1/files"
168
-
169
- # Upload a document
170
- curl -X POST "http://localhost:3000/api/v1/files/upload" \
171
- -F "file=@spec.pdf"
172
-
173
- # Delete a file
174
- curl -X DELETE "http://localhost:3000/api/v1/files" \
175
- -H "Content-Type: application/json" \
176
- -d '{"filePath": "/path/to/spec.pdf"}'
177
-
178
- # Get system status
179
- curl "http://localhost:3000/api/v1/status"
180
-
181
- # Health check (for load balancers)
182
- curl "http://localhost:3000/api/v1/health"
183
- ```
184
-
185
- ## Real-World Examples
186
-
187
- ### Search Your Codebase Documentation
188
-
189
- ```
190
- You: "Ingest all the markdown files in /docs"
191
- AI: Ingested 23 files (847 chunks total)
192
-
193
- You: "What's the retry policy for failed API calls?"
194
- AI: According to error-handling.md, failed requests retry 3 times
195
- with exponential backoff: 1s, 2s, 4s...
196
- ```
197
-
198
- ### Index Web Documentation
199
-
200
- ```
201
- You: "Fetch https://docs.example.com/api and ingest the HTML"
202
- AI: Ingested "docs.example.com/api" (156 chunks)
203
-
204
- You: "What rate limits apply to the /users endpoint?"
205
- AI: The API limits /users to 100 requests per minute per API key...
206
- ```
207
-
208
- ### Build a Personal Knowledge Base
209
-
210
- ```
211
- You: "Ingest my research papers folder"
212
- AI: Ingested 12 PDFs (2,341 chunks)
213
-
214
- You: "What do recent studies say about transformer attention mechanisms?"
215
- AI: Based on attention-mechanisms-2024.pdf, the key finding is...
216
- ```
217
-
218
- ### Search Exact Technical Terms
219
-
220
- RAG Vault's hybrid search catches both meaning and exact matches:
221
-
222
- ```
223
- You: "Search for ERR_CONNECTION_REFUSED"
224
- AI: Found 3 results mentioning ERR_CONNECTION_REFUSED:
225
- 1. troubleshooting.md - "When you see ERR_CONNECTION_REFUSED..."
226
- 2. network-errors.pdf - "Common causes include..."
227
- ```
228
-
229
- Pure semantic search would miss this. RAG Vault finds it.
230
-
231
- ## How It Works
232
-
233
- ```
234
- Document Parse Chunk by meaning Embed locally → Store in LanceDB
235
-
236
- Query → Embed → Vector search → Keyword boost → Quality filter → Results
237
- ```
238
-
239
- **Smart chunking**: Splits by meaning, not character count. Keeps code blocks intact.
240
-
241
- **Hybrid search**: Vector similarity finds related content. Keyword boost ranks exact matches higher.
242
-
243
- **Quality filtering**: Groups results by relevance gaps instead of arbitrary top-K cutoffs.
244
-
245
- **Local everything**: Embeddings via Transformers.js. Storage via LanceDB. No network after model download.
246
-
247
- ## Supported Formats
248
-
249
- | Format | Extension | Notes |
250
- |--------|-----------|-------|
251
- | PDF | `.pdf` | Full text extraction, header/footer filtering |
252
- | Word | `.docx` | Tables, lists, formatting preserved |
253
- | Markdown | `.md` | Code blocks kept intact |
254
- | Text | `.txt` | Plain text |
255
- | JSON | `.json` | Converted to searchable key-value text |
256
- | HTML | via `ingest_data` | Auto-cleaned with Readability |
257
-
258
- ## Configuration
259
-
260
- ### Environment Variables
261
-
262
- | Variable | Default | What it does |
263
- |----------|---------|--------------|
264
- | `BASE_DIR` | Current directory | Only files under this path can be accessed |
265
- | `DB_PATH` | `./lancedb/` | Where vectors are stored |
266
- | `MODEL_NAME` | `Xenova/all-MiniLM-L6-v2` | HuggingFace embedding model |
267
- | `WEB_PORT` | `3000` | Port for web interface |
268
-
269
- ### Search Tuning
270
-
271
- | Variable | Default | What it does |
272
- |----------|---------|--------------|
273
- | `RAG_HYBRID_WEIGHT` | `0.6` | Keyword boost strength. 0 = semantic-only, higher = stronger boost for exact keyword matches |
274
- | `RAG_GROUPING` | | `similar` = top group only, `related` = top 2 groups |
275
- | `RAG_MAX_DISTANCE` | | Filter out results below this relevance threshold |
276
-
277
- ### Security (optional)
278
-
279
- | Variable | Default | What it does |
280
- |----------|---------|--------------|
281
- | `RAG_API_KEY` | — | API key for authentication |
282
- | `CORS_ORIGINS` | localhost | Allowed origins (comma-separated, or `*`) |
283
- | `RATE_LIMIT_WINDOW_MS` | `60000` | Rate limit time window (ms) |
284
- | `RATE_LIMIT_MAX_REQUESTS` | `100` | Max requests per window |
285
-
286
- ### Advanced
287
-
288
- | Variable | Default | What it does |
289
- |----------|---------|--------------|
290
- | `ALLOWED_SCAN_ROOTS` | Home directory | Directories allowed for database scanning |
291
- | `JSON_BODY_LIMIT` | `5mb` | Max request body size |
292
- | `REQUEST_TIMEOUT_MS` | `30000` | API request timeout |
293
- | `REQUEST_LOGGING` | `false` | Enable request audit logging |
294
-
295
- > Copy [`.env.example`](.env.example) for a complete configuration template.
296
-
297
- **For code-heavy content**, try:
298
-
299
- ```json
300
- "env": {
301
- "RAG_HYBRID_WEIGHT": "0.8",
302
- "RAG_GROUPING": "similar"
303
- }
304
- ```
305
-
306
- ## Frequently Asked Questions
307
-
308
- <details>
309
- <summary><strong>Is my data really private?</strong></summary>
310
-
311
- Yes. After the embedding model downloads (~90MB), RAG Vault makes zero network requests. Everything runs on your machine. Verify with network monitoring.
312
-
313
- </details>
314
-
315
- <details>
316
- <summary><strong>Does it work offline?</strong></summary>
317
-
318
- Yes, after the first run. The model caches locally.
319
-
320
- </details>
321
-
322
- <details>
323
- <summary><strong>What about GPU acceleration?</strong></summary>
324
-
325
- Transformers.js runs on CPU. GPU support is experimental but unnecessary for most use cases—queries return in ~1 second even with 10,000 chunks.
326
-
327
- </details>
328
-
329
- <details>
330
- <summary><strong>Can I change the embedding model?</strong></summary>
331
-
332
- Yes. Set `MODEL_NAME` to any compatible HuggingFace model. But you must delete `DB_PATH` and re-ingest—different models produce incompatible vectors.
333
-
334
- **Recommended upgrade:** For better quality and multilingual support, use [EmbeddingGemma](https://huggingface.co/onnx-community/embeddinggemma-300m-ONNX):
335
-
336
- ```json
337
- "MODEL_NAME": "onnx-community/embeddinggemma-300m-ONNX"
338
- ```
339
-
340
- This 300M parameter model scores 68.36 on MTEB benchmarks and supports 100+ languages, making it ideal for mixed-language or high-quality retrieval needs.
341
-
342
- **Other specialized models:**
343
- - Scientific: `sentence-transformers/allenai-specter`
344
- - Code: `jinaai/jina-embeddings-v2-base-code`
345
-
346
- </details>
347
-
348
- <details>
349
- <summary><strong>How do I back up my data?</strong></summary>
350
-
351
- Copy the `DB_PATH` directory (default: `./lancedb/`).
352
-
353
- </details>
354
-
355
- ## Troubleshooting
356
-
357
- | Problem | Solution |
358
- |---------|----------|
359
- | No results found | Documents must be ingested first. Run "List all ingested files" to check. |
360
- | Model download failed | Check internet connection. Model is ~90MB from HuggingFace. |
361
- | File too large | Default limit is 100MB. Set `MAX_FILE_SIZE` higher or split the file. |
362
- | Path outside BASE_DIR | All file paths must be under `BASE_DIR`. Use absolute paths. |
363
- | MCP tools not showing | Verify config syntax, restart your AI tool completely (Cmd+Q on Mac). |
364
- | 401 Unauthorized | API key required. Set `RAG_API_KEY` or use correct header format. |
365
- | 429 Too Many Requests | Rate limited. Wait for reset or increase `RATE_LIMIT_MAX_REQUESTS`. |
366
- | CORS errors | Add your origin to `CORS_ORIGINS` environment variable. |
367
-
368
- ## Development
369
-
370
- ```bash
371
- git clone https://github.com/RobThePCGuy/rag-vault.git
372
- cd rag-vault
373
- pnpm install
374
-
375
- # Run tests
376
- pnpm test
377
-
378
- # Type check + lint + format
379
- pnpm check:all
380
-
381
- # Build
382
- pnpm build
383
-
384
- # Run MCP server locally
385
- pnpm dev
386
-
387
- # Run web server locally
388
- pnpm web:dev
389
- ```
390
-
391
- ### Project Structure
392
-
393
- ```
394
- src/
395
- ├── server/ # MCP tool handlers
396
- ├── vectordb/ # LanceDB + hybrid search
397
- ├── chunker/ # Semantic text splitting
398
- ├── embedder/ # Transformers.js wrapper
399
- ├── parser/ # PDF, DOCX, HTML parsing
400
- ├── web/ # Express server + REST API
401
- └── __tests__/ # Test suites
402
-
403
- web-ui/ # React frontend
404
- ```
405
-
406
- ## Documentation
407
-
408
- - [SECURITY.md](SECURITY.md) — Security configuration and best practices
409
- - [.env.example](.env.example) — Complete environment variable template
410
-
411
- ## License
412
-
413
- MIT — free for personal and commercial use.
414
-
415
- ## Acknowledgments
416
-
417
- Built with [Model Context Protocol](https://modelcontextprotocol.io/), [LanceDB](https://lancedb.com/), and [Transformers.js](https://huggingface.co/docs/transformers.js).
418
-
419
- > Started as a fork of [mcp-local-rag](https://github.com/shinpr/mcp-local-rag) by [Shinsuke Kagawa](https://github.com/shinpr). Now it’s its own thing.
420
- > Huge credit to upstream contributors for the foundation, I’ve been iterating hard from there.
421
- > Local-first dev tools, all the way.
1
+ # RAG Vault
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
5
+ [![MCP Registry](https://img.shields.io/badge/MCP-Registry-green.svg)](https://registry.modelcontextprotocol.io/servers/io.github.RobThePCGuy/rag-vault)
6
+
7
+ **Your documents. Your machine. Your control.**
8
+
9
+ RAG Vault gives AI coding assistants instant access to your private documents—API specs, research papers, internal docs—without ever sending data to the cloud. One command, zero configuration, complete privacy.
10
+
11
+ ## Why RAG Vault?
12
+
13
+ | Pain Point | RAG Vault Solution |
14
+ |------------|-------------------|
15
+ | "I don't want my docs on someone else's server" | Everything stays local. No API calls after setup. |
16
+ | "Semantic search misses exact code terms" | Hybrid search: meaning + exact matches like `useEffect` |
17
+ | "Setup requires Docker, Python, databases..." | One `npx` command. Done. |
18
+ | "Cloud APIs charge per query" | Free forever. No subscriptions. |
19
+
20
+ ## Security
21
+
22
+ RAG Vault includes security features for production deployment:
23
+ - **API Authentication** — Optional API key via `RAG_API_KEY`
24
+ - **Rate Limiting** — Configurable request throttling
25
+ - **CORS Control** — Restrict allowed origins
26
+ - **Security Headers** — Helmet.js protection
27
+
28
+ See [SECURITY.md](SECURITY.md) for complete documentation.
29
+
30
+ ## Get Started in 30 Seconds
31
+
32
+ ### For Cursor
33
+
34
+ Add to `~/.cursor/mcp.json`:
35
+
36
+ ```json
37
+ {
38
+ "mcpServers": {
39
+ "local-rag": {
40
+ "type": "stdio",
41
+ "command": "npx",
42
+ "args": ["-y", "github:RobThePCGuy/rag-vault"],
43
+ "env": {
44
+ "BASE_DIR": "/path/to/your/documents"
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ### For Claude Code
52
+
53
+ Add to `.mcp.json` in your project directory:
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "local-rag": {
59
+ "type": "stdio",
60
+ "command": "npx",
61
+ "args": ["-y", "github:RobThePCGuy/rag-vault"],
62
+ "env": {
63
+ "BASE_DIR": "./documents",
64
+ "DB_PATH": "./documents/.rag-db",
65
+ "CACHE_DIR": "./.cache",
66
+ "RAG_HYBRID_WEIGHT": "0.6",
67
+ "RAG_GROUPING": "related"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ Or add inline via CLI:
75
+
76
+ ```bash
77
+ claude mcp add local-rag --scope user --env BASE_DIR=/path/to/your/documents -- npx -y github:RobThePCGuy/rag-vault
78
+ ```
79
+
80
+ ### For Codex
81
+
82
+ Add to `~/.codex/config.toml`:
83
+
84
+ ```toml
85
+ [mcp_servers.local-rag]
86
+ command = "npx"
87
+ args = ["-y", "github:RobThePCGuy/rag-vault"]
88
+
89
+ [mcp_servers.local-rag.env]
90
+ BASE_DIR = "/path/to/your/documents"
91
+ ```
92
+
93
+ ### Install Skills (Optional)
94
+
95
+ For enhanced AI guidance on query formulation and result interpretation, install the RAG Vault skills:
96
+
97
+ ```bash
98
+ # Claude Code (project-level - recommended for team projects)
99
+ npx github:RobThePCGuy/rag-vault skills install --claude-code
100
+
101
+ # Claude Code (user-level - available in all projects)
102
+ npx github:RobThePCGuy/rag-vault skills install --claude-code --global
103
+
104
+ # Codex (user-level)
105
+ npx github:RobThePCGuy/rag-vault skills install --codex
106
+
107
+ # Custom location
108
+ npx github:RobThePCGuy/rag-vault skills install --path /your/custom/path
109
+ ```
110
+
111
+ Skills teach Claude best practices for:
112
+ - Query formulation and expansion strategies
113
+ - Score interpretation (< 0.3 = good match, > 0.5 = skip)
114
+ - When to use `ingest_file` vs `ingest_data`
115
+ - HTML ingestion and URL handling
116
+
117
+ Restart your AI tool, and start talking:
118
+
119
+ ```
120
+ You: "Ingest api-spec.pdf"
121
+ AI: Successfully ingested api-spec.pdf (47 chunks)
122
+
123
+ You: "How does authentication work?"
124
+ AI: Based on section 3.2, authentication uses OAuth 2.0 with JWT tokens...
125
+ ```
126
+
127
+ That's it. No Docker. No Python. No servers.
128
+
129
+ ## Web Interface
130
+
131
+ RAG Vault includes a full-featured web UI for managing your documents without the command line.
132
+
133
+ ### Launch the Web UI
134
+
135
+ ```bash
136
+ npx github:RobThePCGuy/rag-vault web
137
+ ```
138
+
139
+ Open [http://localhost:3000](http://localhost:3000) in your browser.
140
+
141
+ ### What You Can Do
142
+
143
+ - **Upload documents** — Drag and drop PDFs, Word docs, Markdown, text files
144
+ - **Search instantly** — Type queries and see results with relevance scores
145
+ - **Preview content** — Click any result to see the full chunk in context
146
+ - **Manage files** — View all indexed documents, delete what you don't need
147
+ - **Switch databases** — Create and switch between multiple knowledge bases
148
+ - **Monitor status** — See document counts, memory usage, and search mode
149
+ - **Export/Import settings** — Back up and restore your vault configuration
150
+ - **Theme preferences** — Switch between light, dark, or system theme
151
+ - **Folder browser** — Navigate directories to select documents
152
+
153
+ ### REST API
154
+
155
+ The web server exposes a REST API for programmatic access. Set `RAG_API_KEY` to require authentication:
156
+
157
+ ```bash
158
+ # With authentication (when RAG_API_KEY is set)
159
+ curl -X POST "http://localhost:3000/api/v1/search" \
160
+ -H "Authorization: Bearer your-api-key" \
161
+ -H "Content-Type: application/json" \
162
+ -d '{"query": "authentication", "limit": 5}'
163
+
164
+ # Search documents (no auth required if RAG_API_KEY is not set)
165
+ curl -X POST "http://localhost:3000/api/v1/search" \
166
+ -H "Content-Type: application/json" \
167
+ -d '{"query": "authentication", "limit": 5}'
168
+
169
+ # List all files
170
+ curl "http://localhost:3000/api/v1/files"
171
+
172
+ # Upload a document
173
+ curl -X POST "http://localhost:3000/api/v1/files/upload" \
174
+ -F "file=@spec.pdf"
175
+
176
+ # Delete a file
177
+ curl -X DELETE "http://localhost:3000/api/v1/files" \
178
+ -H "Content-Type: application/json" \
179
+ -d '{"filePath": "/path/to/spec.pdf"}'
180
+
181
+ # Get system status
182
+ curl "http://localhost:3000/api/v1/status"
183
+
184
+ # Health check (for load balancers)
185
+ curl "http://localhost:3000/api/v1/health"
186
+ ```
187
+
188
+ ### Reader API Endpoints
189
+
190
+ For programmatic document reading and cross-document discovery:
191
+
192
+ ```bash
193
+ # Get all chunks for a document (ordered by index)
194
+ curl "http://localhost:3000/api/v1/documents/chunks?filePath=/path/to/doc.pdf"
195
+
196
+ # Find related chunks for cross-document discovery
197
+ curl "http://localhost:3000/api/v1/chunks/related?filePath=/path/to/doc.pdf&chunkIndex=0&limit=5"
198
+
199
+ # Batch request for multiple chunks (efficient for UIs)
200
+ curl -X POST "http://localhost:3000/api/v1/chunks/batch-related" \
201
+ -H "Content-Type: application/json" \
202
+ -d '{"chunks": [{"filePath": "/path/to/doc.pdf", "chunkIndex": 0}], "limit": 3}'
203
+ ```
204
+
205
+ ## Real-World Examples
206
+
207
+ ### Search Your Codebase Documentation
208
+
209
+ ```
210
+ You: "Ingest all the markdown files in /docs"
211
+ AI: Ingested 23 files (847 chunks total)
212
+
213
+ You: "What's the retry policy for failed API calls?"
214
+ AI: According to error-handling.md, failed requests retry 3 times
215
+ with exponential backoff: 1s, 2s, 4s...
216
+ ```
217
+
218
+ ### Index Web Documentation
219
+
220
+ ```
221
+ You: "Fetch https://docs.example.com/api and ingest the HTML"
222
+ AI: Ingested "docs.example.com/api" (156 chunks)
223
+
224
+ You: "What rate limits apply to the /users endpoint?"
225
+ AI: The API limits /users to 100 requests per minute per API key...
226
+ ```
227
+
228
+ ### Build a Personal Knowledge Base
229
+
230
+ ```
231
+ You: "Ingest my research papers folder"
232
+ AI: Ingested 12 PDFs (2,341 chunks)
233
+
234
+ You: "What do recent studies say about transformer attention mechanisms?"
235
+ AI: Based on attention-mechanisms-2024.pdf, the key finding is...
236
+ ```
237
+
238
+ ### Search Exact Technical Terms
239
+
240
+ RAG Vault's hybrid search catches both meaning and exact matches:
241
+
242
+ ```
243
+ You: "Search for ERR_CONNECTION_REFUSED"
244
+ AI: Found 3 results mentioning ERR_CONNECTION_REFUSED:
245
+ 1. troubleshooting.md - "When you see ERR_CONNECTION_REFUSED..."
246
+ 2. network-errors.pdf - "Common causes include..."
247
+ ```
248
+
249
+ Pure semantic search would miss this. RAG Vault finds it.
250
+
251
+ ## How It Works
252
+
253
+ ```
254
+ Document Parse Chunk by meaning → Embed locally → Store in LanceDB
255
+
256
+ Query Embed Vector search Keyword boost → Quality filter → Results
257
+ ```
258
+
259
+ **Smart chunking**: Splits by meaning, not character count. Keeps code blocks intact.
260
+
261
+ **Hybrid search**: Vector similarity finds related content. Keyword boost ranks exact matches higher.
262
+
263
+ **Quality filtering**: Groups results by relevance gaps instead of arbitrary top-K cutoffs.
264
+
265
+ **Local everything**: Embeddings via Transformers.js. Storage via LanceDB. No network after model download.
266
+
267
+ ## Supported Formats
268
+
269
+ | Format | Extension | Notes |
270
+ |--------|-----------|-------|
271
+ | PDF | `.pdf` | Full text extraction, header/footer filtering |
272
+ | Word | `.docx` | Tables, lists, formatting preserved |
273
+ | Markdown | `.md` | Code blocks kept intact |
274
+ | Text | `.txt` | Plain text |
275
+ | JSON | `.json` | Converted to searchable key-value text |
276
+ | HTML | via `ingest_data` | Auto-cleaned with Readability |
277
+
278
+ ## Configuration
279
+
280
+ ### Environment Variables
281
+
282
+ | Variable | Default | What it does |
283
+ |----------|---------|--------------|
284
+ | `BASE_DIR` | Current directory | Only files under this path can be accessed |
285
+ | `DB_PATH` | `./lancedb/` | Where vectors are stored |
286
+ | `MODEL_NAME` | `Xenova/all-MiniLM-L6-v2` | HuggingFace embedding model |
287
+ | `WEB_PORT` | `3000` | Port for web interface |
288
+
289
+ ### Search Tuning
290
+
291
+ | Variable | Default | What it does |
292
+ |----------|---------|--------------|
293
+ | `RAG_HYBRID_WEIGHT` | `0.6` | Keyword boost strength. 0 = semantic-only, higher = stronger boost for exact keyword matches |
294
+ | `RAG_GROUPING` | — | `similar` = top group only, `related` = top 2 groups |
295
+ | `RAG_MAX_DISTANCE` | | Filter out results below this relevance threshold |
296
+
297
+ ### Security (optional)
298
+
299
+ | Variable | Default | What it does |
300
+ |----------|---------|--------------|
301
+ | `RAG_API_KEY` | — | API key for authentication |
302
+ | `CORS_ORIGINS` | localhost | Allowed origins (comma-separated, or `*`) |
303
+ | `RATE_LIMIT_WINDOW_MS` | `60000` | Rate limit time window (ms) |
304
+ | `RATE_LIMIT_MAX_REQUESTS` | `100` | Max requests per window |
305
+
306
+ ### Advanced
307
+
308
+ | Variable | Default | What it does |
309
+ |----------|---------|--------------|
310
+ | `ALLOWED_SCAN_ROOTS` | Home directory | Directories allowed for database scanning |
311
+ | `JSON_BODY_LIMIT` | `5mb` | Max request body size |
312
+ | `REQUEST_TIMEOUT_MS` | `30000` | API request timeout |
313
+ | `REQUEST_LOGGING` | `false` | Enable request audit logging |
314
+
315
+ > Copy [`.env.example`](.env.example) for a complete configuration template.
316
+
317
+ **For code-heavy content**, try:
318
+
319
+ ```json
320
+ "env": {
321
+ "RAG_HYBRID_WEIGHT": "0.8",
322
+ "RAG_GROUPING": "similar"
323
+ }
324
+ ```
325
+
326
+ ## Frequently Asked Questions
327
+
328
+ <details>
329
+ <summary><strong>Is my data really private?</strong></summary>
330
+
331
+ Yes. After the embedding model downloads (~90MB), RAG Vault makes zero network requests. Everything runs on your machine. Verify with network monitoring.
332
+
333
+ </details>
334
+
335
+ <details>
336
+ <summary><strong>Does it work offline?</strong></summary>
337
+
338
+ Yes, after the first run. The model caches locally.
339
+
340
+ </details>
341
+
342
+ <details>
343
+ <summary><strong>What about GPU acceleration?</strong></summary>
344
+
345
+ Transformers.js runs on CPU. GPU support is experimental but unnecessary for most use cases—queries return in ~1 second even with 10,000 chunks.
346
+
347
+ </details>
348
+
349
+ <details>
350
+ <summary><strong>Can I change the embedding model?</strong></summary>
351
+
352
+ Yes. Set `MODEL_NAME` to any compatible HuggingFace model. But you must delete `DB_PATH` and re-ingest—different models produce incompatible vectors.
353
+
354
+ **Recommended upgrade:** For better quality and multilingual support, use [EmbeddingGemma](https://huggingface.co/onnx-community/embeddinggemma-300m-ONNX):
355
+
356
+ ```json
357
+ "MODEL_NAME": "onnx-community/embeddinggemma-300m-ONNX"
358
+ ```
359
+
360
+ This 300M parameter model scores 68.36 on MTEB benchmarks and supports 100+ languages, making it ideal for mixed-language or high-quality retrieval needs.
361
+
362
+ **Other specialized models:**
363
+ - Scientific: `sentence-transformers/allenai-specter`
364
+ - Code: `jinaai/jina-embeddings-v2-base-code`
365
+
366
+ </details>
367
+
368
+ <details>
369
+ <summary><strong>How do I back up my data?</strong></summary>
370
+
371
+ Copy the `DB_PATH` directory (default: `./lancedb/`).
372
+
373
+ </details>
374
+
375
+ ## Troubleshooting
376
+
377
+ | Problem | Solution |
378
+ |---------|----------|
379
+ | No results found | Documents must be ingested first. Run "List all ingested files" to check. |
380
+ | Model download failed | Check internet connection. Model is ~90MB from HuggingFace. |
381
+ | File too large | Default limit is 100MB. Set `MAX_FILE_SIZE` higher or split the file. |
382
+ | Path outside BASE_DIR | All file paths must be under `BASE_DIR`. Use absolute paths. |
383
+ | MCP tools not showing | Verify config syntax, restart your AI tool completely (Cmd+Q on Mac). |
384
+ | 401 Unauthorized | API key required. Set `RAG_API_KEY` or use correct header format. |
385
+ | 429 Too Many Requests | Rate limited. Wait for reset or increase `RATE_LIMIT_MAX_REQUESTS`. |
386
+ | CORS errors | Add your origin to `CORS_ORIGINS` environment variable. |
387
+
388
+ ## Development
389
+
390
+ ```bash
391
+ git clone https://github.com/RobThePCGuy/rag-vault.git
392
+ cd rag-vault
393
+ pnpm install
394
+
395
+ # Run tests
396
+ pnpm test
397
+
398
+ # Type check + lint + format
399
+ pnpm check:all
400
+
401
+ # Build
402
+ pnpm build
403
+
404
+ # Run MCP server locally
405
+ pnpm dev
406
+
407
+ # Run web server locally
408
+ pnpm web:dev
409
+ ```
410
+
411
+ ### Project Structure
412
+
413
+ ```
414
+ src/
415
+ ├── server/ # MCP tool handlers
416
+ ├── vectordb/ # LanceDB + hybrid search
417
+ ├── chunker/ # Semantic text splitting
418
+ ├── embedder/ # Transformers.js wrapper
419
+ ├── parser/ # PDF, DOCX, HTML parsing
420
+ ├── web/ # Express server + REST API
421
+ └── __tests__/ # Test suites
422
+
423
+ web-ui/ # React frontend
424
+ ```
425
+
426
+ ## Documentation
427
+
428
+ - [SECURITY.md](SECURITY.md) — Security configuration and best practices
429
+ - [.env.example](.env.example) — Complete environment variable template
430
+
431
+ ## License
432
+
433
+ MIT — free for personal and commercial use.
434
+
435
+ ## Acknowledgments
436
+
437
+ Built with [Model Context Protocol](https://modelcontextprotocol.io/), [LanceDB](https://lancedb.com/), and [Transformers.js](https://huggingface.co/docs/transformers.js).
438
+
439
+ > Started as a fork of [mcp-local-rag](https://github.com/shinpr/mcp-local-rag) by [Shinsuke Kagawa](https://github.com/shinpr). Now it’s its own thing.
440
+ > Huge credit to upstream contributors for the foundation, I’ve been iterating hard from there.
441
+ > Local-first dev tools, all the way.