rag-lite-ts 2.2.0 → 2.3.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 (50) hide show
  1. package/README.md +88 -5
  2. package/dist/cjs/cli/indexer.js +73 -15
  3. package/dist/cjs/cli/ui-server.d.ts +5 -0
  4. package/dist/cjs/cli/ui-server.js +152 -0
  5. package/dist/cjs/cli.js +25 -6
  6. package/dist/cjs/core/binary-index-format.js +6 -3
  7. package/dist/cjs/core/db.d.ts +56 -0
  8. package/dist/cjs/core/db.js +105 -0
  9. package/dist/cjs/core/ingestion.js +3 -0
  10. package/dist/cjs/core/knowledge-base-manager.d.ts +109 -0
  11. package/dist/cjs/core/knowledge-base-manager.js +256 -0
  12. package/dist/cjs/core/search-pipeline.js +1 -1
  13. package/dist/cjs/core/search.js +1 -1
  14. package/dist/cjs/core/vector-index-messages.d.ts +52 -0
  15. package/dist/cjs/core/vector-index-messages.js +5 -0
  16. package/dist/cjs/core/vector-index-worker.d.ts +6 -0
  17. package/dist/cjs/core/vector-index-worker.js +304 -0
  18. package/dist/cjs/core/vector-index.d.ts +45 -10
  19. package/dist/cjs/core/vector-index.js +229 -218
  20. package/dist/cjs/factories/ingestion-factory.js +3 -7
  21. package/dist/cjs/factories/search-factory.js +11 -0
  22. package/dist/cjs/index-manager.d.ts +23 -3
  23. package/dist/cjs/index-manager.js +84 -15
  24. package/dist/cjs/index.d.ts +2 -1
  25. package/dist/cjs/index.js +3 -1
  26. package/dist/esm/cli/indexer.js +73 -15
  27. package/dist/esm/cli/ui-server.d.ts +5 -0
  28. package/dist/esm/cli/ui-server.js +152 -0
  29. package/dist/esm/cli.js +25 -6
  30. package/dist/esm/core/binary-index-format.js +6 -3
  31. package/dist/esm/core/db.d.ts +56 -0
  32. package/dist/esm/core/db.js +105 -0
  33. package/dist/esm/core/ingestion.js +3 -0
  34. package/dist/esm/core/knowledge-base-manager.d.ts +109 -0
  35. package/dist/esm/core/knowledge-base-manager.js +256 -0
  36. package/dist/esm/core/search-pipeline.js +1 -1
  37. package/dist/esm/core/search.js +1 -1
  38. package/dist/esm/core/vector-index-messages.d.ts +52 -0
  39. package/dist/esm/core/vector-index-messages.js +5 -0
  40. package/dist/esm/core/vector-index-worker.d.ts +6 -0
  41. package/dist/esm/core/vector-index-worker.js +304 -0
  42. package/dist/esm/core/vector-index.d.ts +45 -10
  43. package/dist/esm/core/vector-index.js +229 -218
  44. package/dist/esm/factories/ingestion-factory.js +3 -7
  45. package/dist/esm/factories/search-factory.js +11 -0
  46. package/dist/esm/index-manager.d.ts +23 -3
  47. package/dist/esm/index-manager.js +84 -15
  48. package/dist/esm/index.d.ts +2 -1
  49. package/dist/esm/index.js +3 -1
  50. package/package.json +14 -7
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg?style=flat-square)](https://www.typescriptlang.org/)
12
12
  [![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg?style=flat-square)](https://nodejs.org/)
13
13
 
14
- [Quick Start](#quick-start) • [Features](#features) • [Documentation](#documentation) • [Examples](#examples) • [MCP Integration](#mcp-server-integration)
14
+ [Quick Start](#quick-start) • [Features](#features) • [Documentation](#documentation) • [Examples](#examples) • [UI](#web-interface-ui) • [MCP Integration](#mcp-server-integration)
15
15
 
16
16
  </div>
17
17
 
@@ -27,7 +27,7 @@ raglite ingest ./docs/
27
27
  raglite search "your query here"
28
28
  ```
29
29
 
30
- **That's it.** No API keys, no cloud services, no configuration hell.
30
+ **That's it.** No API keys, no cloud services, no configuration hell. Prefer a UI? Run `raglite ui` for a visual interface with drag‑and‑drop ingestion and search.
31
31
 
32
32
  ### 🎬 See It In Action
33
33
 
@@ -101,6 +101,7 @@ See [CHANGELOG.md](CHANGELOG.md) for complete details.
101
101
  - [How It Works](#-how-it-works)
102
102
  - [Supported Models](#-supported-models)
103
103
  - [Documentation](#-documentation)
104
+ - [Web Interface (UI)](#-web-interface-ui)
104
105
  - [MCP Server Integration](#-mcp-server-integration)
105
106
  - [Development](#-development)
106
107
  - [Contributing](#-contributing)
@@ -114,7 +115,7 @@ See [CHANGELOG.md](CHANGELOG.md) for complete details.
114
115
  npm install -g rag-lite-ts
115
116
  ```
116
117
 
117
- ### Basic Usage
118
+ ### Basic Usage (CLI)
118
119
 
119
120
  ```bash
120
121
  # Ingest documents
@@ -127,11 +128,32 @@ raglite search "machine learning concepts"
127
128
  raglite search "API documentation" --top-k 10 --rerank
128
129
  ```
129
130
 
131
+ ### Web Interface (UI)
132
+
133
+ Launch the visual web interface for interactive document management:
134
+
135
+ ```bash
136
+ # Start the UI (opens in browser)
137
+ raglite ui
138
+
139
+ # UI provides:
140
+ # - Drag & drop file upload
141
+ # - Real-time ingestion progress
142
+ # - Visual search interface
143
+ # - Image search with upload
144
+ # - Knowledge base statistics
145
+ ```
146
+
147
+ → **[Complete UI Guide](docs/ui-guide.md)**
148
+
130
149
  ### Using Different Models
131
150
 
132
151
  ```bash
133
- # Use higher quality model (auto-rebuilds if needed)
134
- raglite ingest ./docs/ --model Xenova/all-mpnet-base-v2 --rebuild-if-needed
152
+ # Use higher quality model
153
+ raglite ingest ./docs/ --model Xenova/all-mpnet-base-v2
154
+
155
+ # Switch models or refresh your data (DESTRUCTIVE: wipes DB+index and rebuilds from scratch)
156
+ raglite ingest ./docs/ --model Xenova/all-mpnet-base-v2 --force-rebuild
135
157
 
136
158
  # Search automatically uses the correct model
137
159
  raglite search "complex query"
@@ -441,6 +463,27 @@ Now Claude can search your docs directly! Works with any MCP-compatible AI tool.
441
463
  - **Model compatibility** - Auto-detection, rebuilds
442
464
  - **Error recovery** - Clear messages, helpful hints
443
465
 
466
+ </td>
467
+ </tr>
468
+ <tr>
469
+ <td width="50%">
470
+
471
+ ### 🎨 Web Interface (UI)
472
+ - **Visual ingestion** - Drag & drop file upload
473
+ - **Real-time progress** - Live ingestion tracking
474
+ - **Image search** - Upload images to find similar content
475
+ - **Interactive search** - Visual results with previews
476
+ - **Knowledge base stats** - Overview of your data
477
+
478
+ </td>
479
+ <td width="50%">
480
+
481
+ ### 📚 Documentation
482
+ - **Comprehensive guides** - CLI, API, multimodal tutorials
483
+ - **Quick start guides** - Get running in minutes
484
+ - **Troubleshooting** - Solutions for common issues
485
+ - **Examples** - Real-world use cases
486
+
444
487
  </td>
445
488
  </tr>
446
489
  </table>
@@ -579,6 +622,7 @@ Choose the right model for your use case:
579
622
 
580
623
  ### 🚀 Getting Started
581
624
  - [CLI Reference](docs/cli-reference.md)
625
+ - [UI Guide](docs/ui-guide.md) 🆕
582
626
  - [API Reference](docs/api-reference.md)
583
627
  - [Multimodal Tutorial](docs/multimodal-tutorial.md)
584
628
  - [Unified Content System](docs/unified-content-system.md)
@@ -610,6 +654,7 @@ Choose the right model for your use case:
610
654
  | I want to... | Start here |
611
655
  |--------------|------------|
612
656
  | 🆕 Try it out | [CLI Reference](docs/cli-reference.md) → `npm i -g rag-lite-ts` |
657
+ | 🎨 Use visual interface | [UI Guide](docs/ui-guide.md) → `raglite ui` |
613
658
  | 🖼️ Search images | [Multimodal Tutorial](docs/multimodal-tutorial.md) → `--mode multimodal` |
614
659
  | 💻 Build an app | [API Reference](docs/api-reference.md) → `new SearchEngine()` |
615
660
  | 🤖 Integrate with AI | [MCP Guide](docs/mcp-server-multimodal-guide.md) → `raglite-mcp` |
@@ -618,6 +663,44 @@ Choose the right model for your use case:
618
663
 
619
664
  **📖 [Complete Documentation Hub](docs/README.md)**
620
665
 
666
+ ## 🎨 Web Interface (UI)
667
+
668
+ RAG-lite TS includes a modern web-based interface for visual document management and search.
669
+
670
+ ### Quick Start
671
+
672
+ ```bash
673
+ # Launch the UI (starts both frontend and backend)
674
+ raglite ui
675
+
676
+ # Opens in browser at http://localhost:3000
677
+ ```
678
+
679
+ ### Features
680
+
681
+ - **📤 Visual Ingestion**: Drag & drop file upload with real-time progress
682
+ - **🔍 Interactive Search**: Text and image search with visual results
683
+ - **📊 Knowledge Base Stats**: Overview of documents, chunks, and model information
684
+ - **⚙️ Configuration**: Visual interface for all ingestion options
685
+ - **🖼️ Image Search**: Upload images to find similar content
686
+ - **📁 Folder Support**: Upload entire directory structures
687
+
688
+ ### UI vs CLI
689
+
690
+ | Feature | UI | CLI |
691
+ |---------|----|----|
692
+ | File upload | ✅ Drag & drop | ✅ Command-line |
693
+ | Progress tracking | ✅ Visual bars | ✅ Console output |
694
+ | Image search | ✅ Upload interface | ✅ File path |
695
+ | Configuration | ✅ Visual options | ✅ Command flags |
696
+ | Batch processing | ✅ | ✅ |
697
+ | Scripting | ❌ | ✅ |
698
+
699
+ **Use UI for:** Interactive exploration, visual feedback, learning the system
700
+ **Use CLI for:** Automation, scripting, headless environments
701
+
702
+ → **[Complete UI Guide](docs/ui-guide.md)**
703
+
621
704
  ## 🔌 MCP Server Integration
622
705
 
623
706
  **Give your AI agents semantic memory.** RAG-lite TS includes a built-in Model Context Protocol (MCP) server.
@@ -80,7 +80,7 @@ async function validateModeConfiguration(options) {
80
80
  */
81
81
  export async function runIngest(path, options = {}) {
82
82
  try {
83
- // Handle --rebuild-if-needed flag immediately to prevent dimension mismatch error
83
+ // Handle --force-rebuild flag immediately to prevent dimension mismatch errors
84
84
  // Validate path exists
85
85
  const resolvedPath = resolve(path);
86
86
  if (!existsSync(resolvedPath)) {
@@ -159,26 +159,52 @@ export async function runIngest(path, options = {}) {
159
159
  factoryOptions.mode = options.mode;
160
160
  console.log(`Using processing mode: ${options.mode}`);
161
161
  }
162
- if (options.rebuildIfNeeded) {
162
+ if (options.forceRebuild) {
163
163
  factoryOptions.forceRebuild = true;
164
- console.log('Force rebuild enabled due to rebuildIfNeeded option');
165
- // Delete old index file immediately to prevent dimension mismatch errors
166
- const indexPath = process.env.RAG_INDEX_FILE || './vector-index.bin';
167
- const { existsSync, unlinkSync } = await import('fs');
168
- if (existsSync(indexPath)) {
169
- try {
170
- unlinkSync(indexPath);
171
- console.log('🗑️ Removed old index file to prevent dimension mismatch');
172
- }
173
- catch (error) {
174
- console.warn(`⚠️ Could not remove old index file: ${error}`);
175
- }
176
- }
164
+ console.log('Force rebuild enabled (--force-rebuild)');
177
165
  }
178
166
  // Validate mode-specific model and strategy combinations
179
167
  await validateModeConfiguration(factoryOptions);
180
168
  const dbPath = process.env.RAG_DB_FILE || './db.sqlite';
181
169
  const indexPath = process.env.RAG_INDEX_FILE || './vector-index.bin';
170
+ // --force-rebuild: Always delete DB (and sidecars) and index to guarantee a clean rebuild.
171
+ if (options.forceRebuild) {
172
+ try {
173
+ const { existsSync: fsExistsSync, unlinkSync } = await import('fs');
174
+ console.log('🗑️ Deleting existing database and index to perform a clean rebuild...');
175
+ // Remove WAL/SHM if present (common on SQLite with WAL journaling).
176
+ const sidecars = [`${dbPath}-wal`, `${dbPath}-shm`];
177
+ for (const p of sidecars) {
178
+ if (fsExistsSync(p)) {
179
+ try {
180
+ unlinkSync(p);
181
+ }
182
+ catch (e) {
183
+ console.warn(`⚠️ Could not remove SQLite sidecar file (${p}):`, e);
184
+ }
185
+ }
186
+ }
187
+ if (fsExistsSync(dbPath)) {
188
+ try {
189
+ unlinkSync(dbPath);
190
+ }
191
+ catch (e) {
192
+ console.warn(`⚠️ Could not remove database file (${dbPath}):`, e);
193
+ }
194
+ }
195
+ if (fsExistsSync(indexPath)) {
196
+ try {
197
+ unlinkSync(indexPath);
198
+ }
199
+ catch (e) {
200
+ console.warn(`⚠️ Could not remove index file (${indexPath}):`, e);
201
+ }
202
+ }
203
+ }
204
+ catch (error) {
205
+ console.warn('⚠️ Could not delete existing database/index for clean rebuild:', error instanceof Error ? error.message : String(error));
206
+ }
207
+ }
182
208
  // Setup graceful cleanup
183
209
  setupCLICleanup(dbPath);
184
210
  // Check if database is busy before starting
@@ -218,6 +244,22 @@ export async function runIngest(path, options = {}) {
218
244
  console.log(`Processing rate: ${chunksPerSecond} chunks/second`);
219
245
  }
220
246
  console.log('\nIngestion completed successfully!');
247
+ // Run VACUUM to compact the SQLite database after ingestion
248
+ try {
249
+ const { openDatabase } = await import('../core/db.js');
250
+ const vacuumDb = await openDatabase(dbPath);
251
+ try {
252
+ console.log('Running VACUUM to optimize database size...');
253
+ await vacuumDb.run('VACUUM');
254
+ console.log('VACUUM completed successfully.');
255
+ }
256
+ finally {
257
+ await vacuumDb.close();
258
+ }
259
+ }
260
+ catch (vacuumError) {
261
+ console.warn('⚠️ VACUUM operation failed or was skipped:', vacuumError instanceof Error ? vacuumError.message : String(vacuumError));
262
+ }
221
263
  // Display mode-specific information
222
264
  const mode = options.mode || 'text';
223
265
  if (mode === 'multimodal') {
@@ -397,6 +439,22 @@ export async function runRebuild() {
397
439
  console.log('All embeddings have been regenerated with the current model.');
398
440
  console.log('');
399
441
  console.log('You can now search your documents using: raglite search "your query"');
442
+ // Run VACUUM to compact the SQLite database after rebuild
443
+ try {
444
+ const { openDatabase } = await import('../core/db.js');
445
+ const vacuumDb = await openDatabase(dbPath);
446
+ try {
447
+ console.log('Running VACUUM to optimize database size after rebuild...');
448
+ await vacuumDb.run('VACUUM');
449
+ console.log('VACUUM completed successfully.');
450
+ }
451
+ finally {
452
+ await vacuumDb.close();
453
+ }
454
+ }
455
+ catch (vacuumError) {
456
+ console.warn('⚠️ VACUUM operation failed or was skipped:', vacuumError instanceof Error ? vacuumError.message : String(vacuumError));
457
+ }
400
458
  }
401
459
  finally {
402
460
  await db.close();
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Launch the UI server
3
+ */
4
+ export declare function runUI(options?: any): Promise<void>;
5
+ //# sourceMappingURL=ui-server.d.ts.map
@@ -0,0 +1,152 @@
1
+ import { fileURLToPath } from 'url';
2
+ import { dirname, join } from 'path';
3
+ import { spawn } from 'child_process';
4
+ import fs from 'fs';
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ /**
8
+ * Get the project root directory
9
+ * When built, CLI is at dist/esm/cli/ui-server.js, so go up 3 levels
10
+ * When running from source, CLI is at src/cli/ui-server.ts, so go up 2 levels
11
+ */
12
+ function getProjectRoot() {
13
+ // Try going up 3 levels first (for built version)
14
+ const builtPath = join(__dirname, '../../..');
15
+ if (fs.existsSync(join(builtPath, 'package.json'))) {
16
+ return builtPath;
17
+ }
18
+ // Fallback: go up 2 levels (for source execution)
19
+ return join(__dirname, '../..');
20
+ }
21
+ /**
22
+ * Launch the UI server
23
+ */
24
+ export async function runUI(options = {}) {
25
+ const port = options.port || 3000;
26
+ const backendPort = options.backendPort || 3001;
27
+ console.log('🚀 Launching RAG-lite TS UI...');
28
+ // Resolve UI paths from project root
29
+ const projectRoot = getProjectRoot();
30
+ const backendBuiltPath = join(projectRoot, 'ui', 'backend', 'dist', 'index.js');
31
+ const backendSourcePath = join(projectRoot, 'ui', 'backend', 'src', 'index.ts');
32
+ const frontendBuiltPath = join(projectRoot, 'ui', 'frontend', 'dist');
33
+ const frontendSourcePath = join(projectRoot, 'ui', 'frontend');
34
+ // Check if built files exist
35
+ const useBuiltBackend = fs.existsSync(backendBuiltPath);
36
+ const useBuiltFrontend = fs.existsSync(frontendBuiltPath);
37
+ if (!useBuiltBackend && !fs.existsSync(backendSourcePath)) {
38
+ console.error(`❌ UI backend not found at: ${backendSourcePath}`);
39
+ console.error(' Make sure the UI is set up in the ui/ directory.');
40
+ process.exit(1);
41
+ }
42
+ if (!useBuiltFrontend && !fs.existsSync(frontendSourcePath)) {
43
+ console.error(`❌ UI frontend not found at: ${frontendSourcePath}`);
44
+ console.error(' Make sure the UI is set up in the ui/ directory.');
45
+ process.exit(1);
46
+ }
47
+ // Pass the working directory where 'raglite ui' was called to the backend
48
+ const workingDir = process.cwd();
49
+ // Built mode: single server on port (UI + API). Dev mode: backend on backendPort, frontend on port.
50
+ const effectiveBackendPort = useBuiltFrontend ? port : backendPort;
51
+ console.log(`📡 Starting backend on port ${effectiveBackendPort}...`);
52
+ // Start backend server - use built version if available
53
+ const backendCommand = useBuiltBackend ? 'node' : 'npx';
54
+ const backendArgs = useBuiltBackend
55
+ ? [backendBuiltPath]
56
+ : ['tsx', backendSourcePath];
57
+ const backendProcess = spawn(backendCommand, backendArgs, {
58
+ stdio: 'pipe',
59
+ env: {
60
+ ...process.env,
61
+ PORT: effectiveBackendPort.toString(),
62
+ RAG_WORKING_DIR: workingDir,
63
+ UI_FRONTEND_DIST: useBuiltFrontend ? frontendBuiltPath : undefined
64
+ },
65
+ shell: true
66
+ });
67
+ backendProcess.on('error', (err) => {
68
+ console.error('❌ Failed to start backend process:', err);
69
+ process.exit(1);
70
+ });
71
+ // Forward backend output with prefix
72
+ backendProcess.stdout?.on('data', (data) => {
73
+ process.stdout.write(`[Backend] ${data}`);
74
+ });
75
+ backendProcess.stderr?.on('data', (data) => {
76
+ process.stderr.write(`[Backend] ${data}`);
77
+ });
78
+ // Only start frontend dev server if built version doesn't exist
79
+ let frontendProcess = null;
80
+ if (!useBuiltFrontend) {
81
+ console.log(`🎨 Starting frontend dev server on port ${port}...`);
82
+ frontendProcess = spawn('npm', ['run', 'dev'], {
83
+ cwd: frontendSourcePath,
84
+ stdio: 'pipe',
85
+ env: {
86
+ ...process.env,
87
+ VITE_API_URL: `http://localhost:${effectiveBackendPort}`
88
+ },
89
+ shell: true
90
+ });
91
+ frontendProcess.on('error', (err) => {
92
+ console.error('❌ Failed to start frontend process:', err);
93
+ backendProcess.kill();
94
+ process.exit(1);
95
+ });
96
+ // Forward frontend output with prefix
97
+ frontendProcess.stdout?.on('data', (data) => {
98
+ process.stdout.write(`[Frontend] ${data}`);
99
+ });
100
+ frontendProcess.stderr?.on('data', (data) => {
101
+ process.stderr.write(`[Frontend] ${data}`);
102
+ });
103
+ }
104
+ else {
105
+ console.log(`🎨 Using built frontend from ${frontendBuiltPath}`);
106
+ console.log(` Frontend will be served by backend on port ${effectiveBackendPort}`);
107
+ }
108
+ // Wait a bit for servers to start
109
+ await new Promise(resolve => setTimeout(resolve, 2000));
110
+ console.log(`\n✨ UI Access:`);
111
+ if (useBuiltFrontend) {
112
+ console.log(` Frontend & Backend: http://localhost:${port}`);
113
+ }
114
+ else {
115
+ console.log(` Frontend: http://localhost:${port}`);
116
+ console.log(` Backend: http://localhost:${effectiveBackendPort}`);
117
+ }
118
+ console.log(`\n💡 Press Ctrl+C to stop both servers\n`);
119
+ // Keep the process alive and handle cleanup
120
+ return new Promise((resolve) => {
121
+ const cleanup = () => {
122
+ console.log('\n🛑 Shutting down servers...');
123
+ backendProcess.kill();
124
+ if (frontendProcess) {
125
+ frontendProcess.kill();
126
+ }
127
+ resolve();
128
+ };
129
+ process.on('SIGINT', cleanup);
130
+ process.on('SIGTERM', cleanup);
131
+ // Handle process exits
132
+ backendProcess.on('exit', (code) => {
133
+ if (code !== 0 && code !== null) {
134
+ console.error(`\n❌ Backend process exited with code ${code}`);
135
+ if (frontendProcess) {
136
+ frontendProcess.kill();
137
+ }
138
+ resolve();
139
+ }
140
+ });
141
+ if (frontendProcess) {
142
+ frontendProcess.on('exit', (code) => {
143
+ if (code !== 0 && code !== null) {
144
+ console.error(`\n❌ Frontend process exited with code ${code}`);
145
+ backendProcess.kill();
146
+ resolve();
147
+ }
148
+ });
149
+ }
150
+ });
151
+ }
152
+ //# sourceMappingURL=ui-server.js.map
package/dist/cjs/cli.js CHANGED
@@ -6,8 +6,18 @@ import { EXIT_CODES, ConfigurationError } from './core/config.js';
6
6
  // Get package.json for version info
7
7
  const __filename = fileURLToPath(import.meta.url);
8
8
  const __dirname = dirname(__filename);
9
- const packageJsonPath = join(__dirname, '..', 'package.json');
10
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
9
+ // When built, CLI is at dist/esm/cli.js, so go up two levels to root
10
+ // When running from source, CLI is at src/cli.ts, so go up one level to root
11
+ const packageJsonPath = join(__dirname, '..', '..', 'package.json');
12
+ let packageJson;
13
+ try {
14
+ packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
15
+ }
16
+ catch {
17
+ // Fallback: try one level up (for source execution)
18
+ const fallbackPath = join(__dirname, '..', 'package.json');
19
+ packageJson = JSON.parse(readFileSync(fallbackPath, 'utf-8'));
20
+ }
11
21
  /**
12
22
  * Display version information
13
23
  */
@@ -28,6 +38,7 @@ Usage:
28
38
  Commands:
29
39
  ingest <path> Ingest documents from file or directory
30
40
  search <query> Search indexed documents (text or image)
41
+ ui Launch the web interface
31
42
  rebuild Rebuild the vector index
32
43
  version Show version information
33
44
  help Show this help message
@@ -43,6 +54,7 @@ Examples:
43
54
  raglite search "red car" --content-type image # Search only image results
44
55
  raglite search ./photo.jpg # Search with image (multimodal mode only)
45
56
  raglite search ./image.png --top-k 5 # Find similar images
57
+ raglite ui # Launch web interface
46
58
 
47
59
  raglite rebuild # Rebuild the entire index
48
60
 
@@ -55,7 +67,7 @@ Options for search:
55
67
  Options for ingest:
56
68
  --model <name> Use specific embedding model
57
69
  --mode <mode> Processing mode: 'text' (default) or 'multimodal'
58
- --rebuild-if-needed Automatically rebuild if model mismatch detected (WARNING: rebuilds entire index)
70
+ --force-rebuild Wipe DB+index and rebuild from scratch (DESTRUCTIVE)
59
71
  --path-strategy <strategy> Path storage strategy: 'relative' (default) or 'absolute'
60
72
  --path-base <path> Base directory for relative paths (defaults to current directory)
61
73
 
@@ -111,8 +123,8 @@ function parseArgs() {
111
123
  else if (optionName === 'no-rerank') {
112
124
  options.rerank = false;
113
125
  }
114
- else if (optionName === 'rebuild-if-needed') {
115
- options.rebuildIfNeeded = true;
126
+ else if (optionName === 'force-rebuild') {
127
+ options.forceRebuild = true;
116
128
  }
117
129
  else if (optionName === 'help') {
118
130
  return { command: 'help', args: [], options: {} };
@@ -169,7 +181,7 @@ function validateArgs(command, args, options) {
169
181
  console.error('Options:');
170
182
  console.error(' --model <name> Use specific embedding model');
171
183
  console.error(' --mode <mode> Processing mode: text (default) or multimodal');
172
- console.error(' --rebuild-if-needed Automatically rebuild if model mismatch detected');
184
+ console.error(' --force-rebuild Wipe DB+index and rebuild from scratch (DESTRUCTIVE)');
173
185
  console.error('');
174
186
  console.error('The path can be either a file (.md or .txt) or a directory.');
175
187
  process.exit(EXIT_CODES.INVALID_ARGUMENTS);
@@ -201,6 +213,9 @@ function validateArgs(command, args, options) {
201
213
  case 'rebuild':
202
214
  // No arguments required
203
215
  break;
216
+ case 'ui':
217
+ // No arguments required
218
+ break;
204
219
  case 'version':
205
220
  // No validation needed
206
221
  break;
@@ -412,6 +427,10 @@ async function main() {
412
427
  const { runRebuild } = await import('./cli/indexer.js');
413
428
  await runRebuild();
414
429
  break;
430
+ case 'ui':
431
+ const { runUI } = await import('./cli/ui-server.js');
432
+ await runUI(options);
433
+ break;
415
434
  default:
416
435
  console.error(`Error: Unknown command '${command}'`);
417
436
  process.exit(1);
@@ -27,10 +27,12 @@ export class BinaryIndexFormat {
27
27
  * @param data Index data to serialize
28
28
  */
29
29
  static async save(indexPath, data) {
30
- // Calculate total size
30
+ // Use actual vector count to ensure accurate file size
31
+ const actualVectorCount = data.vectors.length;
32
+ // Calculate total size based on actual vectors
31
33
  const headerSize = 24; // 6 uint32 fields
32
34
  const vectorSize = 4 + (data.dimensions * 4); // id + vector
33
- const totalSize = headerSize + (data.currentSize * vectorSize);
35
+ const totalSize = headerSize + (actualVectorCount * vectorSize);
34
36
  const buffer = new ArrayBuffer(totalSize);
35
37
  const view = new DataView(buffer);
36
38
  let offset = 0;
@@ -45,7 +47,8 @@ export class BinaryIndexFormat {
45
47
  offset += 4;
46
48
  view.setUint32(offset, data.seed, true);
47
49
  offset += 4;
48
- view.setUint32(offset, data.currentSize, true);
50
+ // Write actual vector count in header
51
+ view.setUint32(offset, actualVectorCount, true);
49
52
  offset += 4;
50
53
  // Write vectors
51
54
  for (const item of data.vectors) {
@@ -210,4 +210,60 @@ export declare function updateStorageStats(connection: DatabaseConnection, stats
210
210
  filesystemRefs?: number;
211
211
  lastCleanup?: Date;
212
212
  }): Promise<void>;
213
+ /**
214
+ * Result of a database reset operation
215
+ */
216
+ export interface DatabaseResetResult {
217
+ /** Whether the reset was successful */
218
+ success: boolean;
219
+ /** Number of documents deleted */
220
+ documentsDeleted: number;
221
+ /** Number of chunks deleted */
222
+ chunksDeleted: number;
223
+ /** Number of content metadata entries deleted */
224
+ contentMetadataDeleted: number;
225
+ /** Whether system_info was preserved or cleared */
226
+ systemInfoCleared: boolean;
227
+ /** Time taken for the reset operation in milliseconds */
228
+ resetTimeMs: number;
229
+ }
230
+ /**
231
+ * Options for database reset operation
232
+ */
233
+ export interface DatabaseResetOptions {
234
+ /** Whether to preserve system_info (mode, model configuration) - default: false */
235
+ preserveSystemInfo?: boolean;
236
+ /** Whether to run VACUUM after deletion to reclaim space - default: true */
237
+ runVacuum?: boolean;
238
+ }
239
+ /**
240
+ * Reset the database by deleting all data while keeping the schema intact.
241
+ * This is a safer alternative to file deletion that avoids file locking issues on Windows.
242
+ *
243
+ * This function:
244
+ * 1. Deletes all rows from chunks, documents, content_metadata tables
245
+ * 2. Optionally clears system_info (mode/model configuration)
246
+ * 3. Resets storage_stats counters
247
+ * 4. Optionally runs VACUUM to reclaim disk space
248
+ *
249
+ * @param connection - Database connection object
250
+ * @param options - Reset options
251
+ * @returns Promise resolving to reset result statistics
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * const db = await openDatabase('./db.sqlite');
256
+ * const result = await resetDatabase(db, { preserveSystemInfo: false });
257
+ * console.log(`Deleted ${result.documentsDeleted} documents and ${result.chunksDeleted} chunks`);
258
+ * ```
259
+ */
260
+ export declare function resetDatabase(connection: DatabaseConnection, options?: DatabaseResetOptions): Promise<DatabaseResetResult>;
261
+ /**
262
+ * Check if the database has any data (documents, chunks, or content)
263
+ * Useful for determining if a reset is needed
264
+ *
265
+ * @param connection - Database connection object
266
+ * @returns Promise resolving to true if database has data, false if empty
267
+ */
268
+ export declare function hasDatabaseData(connection: DatabaseConnection): Promise<boolean>;
213
269
  //# sourceMappingURL=db.d.ts.map