rag-lite-ts 2.1.1 → 2.2.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 (309) hide show
  1. package/dist/{core → cjs/core}/model-validator.js +1 -1
  2. package/dist/{core → cjs/core}/vector-index.js +4 -2
  3. package/dist/esm/api-errors.d.ts +90 -0
  4. package/dist/esm/api-errors.js +320 -0
  5. package/dist/esm/cli/indexer.d.ts +11 -0
  6. package/dist/esm/cli/indexer.js +471 -0
  7. package/dist/esm/cli/search.d.ts +7 -0
  8. package/dist/esm/cli/search.js +332 -0
  9. package/dist/esm/cli.d.ts +3 -0
  10. package/dist/esm/cli.js +529 -0
  11. package/dist/esm/config.d.ts +51 -0
  12. package/dist/esm/config.js +79 -0
  13. package/dist/esm/core/abstract-embedder.d.ts +125 -0
  14. package/dist/esm/core/abstract-embedder.js +264 -0
  15. package/dist/esm/core/actionable-error-messages.d.ts +60 -0
  16. package/dist/esm/core/actionable-error-messages.js +397 -0
  17. package/dist/esm/core/adapters.d.ts +93 -0
  18. package/dist/esm/core/adapters.js +139 -0
  19. package/dist/esm/core/batch-processing-optimizer.d.ts +155 -0
  20. package/dist/esm/core/batch-processing-optimizer.js +536 -0
  21. package/dist/esm/core/binary-index-format.d.ts +78 -0
  22. package/dist/esm/core/binary-index-format.js +291 -0
  23. package/dist/esm/core/chunker.d.ts +119 -0
  24. package/dist/esm/core/chunker.js +73 -0
  25. package/dist/esm/core/cli-database-utils.d.ts +53 -0
  26. package/dist/esm/core/cli-database-utils.js +239 -0
  27. package/dist/esm/core/config.d.ts +102 -0
  28. package/dist/esm/core/config.js +247 -0
  29. package/dist/esm/core/content-errors.d.ts +111 -0
  30. package/dist/esm/core/content-errors.js +362 -0
  31. package/dist/esm/core/content-manager.d.ts +335 -0
  32. package/dist/esm/core/content-manager.js +1476 -0
  33. package/dist/esm/core/content-performance-optimizer.d.ts +150 -0
  34. package/dist/esm/core/content-performance-optimizer.js +516 -0
  35. package/dist/esm/core/content-resolver.d.ts +104 -0
  36. package/dist/esm/core/content-resolver.js +285 -0
  37. package/dist/esm/core/cross-modal-search.d.ts +164 -0
  38. package/dist/esm/core/cross-modal-search.js +342 -0
  39. package/dist/esm/core/database-connection-manager.d.ts +109 -0
  40. package/dist/esm/core/database-connection-manager.js +310 -0
  41. package/dist/esm/core/db.d.ts +213 -0
  42. package/dist/esm/core/db.js +895 -0
  43. package/dist/esm/core/embedder-factory.d.ts +154 -0
  44. package/dist/esm/core/embedder-factory.js +311 -0
  45. package/dist/esm/core/error-handler.d.ts +112 -0
  46. package/dist/esm/core/error-handler.js +239 -0
  47. package/dist/esm/core/index.d.ts +59 -0
  48. package/dist/esm/core/index.js +69 -0
  49. package/dist/esm/core/ingestion.d.ts +202 -0
  50. package/dist/esm/core/ingestion.js +901 -0
  51. package/dist/esm/core/interfaces.d.ts +408 -0
  52. package/dist/esm/core/interfaces.js +106 -0
  53. package/dist/esm/core/lazy-dependency-loader.d.ts +147 -0
  54. package/dist/esm/core/lazy-dependency-loader.js +435 -0
  55. package/dist/esm/core/mode-detection-service.d.ts +150 -0
  56. package/dist/esm/core/mode-detection-service.js +565 -0
  57. package/dist/esm/core/mode-model-validator.d.ts +92 -0
  58. package/dist/esm/core/mode-model-validator.js +203 -0
  59. package/dist/esm/core/model-registry.d.ts +116 -0
  60. package/dist/esm/core/model-registry.js +411 -0
  61. package/dist/esm/core/model-validator.d.ts +217 -0
  62. package/dist/esm/core/model-validator.js +782 -0
  63. package/dist/esm/core/path-manager.d.ts +47 -0
  64. package/dist/esm/core/path-manager.js +71 -0
  65. package/dist/esm/core/raglite-paths.d.ts +121 -0
  66. package/dist/esm/core/raglite-paths.js +145 -0
  67. package/dist/esm/core/reranking-config.d.ts +42 -0
  68. package/dist/esm/core/reranking-config.js +147 -0
  69. package/dist/esm/core/reranking-factory.d.ts +92 -0
  70. package/dist/esm/core/reranking-factory.js +410 -0
  71. package/dist/esm/core/reranking-strategies.d.ts +310 -0
  72. package/dist/esm/core/reranking-strategies.js +650 -0
  73. package/dist/esm/core/resource-cleanup.d.ts +163 -0
  74. package/dist/esm/core/resource-cleanup.js +371 -0
  75. package/dist/esm/core/resource-manager.d.ts +212 -0
  76. package/dist/esm/core/resource-manager.js +564 -0
  77. package/dist/esm/core/search-pipeline.d.ts +111 -0
  78. package/dist/esm/core/search-pipeline.js +287 -0
  79. package/dist/esm/core/search.d.ts +141 -0
  80. package/dist/esm/core/search.js +320 -0
  81. package/dist/esm/core/streaming-operations.d.ts +145 -0
  82. package/dist/esm/core/streaming-operations.js +409 -0
  83. package/dist/esm/core/types.d.ts +66 -0
  84. package/dist/esm/core/types.js +6 -0
  85. package/dist/esm/core/universal-embedder.d.ts +177 -0
  86. package/dist/esm/core/universal-embedder.js +139 -0
  87. package/dist/esm/core/validation-messages.d.ts +99 -0
  88. package/dist/esm/core/validation-messages.js +334 -0
  89. package/dist/esm/core/vector-index.d.ts +72 -0
  90. package/dist/esm/core/vector-index.js +333 -0
  91. package/dist/esm/dom-polyfills.d.ts +6 -0
  92. package/dist/esm/dom-polyfills.js +37 -0
  93. package/dist/esm/factories/index.d.ts +27 -0
  94. package/dist/esm/factories/index.js +29 -0
  95. package/dist/esm/factories/ingestion-factory.d.ts +200 -0
  96. package/dist/esm/factories/ingestion-factory.js +477 -0
  97. package/dist/esm/factories/search-factory.d.ts +154 -0
  98. package/dist/esm/factories/search-factory.js +344 -0
  99. package/dist/esm/file-processor.d.ts +147 -0
  100. package/dist/esm/file-processor.js +963 -0
  101. package/dist/esm/index-manager.d.ts +116 -0
  102. package/dist/esm/index-manager.js +598 -0
  103. package/dist/esm/index.d.ts +75 -0
  104. package/dist/esm/index.js +110 -0
  105. package/dist/esm/indexer.d.ts +7 -0
  106. package/dist/esm/indexer.js +54 -0
  107. package/dist/esm/ingestion.d.ts +63 -0
  108. package/dist/esm/ingestion.js +124 -0
  109. package/dist/esm/mcp-server.d.ts +46 -0
  110. package/dist/esm/mcp-server.js +1820 -0
  111. package/dist/esm/multimodal/clip-embedder.d.ts +327 -0
  112. package/dist/esm/multimodal/clip-embedder.js +996 -0
  113. package/dist/esm/multimodal/index.d.ts +6 -0
  114. package/dist/esm/multimodal/index.js +6 -0
  115. package/dist/esm/preprocess.d.ts +19 -0
  116. package/dist/esm/preprocess.js +203 -0
  117. package/dist/esm/preprocessors/index.d.ts +17 -0
  118. package/dist/esm/preprocessors/index.js +38 -0
  119. package/dist/esm/preprocessors/mdx.d.ts +25 -0
  120. package/dist/esm/preprocessors/mdx.js +101 -0
  121. package/dist/esm/preprocessors/mermaid.d.ts +68 -0
  122. package/dist/esm/preprocessors/mermaid.js +329 -0
  123. package/dist/esm/preprocessors/registry.d.ts +56 -0
  124. package/dist/esm/preprocessors/registry.js +179 -0
  125. package/dist/esm/run-error-recovery-tests.d.ts +7 -0
  126. package/dist/esm/run-error-recovery-tests.js +101 -0
  127. package/dist/esm/search-standalone.d.ts +7 -0
  128. package/dist/esm/search-standalone.js +117 -0
  129. package/dist/esm/search.d.ts +99 -0
  130. package/dist/esm/search.js +177 -0
  131. package/dist/esm/test-utils.d.ts +18 -0
  132. package/dist/esm/test-utils.js +27 -0
  133. package/dist/esm/text/chunker.d.ts +33 -0
  134. package/dist/esm/text/chunker.js +279 -0
  135. package/dist/esm/text/embedder.d.ts +111 -0
  136. package/dist/esm/text/embedder.js +386 -0
  137. package/dist/esm/text/index.d.ts +8 -0
  138. package/dist/esm/text/index.js +9 -0
  139. package/dist/esm/text/preprocessors/index.d.ts +17 -0
  140. package/dist/esm/text/preprocessors/index.js +38 -0
  141. package/dist/esm/text/preprocessors/mdx.d.ts +25 -0
  142. package/dist/esm/text/preprocessors/mdx.js +101 -0
  143. package/dist/esm/text/preprocessors/mermaid.d.ts +68 -0
  144. package/dist/esm/text/preprocessors/mermaid.js +330 -0
  145. package/dist/esm/text/preprocessors/registry.d.ts +56 -0
  146. package/dist/esm/text/preprocessors/registry.js +180 -0
  147. package/dist/esm/text/reranker.d.ts +49 -0
  148. package/dist/esm/text/reranker.js +274 -0
  149. package/dist/esm/text/sentence-transformer-embedder.d.ts +96 -0
  150. package/dist/esm/text/sentence-transformer-embedder.js +340 -0
  151. package/dist/esm/text/tokenizer.d.ts +22 -0
  152. package/dist/esm/text/tokenizer.js +64 -0
  153. package/dist/esm/types.d.ts +83 -0
  154. package/dist/esm/types.js +3 -0
  155. package/dist/esm/utils/vector-math.d.ts +31 -0
  156. package/dist/esm/utils/vector-math.js +70 -0
  157. package/package.json +30 -12
  158. /package/dist/{api-errors.d.ts → cjs/api-errors.d.ts} +0 -0
  159. /package/dist/{api-errors.js → cjs/api-errors.js} +0 -0
  160. /package/dist/{cli → cjs/cli}/indexer.d.ts +0 -0
  161. /package/dist/{cli → cjs/cli}/indexer.js +0 -0
  162. /package/dist/{cli → cjs/cli}/search.d.ts +0 -0
  163. /package/dist/{cli → cjs/cli}/search.js +0 -0
  164. /package/dist/{cli.d.ts → cjs/cli.d.ts} +0 -0
  165. /package/dist/{cli.js → cjs/cli.js} +0 -0
  166. /package/dist/{config.d.ts → cjs/config.d.ts} +0 -0
  167. /package/dist/{config.js → cjs/config.js} +0 -0
  168. /package/dist/{core → cjs/core}/abstract-embedder.d.ts +0 -0
  169. /package/dist/{core → cjs/core}/abstract-embedder.js +0 -0
  170. /package/dist/{core → cjs/core}/actionable-error-messages.d.ts +0 -0
  171. /package/dist/{core → cjs/core}/actionable-error-messages.js +0 -0
  172. /package/dist/{core → cjs/core}/adapters.d.ts +0 -0
  173. /package/dist/{core → cjs/core}/adapters.js +0 -0
  174. /package/dist/{core → cjs/core}/batch-processing-optimizer.d.ts +0 -0
  175. /package/dist/{core → cjs/core}/batch-processing-optimizer.js +0 -0
  176. /package/dist/{core → cjs/core}/binary-index-format.d.ts +0 -0
  177. /package/dist/{core → cjs/core}/binary-index-format.js +0 -0
  178. /package/dist/{core → cjs/core}/chunker.d.ts +0 -0
  179. /package/dist/{core → cjs/core}/chunker.js +0 -0
  180. /package/dist/{core → cjs/core}/cli-database-utils.d.ts +0 -0
  181. /package/dist/{core → cjs/core}/cli-database-utils.js +0 -0
  182. /package/dist/{core → cjs/core}/config.d.ts +0 -0
  183. /package/dist/{core → cjs/core}/config.js +0 -0
  184. /package/dist/{core → cjs/core}/content-errors.d.ts +0 -0
  185. /package/dist/{core → cjs/core}/content-errors.js +0 -0
  186. /package/dist/{core → cjs/core}/content-manager.d.ts +0 -0
  187. /package/dist/{core → cjs/core}/content-manager.js +0 -0
  188. /package/dist/{core → cjs/core}/content-performance-optimizer.d.ts +0 -0
  189. /package/dist/{core → cjs/core}/content-performance-optimizer.js +0 -0
  190. /package/dist/{core → cjs/core}/content-resolver.d.ts +0 -0
  191. /package/dist/{core → cjs/core}/content-resolver.js +0 -0
  192. /package/dist/{core → cjs/core}/cross-modal-search.d.ts +0 -0
  193. /package/dist/{core → cjs/core}/cross-modal-search.js +0 -0
  194. /package/dist/{core → cjs/core}/database-connection-manager.d.ts +0 -0
  195. /package/dist/{core → cjs/core}/database-connection-manager.js +0 -0
  196. /package/dist/{core → cjs/core}/db.d.ts +0 -0
  197. /package/dist/{core → cjs/core}/db.js +0 -0
  198. /package/dist/{core → cjs/core}/embedder-factory.d.ts +0 -0
  199. /package/dist/{core → cjs/core}/embedder-factory.js +0 -0
  200. /package/dist/{core → cjs/core}/error-handler.d.ts +0 -0
  201. /package/dist/{core → cjs/core}/error-handler.js +0 -0
  202. /package/dist/{core → cjs/core}/index.d.ts +0 -0
  203. /package/dist/{core → cjs/core}/index.js +0 -0
  204. /package/dist/{core → cjs/core}/ingestion.d.ts +0 -0
  205. /package/dist/{core → cjs/core}/ingestion.js +0 -0
  206. /package/dist/{core → cjs/core}/interfaces.d.ts +0 -0
  207. /package/dist/{core → cjs/core}/interfaces.js +0 -0
  208. /package/dist/{core → cjs/core}/lazy-dependency-loader.d.ts +0 -0
  209. /package/dist/{core → cjs/core}/lazy-dependency-loader.js +0 -0
  210. /package/dist/{core → cjs/core}/mode-detection-service.d.ts +0 -0
  211. /package/dist/{core → cjs/core}/mode-detection-service.js +0 -0
  212. /package/dist/{core → cjs/core}/mode-model-validator.d.ts +0 -0
  213. /package/dist/{core → cjs/core}/mode-model-validator.js +0 -0
  214. /package/dist/{core → cjs/core}/model-registry.d.ts +0 -0
  215. /package/dist/{core → cjs/core}/model-registry.js +0 -0
  216. /package/dist/{core → cjs/core}/model-validator.d.ts +0 -0
  217. /package/dist/{core → cjs/core}/path-manager.d.ts +0 -0
  218. /package/dist/{core → cjs/core}/path-manager.js +0 -0
  219. /package/dist/{core → cjs/core}/raglite-paths.d.ts +0 -0
  220. /package/dist/{core → cjs/core}/raglite-paths.js +0 -0
  221. /package/dist/{core → cjs/core}/reranking-config.d.ts +0 -0
  222. /package/dist/{core → cjs/core}/reranking-config.js +0 -0
  223. /package/dist/{core → cjs/core}/reranking-factory.d.ts +0 -0
  224. /package/dist/{core → cjs/core}/reranking-factory.js +0 -0
  225. /package/dist/{core → cjs/core}/reranking-strategies.d.ts +0 -0
  226. /package/dist/{core → cjs/core}/reranking-strategies.js +0 -0
  227. /package/dist/{core → cjs/core}/resource-cleanup.d.ts +0 -0
  228. /package/dist/{core → cjs/core}/resource-cleanup.js +0 -0
  229. /package/dist/{core → cjs/core}/resource-manager.d.ts +0 -0
  230. /package/dist/{core → cjs/core}/resource-manager.js +0 -0
  231. /package/dist/{core → cjs/core}/search-pipeline.d.ts +0 -0
  232. /package/dist/{core → cjs/core}/search-pipeline.js +0 -0
  233. /package/dist/{core → cjs/core}/search.d.ts +0 -0
  234. /package/dist/{core → cjs/core}/search.js +0 -0
  235. /package/dist/{core → cjs/core}/streaming-operations.d.ts +0 -0
  236. /package/dist/{core → cjs/core}/streaming-operations.js +0 -0
  237. /package/dist/{core → cjs/core}/types.d.ts +0 -0
  238. /package/dist/{core → cjs/core}/types.js +0 -0
  239. /package/dist/{core → cjs/core}/universal-embedder.d.ts +0 -0
  240. /package/dist/{core → cjs/core}/universal-embedder.js +0 -0
  241. /package/dist/{core → cjs/core}/validation-messages.d.ts +0 -0
  242. /package/dist/{core → cjs/core}/validation-messages.js +0 -0
  243. /package/dist/{core → cjs/core}/vector-index.d.ts +0 -0
  244. /package/dist/{dom-polyfills.d.ts → cjs/dom-polyfills.d.ts} +0 -0
  245. /package/dist/{dom-polyfills.js → cjs/dom-polyfills.js} +0 -0
  246. /package/dist/{factories → cjs/factories}/index.d.ts +0 -0
  247. /package/dist/{factories → cjs/factories}/index.js +0 -0
  248. /package/dist/{factories → cjs/factories}/ingestion-factory.d.ts +0 -0
  249. /package/dist/{factories → cjs/factories}/ingestion-factory.js +0 -0
  250. /package/dist/{factories → cjs/factories}/search-factory.d.ts +0 -0
  251. /package/dist/{factories → cjs/factories}/search-factory.js +0 -0
  252. /package/dist/{file-processor.d.ts → cjs/file-processor.d.ts} +0 -0
  253. /package/dist/{file-processor.js → cjs/file-processor.js} +0 -0
  254. /package/dist/{index-manager.d.ts → cjs/index-manager.d.ts} +0 -0
  255. /package/dist/{index-manager.js → cjs/index-manager.js} +0 -0
  256. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  257. /package/dist/{index.js → cjs/index.js} +0 -0
  258. /package/dist/{indexer.d.ts → cjs/indexer.d.ts} +0 -0
  259. /package/dist/{indexer.js → cjs/indexer.js} +0 -0
  260. /package/dist/{ingestion.d.ts → cjs/ingestion.d.ts} +0 -0
  261. /package/dist/{ingestion.js → cjs/ingestion.js} +0 -0
  262. /package/dist/{mcp-server.d.ts → cjs/mcp-server.d.ts} +0 -0
  263. /package/dist/{mcp-server.js → cjs/mcp-server.js} +0 -0
  264. /package/dist/{multimodal → cjs/multimodal}/clip-embedder.d.ts +0 -0
  265. /package/dist/{multimodal → cjs/multimodal}/clip-embedder.js +0 -0
  266. /package/dist/{multimodal → cjs/multimodal}/index.d.ts +0 -0
  267. /package/dist/{multimodal → cjs/multimodal}/index.js +0 -0
  268. /package/dist/{preprocess.d.ts → cjs/preprocess.d.ts} +0 -0
  269. /package/dist/{preprocess.js → cjs/preprocess.js} +0 -0
  270. /package/dist/{preprocessors → cjs/preprocessors}/index.d.ts +0 -0
  271. /package/dist/{preprocessors → cjs/preprocessors}/index.js +0 -0
  272. /package/dist/{preprocessors → cjs/preprocessors}/mdx.d.ts +0 -0
  273. /package/dist/{preprocessors → cjs/preprocessors}/mdx.js +0 -0
  274. /package/dist/{preprocessors → cjs/preprocessors}/mermaid.d.ts +0 -0
  275. /package/dist/{preprocessors → cjs/preprocessors}/mermaid.js +0 -0
  276. /package/dist/{preprocessors → cjs/preprocessors}/registry.d.ts +0 -0
  277. /package/dist/{preprocessors → cjs/preprocessors}/registry.js +0 -0
  278. /package/dist/{run-error-recovery-tests.d.ts → cjs/run-error-recovery-tests.d.ts} +0 -0
  279. /package/dist/{run-error-recovery-tests.js → cjs/run-error-recovery-tests.js} +0 -0
  280. /package/dist/{search-standalone.d.ts → cjs/search-standalone.d.ts} +0 -0
  281. /package/dist/{search-standalone.js → cjs/search-standalone.js} +0 -0
  282. /package/dist/{search.d.ts → cjs/search.d.ts} +0 -0
  283. /package/dist/{search.js → cjs/search.js} +0 -0
  284. /package/dist/{test-utils.d.ts → cjs/test-utils.d.ts} +0 -0
  285. /package/dist/{test-utils.js → cjs/test-utils.js} +0 -0
  286. /package/dist/{text → cjs/text}/chunker.d.ts +0 -0
  287. /package/dist/{text → cjs/text}/chunker.js +0 -0
  288. /package/dist/{text → cjs/text}/embedder.d.ts +0 -0
  289. /package/dist/{text → cjs/text}/embedder.js +0 -0
  290. /package/dist/{text → cjs/text}/index.d.ts +0 -0
  291. /package/dist/{text → cjs/text}/index.js +0 -0
  292. /package/dist/{text → cjs/text}/preprocessors/index.d.ts +0 -0
  293. /package/dist/{text → cjs/text}/preprocessors/index.js +0 -0
  294. /package/dist/{text → cjs/text}/preprocessors/mdx.d.ts +0 -0
  295. /package/dist/{text → cjs/text}/preprocessors/mdx.js +0 -0
  296. /package/dist/{text → cjs/text}/preprocessors/mermaid.d.ts +0 -0
  297. /package/dist/{text → cjs/text}/preprocessors/mermaid.js +0 -0
  298. /package/dist/{text → cjs/text}/preprocessors/registry.d.ts +0 -0
  299. /package/dist/{text → cjs/text}/preprocessors/registry.js +0 -0
  300. /package/dist/{text → cjs/text}/reranker.d.ts +0 -0
  301. /package/dist/{text → cjs/text}/reranker.js +0 -0
  302. /package/dist/{text → cjs/text}/sentence-transformer-embedder.d.ts +0 -0
  303. /package/dist/{text → cjs/text}/sentence-transformer-embedder.js +0 -0
  304. /package/dist/{text → cjs/text}/tokenizer.d.ts +0 -0
  305. /package/dist/{text → cjs/text}/tokenizer.js +0 -0
  306. /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
  307. /package/dist/{types.js → cjs/types.js} +0 -0
  308. /package/dist/{utils → cjs/utils}/vector-math.d.ts +0 -0
  309. /package/dist/{utils → cjs/utils}/vector-math.js +0 -0
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Content Resolver - Handles content retrieval and format adaptation for unified content system
3
+ * Resolves content IDs to actual content locations and adapts format based on client needs
4
+ * Supports efficient batch retrieval operations and handles missing content gracefully
5
+ */
6
+ import { DatabaseConnection, type ContentMetadata } from './db.js';
7
+ export type { ContentMetadata };
8
+ /**
9
+ * Content request for batch operations
10
+ */
11
+ export interface ContentRequest {
12
+ contentId: string;
13
+ format: 'file' | 'base64';
14
+ }
15
+ /**
16
+ * Content result for batch operations
17
+ */
18
+ export interface ContentResult {
19
+ contentId: string;
20
+ success: boolean;
21
+ content?: string;
22
+ error?: string;
23
+ }
24
+ /**
25
+ * ContentResolver class for handling content retrieval and format conversion
26
+ * Implements format-adaptive content retrieval for CLI and MCP clients
27
+ */
28
+ export declare class ContentResolver {
29
+ private db;
30
+ private streamingOps;
31
+ private performanceOptimizer;
32
+ constructor(db: DatabaseConnection);
33
+ /**
34
+ * Retrieves content by ID and adapts format based on client needs
35
+ * @param contentId - Content ID to retrieve
36
+ * @param format - Format to return ('file' for CLI clients, 'base64' for MCP clients)
37
+ * @returns Promise that resolves to content in requested format
38
+ */
39
+ getContent(contentId: string, format?: 'file' | 'base64'): Promise<string>;
40
+ /**
41
+ * Retrieves multiple content items efficiently in batch with performance optimizations
42
+ * @param requests - Array of content requests with IDs and formats
43
+ * @returns Promise that resolves to array of content results
44
+ */
45
+ getContentBatch(requests: ContentRequest[]): Promise<ContentResult[]>;
46
+ /**
47
+ * Fallback batch processing implementation
48
+ * @param requests - Array of content requests
49
+ * @returns Promise that resolves to array of content results
50
+ */
51
+ private getContentBatchFallback;
52
+ /**
53
+ * Retrieves content metadata without loading the actual content
54
+ * @param contentId - Content ID to get metadata for
55
+ * @returns Promise that resolves to content metadata
56
+ */
57
+ getContentMetadata(contentId: string): Promise<ContentMetadata>;
58
+ /**
59
+ * Verifies that content exists and is accessible
60
+ * @param contentId - Content ID to verify
61
+ * @returns Promise that resolves to true if content exists, false otherwise
62
+ */
63
+ verifyContentExists(contentId: string): Promise<boolean>;
64
+ /**
65
+ * Gets performance statistics for batch operations and content retrieval
66
+ * @returns Performance statistics
67
+ */
68
+ getPerformanceStats(): {
69
+ batchOperations: {
70
+ totalOperations: number;
71
+ averageDuration: number;
72
+ totalBytesProcessed: number;
73
+ averageSpeed: number;
74
+ errorRate: number;
75
+ };
76
+ contentRetrieval: {
77
+ totalRetrievals: number;
78
+ averageDuration: number;
79
+ cacheHitRate: number;
80
+ };
81
+ };
82
+ /**
83
+ * Clears performance caches and resets metrics
84
+ */
85
+ clearPerformanceCaches(): void;
86
+ /**
87
+ * Returns content as file path for CLI clients
88
+ * @param metadata - Content metadata
89
+ * @returns File path that can be accessed directly
90
+ */
91
+ private getContentAsFilePath;
92
+ /**
93
+ * Returns content as base64 string for MCP clients with optimized I/O
94
+ * @param metadata - Content metadata
95
+ * @returns Base64-encoded content ready for display
96
+ */
97
+ private getContentAsBase64;
98
+ /**
99
+ * Cleanup resources to prevent memory leaks and hanging processes
100
+ * Should be called when ContentResolver is no longer needed
101
+ */
102
+ cleanup(): void;
103
+ }
104
+ //# sourceMappingURL=content-resolver.d.ts.map
@@ -0,0 +1,285 @@
1
+ /**
2
+ * Content Resolver - Handles content retrieval and format adaptation for unified content system
3
+ * Resolves content IDs to actual content locations and adapts format based on client needs
4
+ * Supports efficient batch retrieval operations and handles missing content gracefully
5
+ */
6
+ import { promises as fs } from 'fs';
7
+ import { getContentMetadata } from './db.js';
8
+ import { ContentNotFoundError, ContentRetrievalError, ContentErrorHandler } from './content-errors.js';
9
+ import { withTimeout, SafeBuffer } from './resource-cleanup.js';
10
+ import { createStreamingOperations, formatBytes, formatProcessingTime, calculateProcessingSpeed } from './streaming-operations.js';
11
+ import { createContentPerformanceOptimizer, formatProcessingSpeed } from './content-performance-optimizer.js';
12
+ /**
13
+ * ContentResolver class for handling content retrieval and format conversion
14
+ * Implements format-adaptive content retrieval for CLI and MCP clients
15
+ */
16
+ export class ContentResolver {
17
+ db;
18
+ streamingOps;
19
+ performanceOptimizer;
20
+ constructor(db) {
21
+ this.db = db;
22
+ // Initialize streaming operations for content retrieval
23
+ this.streamingOps = createStreamingOperations({
24
+ chunkSize: 256 * 1024, // 256KB chunks for retrieval operations
25
+ enableProgress: false,
26
+ enableHashing: false,
27
+ timeout: 300000 // 5 minutes
28
+ });
29
+ // Initialize performance optimizer for batch operations and caching
30
+ this.performanceOptimizer = createContentPerformanceOptimizer({
31
+ hashCacheSize: 500, // Smaller cache for resolver
32
+ hashCacheTTL: 30 * 60 * 1000, // 30 minutes TTL
33
+ maxConcurrentOperations: 15, // Higher concurrency for retrieval
34
+ batchSize: 25,
35
+ fileBufferSize: 256 * 1024,
36
+ enableAsyncIO: true,
37
+ enableMetrics: true,
38
+ metricsRetentionTime: 12 * 60 * 60 * 1000 // 12 hours
39
+ });
40
+ }
41
+ /**
42
+ * Retrieves content by ID and adapts format based on client needs
43
+ * @param contentId - Content ID to retrieve
44
+ * @param format - Format to return ('file' for CLI clients, 'base64' for MCP clients)
45
+ * @returns Promise that resolves to content in requested format
46
+ */
47
+ async getContent(contentId, format = 'file') {
48
+ try {
49
+ // Validate format parameter
50
+ if (format !== 'file' && format !== 'base64') {
51
+ throw new ContentRetrievalError(contentId, format, 'Format must be either "file" or "base64"', 'format_validation');
52
+ }
53
+ // Get content metadata with timeout
54
+ const metadata = await withTimeout(getContentMetadata(this.db, contentId), 10000, // 10 second timeout for database query
55
+ 'Database query for content metadata timed out');
56
+ if (!metadata) {
57
+ throw new ContentNotFoundError(contentId, undefined, 'metadata_lookup');
58
+ }
59
+ // Check if content file exists with timeout
60
+ const contentExists = await withTimeout(this.verifyContentExists(contentId), 5000, // 5 second timeout for file verification
61
+ 'Content file verification timed out');
62
+ if (!contentExists) {
63
+ throw new ContentNotFoundError(contentId, metadata.displayName, 'file_verification');
64
+ }
65
+ // Return content in requested format with timeout
66
+ if (format === 'file') {
67
+ return await withTimeout(this.getContentAsFilePath(metadata), 5000, // 5 second timeout for file path resolution
68
+ 'File path resolution timed out');
69
+ }
70
+ else {
71
+ return await withTimeout(this.getContentAsBase64(metadata), 30000, // 30 second timeout for base64 conversion (can be slow for large files)
72
+ 'Base64 conversion timed out');
73
+ }
74
+ }
75
+ catch (error) {
76
+ if (error instanceof ContentNotFoundError || error instanceof ContentRetrievalError) {
77
+ throw error; // Re-throw content-specific errors
78
+ }
79
+ ContentErrorHandler.handleContentError(error, 'content retrieval', 'getContent');
80
+ }
81
+ }
82
+ /**
83
+ * Retrieves multiple content items efficiently in batch with performance optimizations
84
+ * @param requests - Array of content requests with IDs and formats
85
+ * @returns Promise that resolves to array of content results
86
+ */
87
+ async getContentBatch(requests) {
88
+ const startTime = Date.now();
89
+ try {
90
+ // Use performance optimizer for batch processing
91
+ const batchResult = await this.performanceOptimizer.processBatchOptimized(requests, async (request) => {
92
+ try {
93
+ const content = await this.getContent(request.contentId, request.format);
94
+ return {
95
+ contentId: request.contentId,
96
+ success: true,
97
+ content
98
+ };
99
+ }
100
+ catch (error) {
101
+ return {
102
+ contentId: request.contentId,
103
+ success: false,
104
+ error: error instanceof Error ? error.message : 'Unknown error'
105
+ };
106
+ }
107
+ }, {
108
+ batchSize: 25, // Optimized batch size for content retrieval
109
+ maxConcurrency: 15, // Higher concurrency for I/O operations
110
+ enableMetrics: true
111
+ });
112
+ // Log performance metrics for large batches
113
+ if (requests.length > 10) {
114
+ const duration = Date.now() - startTime;
115
+ const speed = batchResult.averageSpeed;
116
+ console.log(`Batch retrieval completed: ${requests.length} items in ${formatProcessingTime(duration)} ` +
117
+ `(${batchResult.successCount} success, ${batchResult.errorCount} errors, ${formatProcessingSpeed(speed)})`);
118
+ }
119
+ return batchResult.results;
120
+ }
121
+ catch (error) {
122
+ // Fallback to original implementation if optimization fails
123
+ console.warn('Batch optimization failed, using fallback:', error);
124
+ return this.getContentBatchFallback(requests);
125
+ }
126
+ }
127
+ /**
128
+ * Fallback batch processing implementation
129
+ * @param requests - Array of content requests
130
+ * @returns Promise that resolves to array of content results
131
+ */
132
+ async getContentBatchFallback(requests) {
133
+ const results = [];
134
+ const concurrencyLimit = 10;
135
+ const batches = [];
136
+ for (let i = 0; i < requests.length; i += concurrencyLimit) {
137
+ batches.push(requests.slice(i, i + concurrencyLimit));
138
+ }
139
+ for (const batch of batches) {
140
+ const batchPromises = batch.map(async (request) => {
141
+ try {
142
+ const content = await this.getContent(request.contentId, request.format);
143
+ return {
144
+ contentId: request.contentId,
145
+ success: true,
146
+ content
147
+ };
148
+ }
149
+ catch (error) {
150
+ return {
151
+ contentId: request.contentId,
152
+ success: false,
153
+ error: error instanceof Error ? error.message : 'Unknown error'
154
+ };
155
+ }
156
+ });
157
+ const batchResults = await Promise.all(batchPromises);
158
+ results.push(...batchResults);
159
+ }
160
+ return results;
161
+ }
162
+ /**
163
+ * Retrieves content metadata without loading the actual content
164
+ * @param contentId - Content ID to get metadata for
165
+ * @returns Promise that resolves to content metadata
166
+ */
167
+ async getContentMetadata(contentId) {
168
+ const metadata = await getContentMetadata(this.db, contentId);
169
+ if (!metadata) {
170
+ throw new ContentNotFoundError(contentId, undefined, 'metadata_retrieval');
171
+ }
172
+ return metadata;
173
+ }
174
+ /**
175
+ * Verifies that content exists and is accessible
176
+ * @param contentId - Content ID to verify
177
+ * @returns Promise that resolves to true if content exists, false otherwise
178
+ */
179
+ async verifyContentExists(contentId) {
180
+ try {
181
+ const metadata = await getContentMetadata(this.db, contentId);
182
+ if (!metadata) {
183
+ return false;
184
+ }
185
+ // Check if the content file exists and is accessible
186
+ try {
187
+ const stats = await fs.stat(metadata.contentPath);
188
+ return stats.isFile();
189
+ }
190
+ catch {
191
+ return false;
192
+ }
193
+ }
194
+ catch {
195
+ return false;
196
+ }
197
+ }
198
+ /**
199
+ * Gets performance statistics for batch operations and content retrieval
200
+ * @returns Performance statistics
201
+ */
202
+ getPerformanceStats() {
203
+ const batchStats = this.performanceOptimizer.getPerformanceStats('batch_processing');
204
+ const retrievalStats = this.performanceOptimizer.getPerformanceStats('file_read');
205
+ return {
206
+ batchOperations: batchStats,
207
+ contentRetrieval: {
208
+ totalRetrievals: retrievalStats.totalOperations,
209
+ averageDuration: retrievalStats.averageDuration,
210
+ cacheHitRate: retrievalStats.cacheHitRate
211
+ }
212
+ };
213
+ }
214
+ /**
215
+ * Clears performance caches and resets metrics
216
+ */
217
+ clearPerformanceCaches() {
218
+ this.performanceOptimizer.clearHashCache();
219
+ }
220
+ // =============================================================================
221
+ // PRIVATE METHODS
222
+ // =============================================================================
223
+ /**
224
+ * Returns content as file path for CLI clients
225
+ * @param metadata - Content metadata
226
+ * @returns File path that can be accessed directly
227
+ */
228
+ async getContentAsFilePath(metadata) {
229
+ // For both filesystem and content_dir storage, return the content path
230
+ // CLI clients can access files directly regardless of storage type
231
+ return metadata.contentPath;
232
+ }
233
+ /**
234
+ * Returns content as base64 string for MCP clients with optimized I/O
235
+ * @param metadata - Content metadata
236
+ * @returns Base64-encoded content ready for display
237
+ */
238
+ async getContentAsBase64(metadata) {
239
+ let safeBuffer = null;
240
+ try {
241
+ // Use optimized file reading for better performance
242
+ if (metadata.fileSize > 10 * 1024 * 1024) { // Use streaming for files > 10MB
243
+ const startTime = Date.now();
244
+ const base64Content = await withTimeout(this.streamingOps.readFileAsBase64Streaming(metadata.contentPath), 300000, // 5 minute timeout for large file base64 conversion
245
+ 'Streaming base64 conversion timed out');
246
+ const processingTime = Date.now() - startTime;
247
+ const speed = calculateProcessingSpeed(metadata.fileSize, processingTime);
248
+ // Log performance metrics for large files
249
+ if (metadata.fileSize > 50 * 1024 * 1024) {
250
+ console.log(`Optimized base64 conversion completed: ${formatBytes(metadata.fileSize)} in ${formatProcessingTime(processingTime)} (${formatProcessingSpeed(speed)})`);
251
+ }
252
+ return base64Content;
253
+ }
254
+ else {
255
+ // For smaller files, use traditional method with memory management
256
+ const content = await fs.readFile(metadata.contentPath);
257
+ // Use safe buffer for memory management (don't clear original for normal operations)
258
+ safeBuffer = new SafeBuffer(content, { clearOriginal: false });
259
+ // Convert to base64
260
+ const base64Content = safeBuffer.get().toString('base64');
261
+ return base64Content;
262
+ }
263
+ }
264
+ catch (error) {
265
+ throw new ContentRetrievalError(metadata.id, 'base64', `Failed to read content file: ${error instanceof Error ? error.message : 'Unknown error'}`, 'file_reading');
266
+ }
267
+ finally {
268
+ // Clear sensitive buffer data
269
+ if (safeBuffer) {
270
+ safeBuffer.clear();
271
+ }
272
+ }
273
+ }
274
+ /**
275
+ * Cleanup resources to prevent memory leaks and hanging processes
276
+ * Should be called when ContentResolver is no longer needed
277
+ */
278
+ cleanup() {
279
+ // Clean up performance optimizer interval that prevents process exit
280
+ if (this.performanceOptimizer && typeof this.performanceOptimizer.cleanup === 'function') {
281
+ this.performanceOptimizer.cleanup();
282
+ }
283
+ }
284
+ }
285
+ //# sourceMappingURL=content-resolver.js.map
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Cross-Modal Search Implementation
3
+ *
4
+ * This module extends the core SearchEngine to provide cross-modal search capabilities
5
+ * that enable text queries to find images and image queries to find text content.
6
+ *
7
+ * Task 4.2: Implement cross-modal search functionality
8
+ * - Update search logic to handle mixed content type results
9
+ * - Ensure ranking works properly across text and image content
10
+ * - Test text queries finding relevant images and vice versa
11
+ *
12
+ * Requirements addressed:
13
+ * - 6.1: Enable text queries to find relevant image content
14
+ * - 6.2: Enable image queries to find relevant text content
15
+ * - 6.3: Rank mixed content types by semantic similarity
16
+ */
17
+ import { SearchEngine } from './search.js';
18
+ import type { SearchResult, SearchOptions } from './types.js';
19
+ import type { EmbedFunction, RerankFunction } from './interfaces.js';
20
+ /**
21
+ * Extended search options for cross-modal search
22
+ */
23
+ export interface CrossModalSearchOptions extends SearchOptions {
24
+ /** Content types to include in search results */
25
+ includeContentTypes?: string[];
26
+ /** Whether to enable cross-modal ranking */
27
+ enableCrossModalRanking?: boolean;
28
+ /** Minimum similarity threshold for cross-modal results */
29
+ crossModalThreshold?: number;
30
+ }
31
+ /**
32
+ * Cross-modal search result with enhanced metadata
33
+ */
34
+ export interface CrossModalSearchResult extends SearchResult {
35
+ /** Whether this result is from a different modality than the query */
36
+ isCrossModal?: boolean;
37
+ /** Semantic similarity score for cross-modal ranking */
38
+ semanticSimilarity?: number;
39
+ /** Original vector search score before cross-modal adjustments */
40
+ originalScore?: number;
41
+ }
42
+ /**
43
+ * Cross-Modal Search Engine
44
+ *
45
+ * Extends the core SearchEngine to provide cross-modal search capabilities.
46
+ * This implementation enables:
47
+ * - Text queries finding semantically similar images
48
+ * - Image queries finding semantically similar text
49
+ * - Mixed content type results ranked by semantic similarity
50
+ * - Unified embedding space leveraging CLIP models
51
+ */
52
+ export declare class CrossModalSearchEngine extends SearchEngine {
53
+ private embedder?;
54
+ constructor(embedFn: EmbedFunction, indexManager: any, db: any, rerankFn?: RerankFunction, contentResolver?: any, embedder?: any);
55
+ /**
56
+ * Perform cross-modal search that can find content across different modalities
57
+ *
58
+ * This method extends the base search functionality to:
59
+ * 1. Detect query content type (text or image path)
60
+ * 2. Generate appropriate embeddings for the query
61
+ * 3. Search across all content types in the unified embedding space
62
+ * 4. Rank results by semantic similarity regardless of content type
63
+ * 5. Apply cross-modal ranking adjustments
64
+ *
65
+ * @param query - Search query (text string or image path)
66
+ * @param options - Cross-modal search options
67
+ * @returns Promise resolving to cross-modal search results
68
+ */
69
+ crossModalSearch(query: string, options?: CrossModalSearchOptions): Promise<CrossModalSearchResult[]>;
70
+ /**
71
+ * Search for images using text queries
72
+ *
73
+ * @param textQuery - Text description to search for
74
+ * @param options - Search options
75
+ * @returns Promise resolving to image search results
76
+ */
77
+ searchImagesWithText(textQuery: string, options?: CrossModalSearchOptions): Promise<CrossModalSearchResult[]>;
78
+ /**
79
+ * Search for text using image queries
80
+ *
81
+ * @param imagePath - Path to image file to search with
82
+ * @param options - Search options
83
+ * @returns Promise resolving to text search results
84
+ */
85
+ searchTextWithImage(imagePath: string, options?: CrossModalSearchOptions): Promise<CrossModalSearchResult[]>;
86
+ /**
87
+ * Search across all content types with unified ranking
88
+ *
89
+ * @param query - Search query (text or image path)
90
+ * @param options - Search options
91
+ * @returns Promise resolving to mixed content type results
92
+ */
93
+ searchUnified(query: string, options?: CrossModalSearchOptions): Promise<CrossModalSearchResult[]>;
94
+ /**
95
+ * Detect the content type of a query
96
+ * @private
97
+ */
98
+ private detectQueryContentType;
99
+ /**
100
+ * Enhance search results with cross-modal information
101
+ * @private
102
+ */
103
+ private enhanceResultsWithCrossModalInfo;
104
+ /**
105
+ * Apply cross-modal ranking to results
106
+ * @private
107
+ */
108
+ private applyCrossModalRanking;
109
+ /**
110
+ * Calculate semantic similarity between query and result content
111
+ * @private
112
+ */
113
+ private calculateSemanticSimilarity;
114
+ /**
115
+ * Get cross-modal search statistics
116
+ */
117
+ getCrossModalStats(): Promise<{
118
+ totalChunks: number;
119
+ textChunks: number;
120
+ imageChunks: number;
121
+ crossModalCapable: boolean;
122
+ supportedContentTypes: string[];
123
+ }>;
124
+ }
125
+ /**
126
+ * Factory function to create a cross-modal search engine
127
+ *
128
+ * @param embedFn - Embedding function that supports multiple content types
129
+ * @param indexManager - Vector index manager
130
+ * @param db - Database connection
131
+ * @param rerankFn - Optional reranking function
132
+ * @param contentResolver - Content resolver for unified content system
133
+ * @param embedder - Reference to the embedder for cross-modal operations
134
+ * @returns CrossModalSearchEngine instance
135
+ */
136
+ export declare function createCrossModalSearchEngine(embedFn: EmbedFunction, indexManager: any, db: any, rerankFn?: RerankFunction, contentResolver?: any, embedder?: any): CrossModalSearchEngine;
137
+ /**
138
+ * Utility function to check if a search engine supports cross-modal search
139
+ *
140
+ * @param searchEngine - Search engine to check
141
+ * @returns True if the engine supports cross-modal search
142
+ */
143
+ export declare function supportsCrossModalSearch(searchEngine: any): searchEngine is CrossModalSearchEngine;
144
+ /**
145
+ * Cross-modal search result analyzer
146
+ * Provides utilities for analyzing cross-modal search results
147
+ */
148
+ export declare class CrossModalResultAnalyzer {
149
+ /**
150
+ * Analyze cross-modal search results
151
+ */
152
+ static analyzeResults(results: CrossModalSearchResult[]): {
153
+ totalResults: number;
154
+ crossModalResults: number;
155
+ sameModalResults: number;
156
+ averageSemanticSimilarity: number;
157
+ contentTypeDistribution: Record<string, number>;
158
+ };
159
+ /**
160
+ * Generate a summary report of cross-modal search results
161
+ */
162
+ static generateReport(results: CrossModalSearchResult[], query: string): string;
163
+ }
164
+ //# sourceMappingURL=cross-modal-search.d.ts.map