rag-lite-ts 1.0.2 → 2.0.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 (202) hide show
  1. package/README.md +606 -93
  2. package/dist/cli/indexer.js +192 -4
  3. package/dist/cli/search.js +50 -11
  4. package/dist/cli.js +183 -26
  5. package/dist/core/abstract-embedder.d.ts +125 -0
  6. package/dist/core/abstract-embedder.js +264 -0
  7. package/dist/core/actionable-error-messages.d.ts +60 -0
  8. package/dist/core/actionable-error-messages.js +397 -0
  9. package/dist/core/batch-processing-optimizer.d.ts +155 -0
  10. package/dist/core/batch-processing-optimizer.js +541 -0
  11. package/dist/core/chunker.d.ts +2 -0
  12. package/dist/core/cli-database-utils.d.ts +53 -0
  13. package/dist/core/cli-database-utils.js +239 -0
  14. package/dist/core/config.js +10 -3
  15. package/dist/core/content-errors.d.ts +111 -0
  16. package/dist/core/content-errors.js +362 -0
  17. package/dist/core/content-manager.d.ts +343 -0
  18. package/dist/core/content-manager.js +1504 -0
  19. package/dist/core/content-performance-optimizer.d.ts +150 -0
  20. package/dist/core/content-performance-optimizer.js +516 -0
  21. package/dist/core/content-resolver.d.ts +104 -0
  22. package/dist/core/content-resolver.js +285 -0
  23. package/dist/core/cross-modal-search.d.ts +164 -0
  24. package/dist/core/cross-modal-search.js +342 -0
  25. package/dist/core/database-connection-manager.d.ts +109 -0
  26. package/dist/core/database-connection-manager.js +304 -0
  27. package/dist/core/db.d.ts +141 -2
  28. package/dist/core/db.js +631 -89
  29. package/dist/core/embedder-factory.d.ts +176 -0
  30. package/dist/core/embedder-factory.js +338 -0
  31. package/dist/core/index.d.ts +3 -1
  32. package/dist/core/index.js +4 -1
  33. package/dist/core/ingestion.d.ts +85 -15
  34. package/dist/core/ingestion.js +510 -45
  35. package/dist/core/lazy-dependency-loader.d.ts +152 -0
  36. package/dist/core/lazy-dependency-loader.js +453 -0
  37. package/dist/core/mode-detection-service.d.ts +150 -0
  38. package/dist/core/mode-detection-service.js +565 -0
  39. package/dist/core/mode-model-validator.d.ts +92 -0
  40. package/dist/core/mode-model-validator.js +203 -0
  41. package/dist/core/model-registry.d.ts +120 -0
  42. package/dist/core/model-registry.js +415 -0
  43. package/dist/core/model-validator.d.ts +217 -0
  44. package/dist/core/model-validator.js +782 -0
  45. package/dist/core/polymorphic-search-factory.d.ts +154 -0
  46. package/dist/core/polymorphic-search-factory.js +344 -0
  47. package/dist/core/raglite-paths.d.ts +121 -0
  48. package/dist/core/raglite-paths.js +145 -0
  49. package/dist/core/reranking-config.d.ts +42 -0
  50. package/dist/core/reranking-config.js +156 -0
  51. package/dist/core/reranking-factory.d.ts +92 -0
  52. package/dist/core/reranking-factory.js +591 -0
  53. package/dist/core/reranking-strategies.d.ts +325 -0
  54. package/dist/core/reranking-strategies.js +720 -0
  55. package/dist/core/resource-cleanup.d.ts +163 -0
  56. package/dist/core/resource-cleanup.js +371 -0
  57. package/dist/core/resource-manager.d.ts +212 -0
  58. package/dist/core/resource-manager.js +564 -0
  59. package/dist/core/search.d.ts +28 -1
  60. package/dist/core/search.js +83 -5
  61. package/dist/core/streaming-operations.d.ts +145 -0
  62. package/dist/core/streaming-operations.js +409 -0
  63. package/dist/core/types.d.ts +3 -0
  64. package/dist/core/universal-embedder.d.ts +177 -0
  65. package/dist/core/universal-embedder.js +139 -0
  66. package/dist/core/validation-messages.d.ts +99 -0
  67. package/dist/core/validation-messages.js +334 -0
  68. package/dist/core/vector-index.js +7 -8
  69. package/dist/factories/index.d.ts +1 -1
  70. package/dist/factories/text-factory.d.ts +128 -34
  71. package/dist/factories/text-factory.js +346 -97
  72. package/dist/file-processor.d.ts +88 -2
  73. package/dist/file-processor.js +720 -17
  74. package/dist/index.d.ts +9 -0
  75. package/dist/index.js +11 -0
  76. package/dist/ingestion.d.ts +16 -0
  77. package/dist/ingestion.js +21 -0
  78. package/dist/mcp-server.d.ts +35 -3
  79. package/dist/mcp-server.js +1107 -31
  80. package/dist/multimodal/clip-embedder.d.ts +314 -0
  81. package/dist/multimodal/clip-embedder.js +945 -0
  82. package/dist/multimodal/index.d.ts +6 -0
  83. package/dist/multimodal/index.js +6 -0
  84. package/dist/run-error-recovery-tests.d.ts +7 -0
  85. package/dist/run-error-recovery-tests.js +101 -0
  86. package/dist/search.d.ts +26 -0
  87. package/dist/search.js +54 -1
  88. package/dist/test-utils.d.ts +8 -26
  89. package/dist/text/chunker.d.ts +1 -0
  90. package/dist/text/embedder.js +15 -8
  91. package/dist/text/index.d.ts +1 -0
  92. package/dist/text/index.js +1 -0
  93. package/dist/text/reranker.d.ts +1 -2
  94. package/dist/text/reranker.js +17 -47
  95. package/dist/text/sentence-transformer-embedder.d.ts +96 -0
  96. package/dist/text/sentence-transformer-embedder.js +340 -0
  97. package/dist/types.d.ts +39 -0
  98. package/dist/utils/vector-math.d.ts +31 -0
  99. package/dist/utils/vector-math.js +70 -0
  100. package/package.json +15 -3
  101. package/dist/api-errors.d.ts.map +0 -1
  102. package/dist/api-errors.js.map +0 -1
  103. package/dist/cli/indexer.d.ts.map +0 -1
  104. package/dist/cli/indexer.js.map +0 -1
  105. package/dist/cli/search.d.ts.map +0 -1
  106. package/dist/cli/search.js.map +0 -1
  107. package/dist/cli.d.ts.map +0 -1
  108. package/dist/cli.js.map +0 -1
  109. package/dist/config.d.ts.map +0 -1
  110. package/dist/config.js.map +0 -1
  111. package/dist/core/adapters.d.ts.map +0 -1
  112. package/dist/core/adapters.js.map +0 -1
  113. package/dist/core/chunker.d.ts.map +0 -1
  114. package/dist/core/chunker.js.map +0 -1
  115. package/dist/core/config.d.ts.map +0 -1
  116. package/dist/core/config.js.map +0 -1
  117. package/dist/core/db.d.ts.map +0 -1
  118. package/dist/core/db.js.map +0 -1
  119. package/dist/core/error-handler.d.ts.map +0 -1
  120. package/dist/core/error-handler.js.map +0 -1
  121. package/dist/core/index.d.ts.map +0 -1
  122. package/dist/core/index.js.map +0 -1
  123. package/dist/core/ingestion.d.ts.map +0 -1
  124. package/dist/core/ingestion.js.map +0 -1
  125. package/dist/core/interfaces.d.ts.map +0 -1
  126. package/dist/core/interfaces.js.map +0 -1
  127. package/dist/core/path-manager.d.ts.map +0 -1
  128. package/dist/core/path-manager.js.map +0 -1
  129. package/dist/core/search-example.d.ts +0 -25
  130. package/dist/core/search-example.d.ts.map +0 -1
  131. package/dist/core/search-example.js +0 -138
  132. package/dist/core/search-example.js.map +0 -1
  133. package/dist/core/search-pipeline-example.d.ts +0 -21
  134. package/dist/core/search-pipeline-example.d.ts.map +0 -1
  135. package/dist/core/search-pipeline-example.js +0 -188
  136. package/dist/core/search-pipeline-example.js.map +0 -1
  137. package/dist/core/search-pipeline.d.ts.map +0 -1
  138. package/dist/core/search-pipeline.js.map +0 -1
  139. package/dist/core/search.d.ts.map +0 -1
  140. package/dist/core/search.js.map +0 -1
  141. package/dist/core/types.d.ts.map +0 -1
  142. package/dist/core/types.js.map +0 -1
  143. package/dist/core/vector-index.d.ts.map +0 -1
  144. package/dist/core/vector-index.js.map +0 -1
  145. package/dist/dom-polyfills.d.ts.map +0 -1
  146. package/dist/dom-polyfills.js.map +0 -1
  147. package/dist/examples/clean-api-examples.d.ts +0 -44
  148. package/dist/examples/clean-api-examples.d.ts.map +0 -1
  149. package/dist/examples/clean-api-examples.js +0 -206
  150. package/dist/examples/clean-api-examples.js.map +0 -1
  151. package/dist/factories/index.d.ts.map +0 -1
  152. package/dist/factories/index.js.map +0 -1
  153. package/dist/factories/text-factory.d.ts.map +0 -1
  154. package/dist/factories/text-factory.js.map +0 -1
  155. package/dist/file-processor.d.ts.map +0 -1
  156. package/dist/file-processor.js.map +0 -1
  157. package/dist/index-manager.d.ts.map +0 -1
  158. package/dist/index-manager.js.map +0 -1
  159. package/dist/index.d.ts.map +0 -1
  160. package/dist/index.js.map +0 -1
  161. package/dist/indexer.d.ts.map +0 -1
  162. package/dist/indexer.js.map +0 -1
  163. package/dist/ingestion.d.ts.map +0 -1
  164. package/dist/ingestion.js.map +0 -1
  165. package/dist/mcp-server.d.ts.map +0 -1
  166. package/dist/mcp-server.js.map +0 -1
  167. package/dist/preprocess.d.ts.map +0 -1
  168. package/dist/preprocess.js.map +0 -1
  169. package/dist/preprocessors/index.d.ts.map +0 -1
  170. package/dist/preprocessors/index.js.map +0 -1
  171. package/dist/preprocessors/mdx.d.ts.map +0 -1
  172. package/dist/preprocessors/mdx.js.map +0 -1
  173. package/dist/preprocessors/mermaid.d.ts.map +0 -1
  174. package/dist/preprocessors/mermaid.js.map +0 -1
  175. package/dist/preprocessors/registry.d.ts.map +0 -1
  176. package/dist/preprocessors/registry.js.map +0 -1
  177. package/dist/search-standalone.d.ts.map +0 -1
  178. package/dist/search-standalone.js.map +0 -1
  179. package/dist/search.d.ts.map +0 -1
  180. package/dist/search.js.map +0 -1
  181. package/dist/test-utils.d.ts.map +0 -1
  182. package/dist/test-utils.js.map +0 -1
  183. package/dist/text/chunker.d.ts.map +0 -1
  184. package/dist/text/chunker.js.map +0 -1
  185. package/dist/text/embedder.d.ts.map +0 -1
  186. package/dist/text/embedder.js.map +0 -1
  187. package/dist/text/index.d.ts.map +0 -1
  188. package/dist/text/index.js.map +0 -1
  189. package/dist/text/preprocessors/index.d.ts.map +0 -1
  190. package/dist/text/preprocessors/index.js.map +0 -1
  191. package/dist/text/preprocessors/mdx.d.ts.map +0 -1
  192. package/dist/text/preprocessors/mdx.js.map +0 -1
  193. package/dist/text/preprocessors/mermaid.d.ts.map +0 -1
  194. package/dist/text/preprocessors/mermaid.js.map +0 -1
  195. package/dist/text/preprocessors/registry.d.ts.map +0 -1
  196. package/dist/text/preprocessors/registry.js.map +0 -1
  197. package/dist/text/reranker.d.ts.map +0 -1
  198. package/dist/text/reranker.js.map +0 -1
  199. package/dist/text/tokenizer.d.ts.map +0 -1
  200. package/dist/text/tokenizer.js.map +0 -1
  201. package/dist/types.d.ts.map +0 -1
  202. package/dist/types.js.map +0 -1
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Database Connection Manager - Centralized connection handling
3
+ * Prevents database locking issues by managing shared connections
4
+ * Addresses production issues with MCP server + CLI concurrent usage
5
+ */
6
+ import { openDatabase } from './db.js';
7
+ /**
8
+ * Database Connection Manager
9
+ * Manages shared database connections to prevent locking issues
10
+ */
11
+ export class DatabaseConnectionManager {
12
+ static connections = new Map();
13
+ static cleanupInterval = null;
14
+ static CLEANUP_INTERVAL = 30000; // 30 seconds
15
+ static MAX_IDLE_TIME = 60000; // 1 minute
16
+ /**
17
+ * Get a shared database connection
18
+ * Creates new connection if none exists, otherwise returns existing
19
+ */
20
+ static async getConnection(dbPath) {
21
+ const normalizedPath = this.normalizePath(dbPath);
22
+ let connectionInfo = this.connections.get(normalizedPath);
23
+ if (!connectionInfo || connectionInfo.isClosing) {
24
+ // Create new connection
25
+ const connection = await openDatabase(dbPath);
26
+ connectionInfo = {
27
+ connection,
28
+ refCount: 1,
29
+ lastAccessed: Date.now(),
30
+ isClosing: false
31
+ };
32
+ this.connections.set(normalizedPath, connectionInfo);
33
+ // Start cleanup timer if this is the first connection
34
+ if (this.connections.size === 1 && !this.cleanupInterval) {
35
+ this.startCleanupTimer();
36
+ }
37
+ console.log(`📊 Database connection created: ${normalizedPath} (total: ${this.connections.size})`);
38
+ }
39
+ else {
40
+ // Reuse existing connection
41
+ connectionInfo.refCount++;
42
+ connectionInfo.lastAccessed = Date.now();
43
+ console.log(`🔄 Database connection reused: ${normalizedPath} (refs: ${connectionInfo.refCount})`);
44
+ }
45
+ return connectionInfo.connection;
46
+ }
47
+ /**
48
+ * Release a database connection reference
49
+ * Connection is kept alive for potential reuse
50
+ */
51
+ static async releaseConnection(dbPath) {
52
+ const normalizedPath = this.normalizePath(dbPath);
53
+ const connectionInfo = this.connections.get(normalizedPath);
54
+ if (connectionInfo && !connectionInfo.isClosing) {
55
+ connectionInfo.refCount = Math.max(0, connectionInfo.refCount - 1);
56
+ connectionInfo.lastAccessed = Date.now();
57
+ console.log(`📉 Database connection released: ${normalizedPath} (refs: ${connectionInfo.refCount})`);
58
+ // Don't immediately close - let cleanup timer handle it
59
+ // This prevents rapid open/close cycles
60
+ }
61
+ }
62
+ /**
63
+ * Force close a specific database connection
64
+ * Use with caution - only for cleanup or error recovery
65
+ */
66
+ static async forceCloseConnection(dbPath) {
67
+ const normalizedPath = this.normalizePath(dbPath);
68
+ const connectionInfo = this.connections.get(normalizedPath);
69
+ if (connectionInfo && !connectionInfo.isClosing) {
70
+ connectionInfo.isClosing = true;
71
+ try {
72
+ await connectionInfo.connection.close();
73
+ console.log(`🔒 Database connection force closed: ${normalizedPath}`);
74
+ }
75
+ catch (error) {
76
+ console.warn(`⚠️ Warning: Error force closing connection ${normalizedPath}:`, error);
77
+ }
78
+ finally {
79
+ this.connections.delete(normalizedPath);
80
+ }
81
+ }
82
+ }
83
+ /**
84
+ * Close all database connections
85
+ * Used during application shutdown
86
+ */
87
+ static async closeAllConnections() {
88
+ if (this.connections.size === 0) {
89
+ return; // Nothing to close
90
+ }
91
+ const isCLI = process.env.RAG_CLI_MODE === 'true';
92
+ if (!isCLI) {
93
+ console.log(`🧹 Closing all database connections (${this.connections.size} active)`);
94
+ }
95
+ const closePromises = [];
96
+ for (const [path, connectionInfo] of this.connections.entries()) {
97
+ if (!connectionInfo.isClosing) {
98
+ connectionInfo.isClosing = true;
99
+ closePromises.push(connectionInfo.connection.close()
100
+ .then(() => {
101
+ if (!isCLI) {
102
+ console.log(`✅ Closed connection: ${path}`);
103
+ }
104
+ })
105
+ .catch(error => {
106
+ if (!isCLI) {
107
+ console.warn(`⚠️ Error closing connection ${path}:`, error);
108
+ }
109
+ }));
110
+ }
111
+ }
112
+ await Promise.all(closePromises);
113
+ this.connections.clear();
114
+ if (this.cleanupInterval) {
115
+ clearInterval(this.cleanupInterval);
116
+ this.cleanupInterval = null;
117
+ }
118
+ if (!isCLI) {
119
+ console.log('✅ All database connections closed');
120
+ }
121
+ }
122
+ /**
123
+ * Get connection statistics for monitoring
124
+ */
125
+ static getConnectionStats() {
126
+ const now = Date.now();
127
+ const connections = Array.from(this.connections.entries()).map(([path, info]) => ({
128
+ path,
129
+ refCount: info.refCount,
130
+ lastAccessed: new Date(info.lastAccessed),
131
+ idleTime: now - info.lastAccessed
132
+ }));
133
+ return {
134
+ totalConnections: this.connections.size,
135
+ connections
136
+ };
137
+ }
138
+ /**
139
+ * Check if a connection exists for a given path
140
+ */
141
+ static hasConnection(dbPath) {
142
+ const normalizedPath = this.normalizePath(dbPath);
143
+ const connectionInfo = this.connections.get(normalizedPath);
144
+ return connectionInfo !== undefined && !connectionInfo.isClosing;
145
+ }
146
+ /**
147
+ * Wait for database to become available
148
+ * Useful for handling temporary locking issues
149
+ */
150
+ static async waitForDatabaseAccess(dbPath, maxWaitMs = 5000) {
151
+ const startTime = Date.now();
152
+ while (Date.now() - startTime < maxWaitMs) {
153
+ try {
154
+ // Try to get a connection
155
+ const connection = await this.getConnection(dbPath);
156
+ await this.releaseConnection(dbPath);
157
+ return; // Success
158
+ }
159
+ catch (error) {
160
+ if (error instanceof Error && error.message.includes('SQLITE_BUSY')) {
161
+ // Wait a bit and retry
162
+ await new Promise(resolve => setTimeout(resolve, 100));
163
+ continue;
164
+ }
165
+ // Other errors should be thrown immediately
166
+ throw error;
167
+ }
168
+ }
169
+ throw new Error(`Database ${dbPath} is busy after ${maxWaitMs}ms. Please try again later.`);
170
+ }
171
+ // =============================================================================
172
+ // PRIVATE METHODS
173
+ // =============================================================================
174
+ /**
175
+ * Normalize database path for consistent key usage
176
+ */
177
+ static normalizePath(dbPath) {
178
+ // Convert to absolute path and normalize separators
179
+ // Use URL constructor for cross-platform path normalization
180
+ try {
181
+ const url = new URL(`file://${dbPath.replace(/\\/g, '/')}`);
182
+ return url.pathname;
183
+ }
184
+ catch {
185
+ // Fallback: simple normalization
186
+ return dbPath.replace(/\\/g, '/');
187
+ }
188
+ }
189
+ /**
190
+ * Start the cleanup timer for idle connections
191
+ * Only start if not in CLI mode to prevent hanging
192
+ */
193
+ static startCleanupTimer() {
194
+ // Don't start cleanup timer for CLI commands - they should exit quickly
195
+ const isCLI = process.argv.some(arg => arg.includes('cli.js') ||
196
+ arg.includes('raglite') ||
197
+ process.env.RAG_CLI_MODE === 'true');
198
+ if (!isCLI) {
199
+ this.cleanupInterval = setInterval(() => {
200
+ this.cleanupIdleConnections();
201
+ }, this.CLEANUP_INTERVAL);
202
+ }
203
+ }
204
+ /**
205
+ * Clean up idle connections that haven't been used recently
206
+ */
207
+ static async cleanupIdleConnections() {
208
+ const now = Date.now();
209
+ const connectionsToClose = [];
210
+ for (const [path, connectionInfo] of this.connections.entries()) {
211
+ const idleTime = now - connectionInfo.lastAccessed;
212
+ // Close connections that are idle and have no active references
213
+ if (connectionInfo.refCount === 0 && idleTime > this.MAX_IDLE_TIME && !connectionInfo.isClosing) {
214
+ connectionsToClose.push(path);
215
+ }
216
+ }
217
+ if (connectionsToClose.length > 0) {
218
+ console.log(`🧹 Cleaning up ${connectionsToClose.length} idle database connections`);
219
+ for (const path of connectionsToClose) {
220
+ await this.forceCloseConnection(path);
221
+ }
222
+ }
223
+ // Stop cleanup timer if no connections remain
224
+ if (this.connections.size === 0 && this.cleanupInterval) {
225
+ clearInterval(this.cleanupInterval);
226
+ this.cleanupInterval = null;
227
+ }
228
+ }
229
+ }
230
+ /**
231
+ * Convenience function to get a managed database connection
232
+ * Use this instead of openDatabase() directly
233
+ */
234
+ export async function getManagedConnection(dbPath) {
235
+ return DatabaseConnectionManager.getConnection(dbPath);
236
+ }
237
+ /**
238
+ * Convenience function to release a managed database connection
239
+ * Use this instead of connection.close() directly
240
+ */
241
+ export async function releaseManagedConnection(dbPath) {
242
+ return DatabaseConnectionManager.releaseConnection(dbPath);
243
+ }
244
+ /**
245
+ * Enhanced database connection wrapper
246
+ * Automatically manages connection lifecycle
247
+ */
248
+ export class ManagedDatabaseConnection {
249
+ dbPath;
250
+ connection = null;
251
+ constructor(dbPath) {
252
+ this.dbPath = dbPath;
253
+ }
254
+ /**
255
+ * Get the underlying database connection
256
+ * Automatically acquires managed connection on first use
257
+ */
258
+ async getConnection() {
259
+ if (!this.connection) {
260
+ this.connection = await DatabaseConnectionManager.getConnection(this.dbPath);
261
+ }
262
+ return this.connection;
263
+ }
264
+ /**
265
+ * Execute a database operation with automatic connection management
266
+ */
267
+ async execute(operation) {
268
+ const connection = await this.getConnection();
269
+ return operation(connection);
270
+ }
271
+ /**
272
+ * Release the managed connection
273
+ * Connection may be kept alive for reuse by other components
274
+ */
275
+ async release() {
276
+ if (this.connection) {
277
+ await DatabaseConnectionManager.releaseConnection(this.dbPath);
278
+ this.connection = null;
279
+ }
280
+ }
281
+ /**
282
+ * Force close the connection
283
+ * Use only during cleanup or error recovery
284
+ */
285
+ async forceClose() {
286
+ if (this.connection) {
287
+ await DatabaseConnectionManager.forceCloseConnection(this.dbPath);
288
+ this.connection = null;
289
+ }
290
+ }
291
+ }
292
+ // =============================================================================
293
+ // PROCESS CLEANUP HANDLERS
294
+ // =============================================================================
295
+ /**
296
+ * Ensure all connections are closed on process exit
297
+ */
298
+ process.on('exit', () => {
299
+ // Synchronous cleanup only
300
+ console.log('🔄 Process exiting, cleaning up database connections...');
301
+ });
302
+ // Don't set up global process handlers - let applications handle their own cleanup
303
+ // This prevents CLI commands from hanging due to active event listeners
304
+ //# sourceMappingURL=database-connection-manager.js.map
package/dist/core/db.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * Model-agnostic. No transformer or modality-specific logic.
4
4
  */
5
5
  import sqlite3 from 'sqlite3';
6
+ import type { SystemInfo } from '../types.js';
6
7
  export interface DatabaseConnection {
7
8
  db: sqlite3.Database;
8
9
  run: (sql: string, params?: any[]) => Promise<sqlite3.RunResult>;
@@ -22,6 +23,7 @@ export interface ContentChunk {
22
23
  document_source: string;
23
24
  document_title: string;
24
25
  document_content_type: string;
26
+ document_content_id?: string;
25
27
  }
26
28
  /**
27
29
  * Opens a SQLite database connection with promisified methods
@@ -42,9 +44,10 @@ export declare function initializeSchema(connection: DatabaseConnection): Promis
42
44
  * @param title - Title of the document
43
45
  * @param contentType - Type of content ('text', 'image', etc.)
44
46
  * @param metadata - Optional metadata object
47
+ * @param contentId - Optional content ID referencing content_metadata table
45
48
  * @returns Promise that resolves to the document ID
46
49
  */
47
- export declare function insertDocument(connection: DatabaseConnection, source: string, title: string, contentType?: string, metadata?: Record<string, any>): Promise<number>;
50
+ export declare function insertDocument(connection: DatabaseConnection, source: string, title: string, contentType?: string, metadata?: Record<string, any>, contentId?: string): Promise<number>;
48
51
  /**
49
52
  * Inserts or updates a chunk in the database with content type support (upsert operation)
50
53
  * @param connection - Database connection object
@@ -64,9 +67,10 @@ export declare function insertChunk(connection: DatabaseConnection, embeddingId:
64
67
  * @param title - Title of the document
65
68
  * @param contentType - Type of content ('text', 'image', etc.)
66
69
  * @param metadata - Optional metadata object
70
+ * @param contentId - Optional content ID referencing content_metadata table
67
71
  * @returns Promise that resolves to the document ID
68
72
  */
69
- export declare function upsertDocument(connection: DatabaseConnection, source: string, title: string, contentType?: string, metadata?: Record<string, any>): Promise<number>;
73
+ export declare function upsertDocument(connection: DatabaseConnection, source: string, title: string, contentType?: string, metadata?: Record<string, any>, contentId?: string): Promise<number>;
70
74
  /**
71
75
  * Retrieves chunks by their embedding IDs with document metadata
72
76
  * Enhanced to include content type information
@@ -76,18 +80,33 @@ export declare function upsertDocument(connection: DatabaseConnection, source: s
76
80
  */
77
81
  export declare function getChunksByEmbeddingIds(connection: DatabaseConnection, embeddingIds: string[]): Promise<ContentChunk[]>;
78
82
  /**
83
+ * Gets the complete system information from system_info table
84
+ * @param connection - Database connection object
85
+ * @returns Promise that resolves to SystemInfo object or null if not set
86
+ */
87
+ export declare function getSystemInfo(connection: DatabaseConnection): Promise<SystemInfo | null>;
88
+ /**
89
+ * Sets the complete system information in system_info table
90
+ * @param connection - Database connection object
91
+ * @param systemInfo - SystemInfo object to store
92
+ */
93
+ export declare function setSystemInfo(connection: DatabaseConnection, systemInfo: Partial<SystemInfo>): Promise<void>;
94
+ /**
95
+ * @deprecated Use getSystemInfo() instead. This function is kept for existing code compatibility.
79
96
  * Gets the current model version from system_info table
80
97
  * @param connection - Database connection object
81
98
  * @returns Promise that resolves to the model version string or null if not set
82
99
  */
83
100
  export declare function getModelVersion(connection: DatabaseConnection): Promise<string | null>;
84
101
  /**
102
+ * @deprecated Use setSystemInfo() instead. This function is kept for existing code compatibility.
85
103
  * Sets the model version in system_info table
86
104
  * @param connection - Database connection object
87
105
  * @param modelVersion - Model version string to store
88
106
  */
89
107
  export declare function setModelVersion(connection: DatabaseConnection, modelVersion: string): Promise<void>;
90
108
  /**
109
+ * @deprecated Use getSystemInfo() instead. This function is kept for existing code compatibility.
91
110
  * Gets the stored model information from system_info table
92
111
  * @param connection - Database connection object
93
112
  * @returns Promise that resolves to model info object or null if not set
@@ -97,10 +116,130 @@ export declare function getStoredModelInfo(connection: DatabaseConnection): Prom
97
116
  dimensions: number;
98
117
  } | null>;
99
118
  /**
119
+ * @deprecated Use setSystemInfo() instead. This function is kept for existing code compatibility.
100
120
  * Sets the model information in system_info table
101
121
  * @param connection - Database connection object
102
122
  * @param modelName - Name of the embedding model
103
123
  * @param dimensions - Number of dimensions for the model
104
124
  */
105
125
  export declare function setStoredModelInfo(connection: DatabaseConnection, modelName: string, dimensions: number): Promise<void>;
126
+ /**
127
+ * Retrieves documents by content type
128
+ * @param connection - Database connection object
129
+ * @param contentType - Content type to filter by
130
+ * @returns Promise that resolves to an array of documents
131
+ */
132
+ export declare function getDocumentsByContentType(connection: DatabaseConnection, contentType: string): Promise<Array<{
133
+ id: number;
134
+ source: string;
135
+ title: string;
136
+ content_type: string;
137
+ metadata?: Record<string, any>;
138
+ created_at: string;
139
+ }>>;
140
+ /**
141
+ * Retrieves chunks by content type
142
+ * @param connection - Database connection object
143
+ * @param contentType - Content type to filter by
144
+ * @returns Promise that resolves to an array of chunks with document metadata
145
+ */
146
+ export declare function getChunksByContentType(connection: DatabaseConnection, contentType: string): Promise<ContentChunk[]>;
147
+ /**
148
+ * Gets content type statistics from the database
149
+ * @param connection - Database connection object
150
+ * @returns Promise that resolves to content type statistics
151
+ */
152
+ export declare function getContentTypeStatistics(connection: DatabaseConnection): Promise<{
153
+ documents: Record<string, number>;
154
+ chunks: Record<string, number>;
155
+ total: {
156
+ documents: number;
157
+ chunks: number;
158
+ };
159
+ }>;
160
+ /**
161
+ * Updates document metadata
162
+ * @param connection - Database connection object
163
+ * @param documentId - ID of the document to update
164
+ * @param metadata - New metadata object
165
+ */
166
+ export declare function updateDocumentMetadata(connection: DatabaseConnection, documentId: number, metadata: Record<string, any>): Promise<void>;
167
+ /**
168
+ * Updates chunk metadata
169
+ * @param connection - Database connection object
170
+ * @param chunkId - ID of the chunk to update
171
+ * @param metadata - New metadata object
172
+ */
173
+ export declare function updateChunkMetadata(connection: DatabaseConnection, chunkId: number, metadata: Record<string, any>): Promise<void>;
174
+ /**
175
+ * Content metadata interface for unified content system
176
+ */
177
+ export interface ContentMetadata {
178
+ id: string;
179
+ storageType: 'filesystem' | 'content_dir';
180
+ originalPath?: string;
181
+ contentPath: string;
182
+ displayName: string;
183
+ contentType: string;
184
+ fileSize: number;
185
+ contentHash: string;
186
+ createdAt: Date;
187
+ }
188
+ /**
189
+ * Inserts content metadata into the content_metadata table
190
+ * @param connection - Database connection object
191
+ * @param contentMetadata - Content metadata to insert
192
+ */
193
+ export declare function insertContentMetadata(connection: DatabaseConnection, contentMetadata: Omit<ContentMetadata, 'createdAt'>): Promise<void>;
194
+ /**
195
+ * Gets content metadata by content ID
196
+ * @param connection - Database connection object
197
+ * @param contentId - Content ID to retrieve
198
+ * @returns Promise that resolves to ContentMetadata or null if not found
199
+ */
200
+ export declare function getContentMetadata(connection: DatabaseConnection, contentId: string): Promise<ContentMetadata | null>;
201
+ /**
202
+ * Gets content metadata by content hash (for deduplication)
203
+ * @param connection - Database connection object
204
+ * @param contentHash - Content hash to search for
205
+ * @returns Promise that resolves to ContentMetadata or null if not found
206
+ */
207
+ export declare function getContentMetadataByHash(connection: DatabaseConnection, contentHash: string): Promise<ContentMetadata | null>;
208
+ /**
209
+ * Gets all content metadata by storage type
210
+ * @param connection - Database connection object
211
+ * @param storageType - Storage type to filter by
212
+ * @returns Promise that resolves to array of ContentMetadata
213
+ */
214
+ export declare function getContentMetadataByStorageType(connection: DatabaseConnection, storageType: 'filesystem' | 'content_dir'): Promise<ContentMetadata[]>;
215
+ /**
216
+ * Deletes content metadata by content ID
217
+ * @param connection - Database connection object
218
+ * @param contentId - Content ID to delete
219
+ * @returns Promise that resolves to true if deleted, false if not found
220
+ */
221
+ export declare function deleteContentMetadata(connection: DatabaseConnection, contentId: string): Promise<boolean>;
222
+ /**
223
+ * Gets storage statistics from storage_stats table
224
+ * @param connection - Database connection object
225
+ * @returns Promise that resolves to storage statistics
226
+ */
227
+ export declare function getStorageStats(connection: DatabaseConnection): Promise<{
228
+ contentDirFiles: number;
229
+ contentDirSize: number;
230
+ filesystemRefs: number;
231
+ lastCleanup: Date | null;
232
+ updatedAt: Date;
233
+ } | null>;
234
+ /**
235
+ * Updates storage statistics in storage_stats table
236
+ * @param connection - Database connection object
237
+ * @param stats - Partial storage statistics to update
238
+ */
239
+ export declare function updateStorageStats(connection: DatabaseConnection, stats: {
240
+ contentDirFiles?: number;
241
+ contentDirSize?: number;
242
+ filesystemRefs?: number;
243
+ lastCleanup?: Date;
244
+ }): Promise<void>;
106
245
  //# sourceMappingURL=db.d.ts.map