@fgv/ts-agent-memory 5.1.0-47 → 5.1.0-48

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 (341) hide show
  1. package/dist/packlets/ingest/orchestrator.js +11 -1
  2. package/dist/packlets/ingest/orchestrator.js.map +1 -1
  3. package/dist/packlets/observe/memoryObservationStore.js +6 -0
  4. package/dist/packlets/observe/memoryObservationStore.js.map +1 -1
  5. package/dist/packlets/observe/observer.js.map +1 -1
  6. package/dist/packlets/store/fileTreeMemoryStore.js +52 -131
  7. package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -1
  8. package/dist/packlets/store/vectorMaintenance.js +251 -0
  9. package/dist/packlets/store/vectorMaintenance.js.map +1 -0
  10. package/dist/packlets/vector/inMemoryCosineIndex.js +81 -18
  11. package/dist/packlets/vector/inMemoryCosineIndex.js.map +1 -1
  12. package/dist/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
  13. package/dist/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
  14. package/dist/packlets/vector/vectorIndex.js.map +1 -1
  15. package/dist/ts-agent-memory.d.ts +297 -66
  16. package/lib/packlets/ingest/orchestrator.d.ts.map +1 -1
  17. package/lib/packlets/ingest/orchestrator.js +11 -1
  18. package/lib/packlets/ingest/orchestrator.js.map +1 -1
  19. package/lib/packlets/observe/memoryObservationStore.d.ts.map +1 -1
  20. package/lib/packlets/observe/memoryObservationStore.js +6 -0
  21. package/lib/packlets/observe/memoryObservationStore.js.map +1 -1
  22. package/lib/packlets/observe/observer.d.ts +61 -0
  23. package/lib/packlets/observe/observer.d.ts.map +1 -1
  24. package/lib/packlets/observe/observer.js.map +1 -1
  25. package/lib/packlets/store/fileTreeMemoryStore.d.ts +66 -59
  26. package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -1
  27. package/lib/packlets/store/fileTreeMemoryStore.js +52 -131
  28. package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -1
  29. package/lib/packlets/store/vectorMaintenance.d.ts +149 -0
  30. package/lib/packlets/store/vectorMaintenance.d.ts.map +1 -0
  31. package/lib/packlets/store/vectorMaintenance.js +255 -0
  32. package/lib/packlets/store/vectorMaintenance.js.map +1 -0
  33. package/lib/packlets/vector/inMemoryCosineIndex.d.ts +30 -7
  34. package/lib/packlets/vector/inMemoryCosineIndex.d.ts.map +1 -1
  35. package/lib/packlets/vector/inMemoryCosineIndex.js +80 -17
  36. package/lib/packlets/vector/inMemoryCosineIndex.js.map +1 -1
  37. package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts +7 -0
  38. package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts.map +1 -1
  39. package/lib/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
  40. package/lib/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
  41. package/lib/packlets/vector/vectorIndex.d.ts +129 -1
  42. package/lib/packlets/vector/vectorIndex.d.ts.map +1 -1
  43. package/lib/packlets/vector/vectorIndex.js.map +1 -1
  44. package/package.json +17 -7
  45. package/.rush/temp/5667e36f1c0cc503a5c20a3ebff76e7b9a702d41.tar.log +0 -468
  46. package/.rush/temp/chunked-rush-logs/ts-agent-memory.build.chunks.jsonl +0 -9
  47. package/.rush/temp/operation/build/all.log +0 -9
  48. package/.rush/temp/operation/build/log-chunks.jsonl +0 -9
  49. package/.rush/temp/operation/build/state.json +0 -3
  50. package/.rush/temp/shrinkwrap-deps.json +0 -689
  51. package/config/api-extractor.json +0 -343
  52. package/config/jest.config.json +0 -14
  53. package/config/rig.json +0 -4
  54. package/dist/test/unit/converters/antagonistRoundTrip.test.js +0 -95
  55. package/dist/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
  56. package/dist/test/unit/converters/bodyConverterRegistry.test.js +0 -72
  57. package/dist/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
  58. package/dist/test/unit/converters/envelopeConverter.test.js +0 -313
  59. package/dist/test/unit/converters/envelopeConverter.test.js.map +0 -1
  60. package/dist/test/unit/index/memoryIndex.test.js +0 -214
  61. package/dist/test/unit/index/memoryIndex.test.js.map +0 -1
  62. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js +0 -277
  63. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
  64. package/dist/test/unit/ingest/cycleGuard.test.js +0 -81
  65. package/dist/test/unit/ingest/cycleGuard.test.js.map +0 -1
  66. package/dist/test/unit/ingest/dedupScope.test.js +0 -434
  67. package/dist/test/unit/ingest/dedupScope.test.js.map +0 -1
  68. package/dist/test/unit/ingest/orchestrator.test.js +0 -1058
  69. package/dist/test/unit/ingest/orchestrator.test.js.map +0 -1
  70. package/dist/test/unit/observe/memoryObservationStore.test.js +0 -118
  71. package/dist/test/unit/observe/memoryObservationStore.test.js.map +0 -1
  72. package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -116
  73. package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
  74. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js +0 -257
  75. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
  76. package/dist/test/unit/retrieve/retrievers.test.js +0 -768
  77. package/dist/test/unit/retrieve/retrievers.test.js.map +0 -1
  78. package/dist/test/unit/retrieve/temporalRetrievers.test.js +0 -182
  79. package/dist/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
  80. package/dist/test/unit/store/antagonistTemporalBoundary.test.js +0 -120
  81. package/dist/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
  82. package/dist/test/unit/store/embedOnWrite.test.js +0 -317
  83. package/dist/test/unit/store/embedOnWrite.test.js.map +0 -1
  84. package/dist/test/unit/store/fileTreeMemoryStore.test.js +0 -778
  85. package/dist/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
  86. package/dist/test/unit/store/fragmentEmbedOnWrite.test.js +0 -255
  87. package/dist/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
  88. package/dist/test/unit/store/indexInjection.test.js +0 -432
  89. package/dist/test/unit/store/indexInjection.test.js.map +0 -1
  90. package/dist/test/unit/store/lenientOpen.test.js +0 -248
  91. package/dist/test/unit/store/lenientOpen.test.js.map +0 -1
  92. package/dist/test/unit/store/listScoped.test.js +0 -109
  93. package/dist/test/unit/store/listScoped.test.js.map +0 -1
  94. package/dist/test/unit/store/observations.test.js +0 -239
  95. package/dist/test/unit/store/observations.test.js.map +0 -1
  96. package/dist/test/unit/store/rankAxis.test.js +0 -254
  97. package/dist/test/unit/store/rankAxis.test.js.map +0 -1
  98. package/dist/test/unit/store/scopeEncoding.test.js +0 -24
  99. package/dist/test/unit/store/scopeEncoding.test.js.map +0 -1
  100. package/dist/test/unit/store/temporalStore.test.js +0 -398
  101. package/dist/test/unit/store/temporalStore.test.js.map +0 -1
  102. package/dist/test/unit/tools/memoryTools.test.js +0 -842
  103. package/dist/test/unit/tools/memoryTools.test.js.map +0 -1
  104. package/dist/test/unit/types/identityCodec.test.js +0 -187
  105. package/dist/test/unit/types/identityCodec.test.js.map +0 -1
  106. package/dist/test/unit/types/ids.test.js +0 -84
  107. package/dist/test/unit/types/ids.test.js.map +0 -1
  108. package/dist/test/unit/types/temporalCodec.test.js +0 -203
  109. package/dist/test/unit/types/temporalCodec.test.js.map +0 -1
  110. package/dist/test/unit/types/temporalPolicy.test.js +0 -83
  111. package/dist/test/unit/types/temporalPolicy.test.js.map +0 -1
  112. package/dist/test/unit/types/writePolicy.test.js +0 -331
  113. package/dist/test/unit/types/writePolicy.test.js.map +0 -1
  114. package/dist/test/unit/vector/fragmentConverters.test.js +0 -58
  115. package/dist/test/unit/vector/fragmentConverters.test.js.map +0 -1
  116. package/dist/test/unit/vector/inMemoryCosineIndex.test.js +0 -252
  117. package/dist/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
  118. package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -362
  119. package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
  120. package/dist/test/unit/vector/vectorIndex.test.js +0 -51
  121. package/dist/test/unit/vector/vectorIndex.test.js.map +0 -1
  122. package/eslint.config.js +0 -15
  123. package/etc/ts-agent-memory.api.md +0 -940
  124. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts +0 -10
  125. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts.map +0 -1
  126. package/lib/test/unit/converters/antagonistRoundTrip.test.js +0 -97
  127. package/lib/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
  128. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts +0 -2
  129. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts.map +0 -1
  130. package/lib/test/unit/converters/bodyConverterRegistry.test.js +0 -74
  131. package/lib/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
  132. package/lib/test/unit/converters/envelopeConverter.test.d.ts +0 -2
  133. package/lib/test/unit/converters/envelopeConverter.test.d.ts.map +0 -1
  134. package/lib/test/unit/converters/envelopeConverter.test.js +0 -315
  135. package/lib/test/unit/converters/envelopeConverter.test.js.map +0 -1
  136. package/lib/test/unit/index/memoryIndex.test.d.ts +0 -2
  137. package/lib/test/unit/index/memoryIndex.test.d.ts.map +0 -1
  138. package/lib/test/unit/index/memoryIndex.test.js +0 -216
  139. package/lib/test/unit/index/memoryIndex.test.js.map +0 -1
  140. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts +0 -9
  141. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts.map +0 -1
  142. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js +0 -279
  143. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
  144. package/lib/test/unit/ingest/cycleGuard.test.d.ts +0 -2
  145. package/lib/test/unit/ingest/cycleGuard.test.d.ts.map +0 -1
  146. package/lib/test/unit/ingest/cycleGuard.test.js +0 -83
  147. package/lib/test/unit/ingest/cycleGuard.test.js.map +0 -1
  148. package/lib/test/unit/ingest/dedupScope.test.d.ts +0 -2
  149. package/lib/test/unit/ingest/dedupScope.test.d.ts.map +0 -1
  150. package/lib/test/unit/ingest/dedupScope.test.js +0 -436
  151. package/lib/test/unit/ingest/dedupScope.test.js.map +0 -1
  152. package/lib/test/unit/ingest/orchestrator.test.d.ts +0 -2
  153. package/lib/test/unit/ingest/orchestrator.test.d.ts.map +0 -1
  154. package/lib/test/unit/ingest/orchestrator.test.js +0 -1060
  155. package/lib/test/unit/ingest/orchestrator.test.js.map +0 -1
  156. package/lib/test/unit/observe/memoryObservationStore.test.d.ts +0 -2
  157. package/lib/test/unit/observe/memoryObservationStore.test.d.ts.map +0 -1
  158. package/lib/test/unit/observe/memoryObservationStore.test.js +0 -120
  159. package/lib/test/unit/observe/memoryObservationStore.test.js.map +0 -1
  160. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts +0 -2
  161. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts.map +0 -1
  162. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -118
  163. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
  164. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts +0 -2
  165. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts.map +0 -1
  166. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js +0 -259
  167. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
  168. package/lib/test/unit/retrieve/retrievers.test.d.ts +0 -2
  169. package/lib/test/unit/retrieve/retrievers.test.d.ts.map +0 -1
  170. package/lib/test/unit/retrieve/retrievers.test.js +0 -770
  171. package/lib/test/unit/retrieve/retrievers.test.js.map +0 -1
  172. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts +0 -2
  173. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts.map +0 -1
  174. package/lib/test/unit/retrieve/temporalRetrievers.test.js +0 -184
  175. package/lib/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
  176. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts +0 -9
  177. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts.map +0 -1
  178. package/lib/test/unit/store/antagonistTemporalBoundary.test.js +0 -122
  179. package/lib/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
  180. package/lib/test/unit/store/embedOnWrite.test.d.ts +0 -2
  181. package/lib/test/unit/store/embedOnWrite.test.d.ts.map +0 -1
  182. package/lib/test/unit/store/embedOnWrite.test.js +0 -319
  183. package/lib/test/unit/store/embedOnWrite.test.js.map +0 -1
  184. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts +0 -2
  185. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts.map +0 -1
  186. package/lib/test/unit/store/fileTreeMemoryStore.test.js +0 -780
  187. package/lib/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
  188. package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts +0 -2
  189. package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts.map +0 -1
  190. package/lib/test/unit/store/fragmentEmbedOnWrite.test.js +0 -257
  191. package/lib/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
  192. package/lib/test/unit/store/indexInjection.test.d.ts +0 -2
  193. package/lib/test/unit/store/indexInjection.test.d.ts.map +0 -1
  194. package/lib/test/unit/store/indexInjection.test.js +0 -434
  195. package/lib/test/unit/store/indexInjection.test.js.map +0 -1
  196. package/lib/test/unit/store/lenientOpen.test.d.ts +0 -2
  197. package/lib/test/unit/store/lenientOpen.test.d.ts.map +0 -1
  198. package/lib/test/unit/store/lenientOpen.test.js +0 -250
  199. package/lib/test/unit/store/lenientOpen.test.js.map +0 -1
  200. package/lib/test/unit/store/listScoped.test.d.ts +0 -2
  201. package/lib/test/unit/store/listScoped.test.d.ts.map +0 -1
  202. package/lib/test/unit/store/listScoped.test.js +0 -111
  203. package/lib/test/unit/store/listScoped.test.js.map +0 -1
  204. package/lib/test/unit/store/observations.test.d.ts +0 -2
  205. package/lib/test/unit/store/observations.test.d.ts.map +0 -1
  206. package/lib/test/unit/store/observations.test.js +0 -241
  207. package/lib/test/unit/store/observations.test.js.map +0 -1
  208. package/lib/test/unit/store/rankAxis.test.d.ts +0 -2
  209. package/lib/test/unit/store/rankAxis.test.d.ts.map +0 -1
  210. package/lib/test/unit/store/rankAxis.test.js +0 -256
  211. package/lib/test/unit/store/rankAxis.test.js.map +0 -1
  212. package/lib/test/unit/store/scopeEncoding.test.d.ts +0 -2
  213. package/lib/test/unit/store/scopeEncoding.test.d.ts.map +0 -1
  214. package/lib/test/unit/store/scopeEncoding.test.js +0 -26
  215. package/lib/test/unit/store/scopeEncoding.test.js.map +0 -1
  216. package/lib/test/unit/store/temporalStore.test.d.ts +0 -2
  217. package/lib/test/unit/store/temporalStore.test.d.ts.map +0 -1
  218. package/lib/test/unit/store/temporalStore.test.js +0 -400
  219. package/lib/test/unit/store/temporalStore.test.js.map +0 -1
  220. package/lib/test/unit/tools/memoryTools.test.d.ts +0 -2
  221. package/lib/test/unit/tools/memoryTools.test.d.ts.map +0 -1
  222. package/lib/test/unit/tools/memoryTools.test.js +0 -844
  223. package/lib/test/unit/tools/memoryTools.test.js.map +0 -1
  224. package/lib/test/unit/types/identityCodec.test.d.ts +0 -2
  225. package/lib/test/unit/types/identityCodec.test.d.ts.map +0 -1
  226. package/lib/test/unit/types/identityCodec.test.js +0 -189
  227. package/lib/test/unit/types/identityCodec.test.js.map +0 -1
  228. package/lib/test/unit/types/ids.test.d.ts +0 -2
  229. package/lib/test/unit/types/ids.test.d.ts.map +0 -1
  230. package/lib/test/unit/types/ids.test.js +0 -86
  231. package/lib/test/unit/types/ids.test.js.map +0 -1
  232. package/lib/test/unit/types/temporalCodec.test.d.ts +0 -2
  233. package/lib/test/unit/types/temporalCodec.test.d.ts.map +0 -1
  234. package/lib/test/unit/types/temporalCodec.test.js +0 -205
  235. package/lib/test/unit/types/temporalCodec.test.js.map +0 -1
  236. package/lib/test/unit/types/temporalPolicy.test.d.ts +0 -2
  237. package/lib/test/unit/types/temporalPolicy.test.d.ts.map +0 -1
  238. package/lib/test/unit/types/temporalPolicy.test.js +0 -85
  239. package/lib/test/unit/types/temporalPolicy.test.js.map +0 -1
  240. package/lib/test/unit/types/writePolicy.test.d.ts +0 -2
  241. package/lib/test/unit/types/writePolicy.test.d.ts.map +0 -1
  242. package/lib/test/unit/types/writePolicy.test.js +0 -333
  243. package/lib/test/unit/types/writePolicy.test.js.map +0 -1
  244. package/lib/test/unit/vector/fragmentConverters.test.d.ts +0 -2
  245. package/lib/test/unit/vector/fragmentConverters.test.d.ts.map +0 -1
  246. package/lib/test/unit/vector/fragmentConverters.test.js +0 -60
  247. package/lib/test/unit/vector/fragmentConverters.test.js.map +0 -1
  248. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts +0 -2
  249. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts.map +0 -1
  250. package/lib/test/unit/vector/inMemoryCosineIndex.test.js +0 -254
  251. package/lib/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
  252. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts +0 -2
  253. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts.map +0 -1
  254. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -364
  255. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
  256. package/lib/test/unit/vector/vectorIndex.test.d.ts +0 -2
  257. package/lib/test/unit/vector/vectorIndex.test.d.ts.map +0 -1
  258. package/lib/test/unit/vector/vectorIndex.test.js +0 -53
  259. package/lib/test/unit/vector/vectorIndex.test.js.map +0 -1
  260. package/rush-logs/ts-agent-memory.build.cache.log +0 -3
  261. package/rush-logs/ts-agent-memory.build.log +0 -9
  262. package/src/index.ts +0 -14
  263. package/src/packlets/converters/bodyConverterRegistry.ts +0 -105
  264. package/src/packlets/converters/envelopeConverter.ts +0 -233
  265. package/src/packlets/converters/index.ts +0 -7
  266. package/src/packlets/index/index.ts +0 -6
  267. package/src/packlets/index/memoryIndex.ts +0 -332
  268. package/src/packlets/ingest/cycleGuard.ts +0 -153
  269. package/src/packlets/ingest/hostStages.ts +0 -111
  270. package/src/packlets/ingest/index.ts +0 -9
  271. package/src/packlets/ingest/model.ts +0 -195
  272. package/src/packlets/ingest/orchestrator.ts +0 -968
  273. package/src/packlets/observe/index.ts +0 -7
  274. package/src/packlets/observe/memoryObservationStore.ts +0 -153
  275. package/src/packlets/observe/observer.ts +0 -119
  276. package/src/packlets/retrieve/fragmentSemanticRetriever.ts +0 -138
  277. package/src/packlets/retrieve/hybridRetriever.ts +0 -194
  278. package/src/packlets/retrieve/index.ts +0 -14
  279. package/src/packlets/retrieve/linkTraversalRetriever.ts +0 -158
  280. package/src/packlets/retrieve/recencyRetriever.ts +0 -54
  281. package/src/packlets/retrieve/retriever.ts +0 -291
  282. package/src/packlets/retrieve/semanticRetriever.ts +0 -152
  283. package/src/packlets/retrieve/structuredFilterRetriever.ts +0 -58
  284. package/src/packlets/retrieve/tagRetriever.ts +0 -58
  285. package/src/packlets/retrieve/temporalRetrievers.ts +0 -210
  286. package/src/packlets/store/fileTreeMemoryStore.ts +0 -1872
  287. package/src/packlets/store/index.ts +0 -7
  288. package/src/packlets/store/scopeEncoding.ts +0 -36
  289. package/src/packlets/tools/index.ts +0 -6
  290. package/src/packlets/tools/memoryTools.ts +0 -706
  291. package/src/packlets/types/envelope.ts +0 -196
  292. package/src/packlets/types/filenameSafety.ts +0 -57
  293. package/src/packlets/types/identityCodec.ts +0 -447
  294. package/src/packlets/types/ids.ts +0 -124
  295. package/src/packlets/types/index.ts +0 -11
  296. package/src/packlets/types/temporal.ts +0 -96
  297. package/src/packlets/types/writePolicy.ts +0 -612
  298. package/src/packlets/vector/fragmentConverters.ts +0 -55
  299. package/src/packlets/vector/inMemoryCosineIndex.ts +0 -196
  300. package/src/packlets/vector/inMemoryFragmentCosineIndex.ts +0 -289
  301. package/src/packlets/vector/index.ts +0 -9
  302. package/src/packlets/vector/vectorIndex.ts +0 -273
  303. package/src/test/unit/converters/antagonistRoundTrip.test.ts +0 -110
  304. package/src/test/unit/converters/bodyConverterRegistry.test.ts +0 -89
  305. package/src/test/unit/converters/envelopeConverter.test.ts +0 -418
  306. package/src/test/unit/index/memoryIndex.test.ts +0 -272
  307. package/src/test/unit/ingest/antagonistCycleAndParity.test.ts +0 -367
  308. package/src/test/unit/ingest/cycleGuard.test.ts +0 -110
  309. package/src/test/unit/ingest/dedupScope.test.ts +0 -542
  310. package/src/test/unit/ingest/orchestrator.test.ts +0 -1355
  311. package/src/test/unit/observe/memoryObservationStore.test.ts +0 -158
  312. package/src/test/unit/retrieve/fragmentSemanticRetriever.test.ts +0 -163
  313. package/src/test/unit/retrieve/linkTraversalRetriever.test.ts +0 -329
  314. package/src/test/unit/retrieve/retrievers.test.ts +0 -1018
  315. package/src/test/unit/retrieve/temporalRetrievers.test.ts +0 -226
  316. package/src/test/unit/store/antagonistTemporalBoundary.test.ts +0 -158
  317. package/src/test/unit/store/embedOnWrite.test.ts +0 -418
  318. package/src/test/unit/store/fileTreeMemoryStore.test.ts +0 -1041
  319. package/src/test/unit/store/fragmentEmbedOnWrite.test.ts +0 -349
  320. package/src/test/unit/store/indexInjection.test.ts +0 -550
  321. package/src/test/unit/store/lenientOpen.test.ts +0 -292
  322. package/src/test/unit/store/listScoped.test.ts +0 -138
  323. package/src/test/unit/store/observations.test.ts +0 -290
  324. package/src/test/unit/store/rankAxis.test.ts +0 -349
  325. package/src/test/unit/store/scopeEncoding.test.ts +0 -37
  326. package/src/test/unit/store/temporalStore.test.ts +0 -469
  327. package/src/test/unit/tools/memoryTools.test.ts +0 -1121
  328. package/src/test/unit/types/identityCodec.test.ts +0 -266
  329. package/src/test/unit/types/ids.test.ts +0 -94
  330. package/src/test/unit/types/temporalCodec.test.ts +0 -259
  331. package/src/test/unit/types/temporalPolicy.test.ts +0 -124
  332. package/src/test/unit/types/writePolicy.test.ts +0 -446
  333. package/src/test/unit/vector/fragmentConverters.test.ts +0 -80
  334. package/src/test/unit/vector/inMemoryCosineIndex.test.ts +0 -318
  335. package/src/test/unit/vector/inMemoryFragmentCosineIndex.test.ts +0 -477
  336. package/src/test/unit/vector/vectorIndex.test.ts +0 -64
  337. package/temp/build/lint/_eslint-5eVG3S6w.json +0 -306
  338. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  339. package/temp/ts-agent-memory.api.json +0 -21030
  340. package/temp/ts-agent-memory.api.md +0 -940
  341. package/tsconfig.json +0 -8
@@ -1,252 +0,0 @@
1
- /*
2
- * Copyright (c) 2026 Erik Fortune
3
- * SPDX-License-Identifier: MIT
4
- */
5
- import '@fgv/ts-utils-jest';
6
- import { fail, succeed } from '@fgv/ts-utils';
7
- import { InMemoryCosineIndex } from '../../../index';
8
- /** A scope-qualified target from a `(scope, id)` pair. */
9
- function target(scope, id) {
10
- return { scope: scope, id: id };
11
- }
12
- /** A trivial record carrying just the id + a marker body, for rebuild tests. */
13
- function record(id, body = `body-${id}`) {
14
- return {
15
- // The cosine index only reads `envelope.id`; a minimal envelope suffices.
16
- envelope: { id: id },
17
- body
18
- };
19
- }
20
- /** A scope-qualified record entry for a rebuild source. */
21
- function scoped(scope, id, body) {
22
- return { target: target(scope, id), record: record(id, body) };
23
- }
24
- /** A scripted record source for `rebuild`. */
25
- class FakeSource {
26
- constructor(result) {
27
- this._result = result;
28
- }
29
- list() {
30
- return Promise.resolve(this._result);
31
- }
32
- }
33
- describe('InMemoryCosineIndex', () => {
34
- describe('add', () => {
35
- test('returns the scoped-target key as the embedding ref and tracks size', async () => {
36
- const index = InMemoryCosineIndex.create().orThrow();
37
- expect(index.size).toBe(0);
38
- const t = target('conv-a', 'turn-1');
39
- expect(await index.add(t, Float32Array.from([1, 0]))).toSucceedWith(`conv-a\0turn-1`);
40
- expect(index.size).toBe(1);
41
- });
42
- test('replaces the vector on a same-target add', async () => {
43
- const index = InMemoryCosineIndex.create().orThrow();
44
- const t = target('conv-a', 'turn-1');
45
- expect(await index.add(t, Float32Array.from([1, 0]))).toSucceed();
46
- expect(await index.add(t, Float32Array.from([0, 1]))).toSucceed();
47
- expect(index.size).toBe(1);
48
- // The query now matches the replacement vector ([0,1]) not the original.
49
- expect(await index.query(Float32Array.from([0, 1]), 1)).toSucceedAndSatisfy((hits) => {
50
- expect(hits[0].score).toBeCloseTo(1);
51
- });
52
- });
53
- test('same stem in different scopes are distinct entries — the second add does NOT clobber the first', async () => {
54
- const index = InMemoryCosineIndex.create().orThrow();
55
- const a = target('conv-a', 'turn-3');
56
- const b = target('conv-b', 'turn-3');
57
- // Two records with the identical stem, orthogonal embeddings.
58
- expect(await index.add(a, Float32Array.from([1, 0]))).toSucceed();
59
- expect(await index.add(b, Float32Array.from([0, 1]))).toSucceed();
60
- // The bug: a bare-id index would have collapsed these to one entry.
61
- expect(index.size).toBe(2);
62
- // A query surfaces BOTH as distinct hits carrying distinct scoped targets.
63
- expect(await index.query(Float32Array.from([1, 1]), 5)).toSucceedAndSatisfy((hits) => {
64
- expect(hits).toHaveLength(2);
65
- expect(hits.map((h) => h.target)).toEqual(expect.arrayContaining([a, b]));
66
- // Each retains its OWN embedding: a matches [1,0], b matches [0,1].
67
- const byScope = new Map(hits.map((h) => [h.target.scope, h.score]));
68
- expect(byScope.get('conv-a')).toBeCloseTo(1 / Math.sqrt(2));
69
- expect(byScope.get('conv-b')).toBeCloseTo(1 / Math.sqrt(2));
70
- });
71
- });
72
- test('fails loudly on an empty vector', async () => {
73
- const index = InMemoryCosineIndex.create().orThrow();
74
- expect(await index.add(target('conv-a', 'turn-1'), new Float32Array(0))).toFailWith(/empty vector/i);
75
- });
76
- test('stores a defensive copy — mutating the caller buffer after add does not corrupt the index', async () => {
77
- const index = InMemoryCosineIndex.create().orThrow();
78
- const buffer = Float32Array.from([1, 0]);
79
- (await index.add(target('conv-a', 'turn-1'), buffer)).orThrow();
80
- // Mutate the caller's buffer after the add; the stored vector must be unaffected.
81
- buffer[0] = 0;
82
- buffer[1] = 1;
83
- expect(await index.query(Float32Array.from([1, 0]), 1)).toSucceedAndSatisfy((hits) => {
84
- // Still maximally similar to [1,0] — proves the index kept its own copy.
85
- expect(hits[0].score).toBeCloseTo(1);
86
- });
87
- });
88
- test('fails loudly on a dimension mismatch against the established dimension', async () => {
89
- const index = InMemoryCosineIndex.create().orThrow();
90
- expect(await index.add(target('conv-a', 'a'), Float32Array.from([1, 0]))).toSucceed();
91
- expect(await index.add(target('conv-a', 'b'), Float32Array.from([1, 0, 0]))).toFailWith(/dimension 3 does not match index dimension 2/i);
92
- });
93
- });
94
- describe('query', () => {
95
- async function seeded() {
96
- const index = InMemoryCosineIndex.create().orThrow();
97
- (await index.add(target('s', 'a'), Float32Array.from([1, 0]))).orThrow();
98
- (await index.add(target('s', 'b'), Float32Array.from([0, 1]))).orThrow();
99
- (await index.add(target('s', 'c'), Float32Array.from([1, 1]))).orThrow();
100
- return index;
101
- }
102
- test('returns hits in descending cosine-similarity order', async () => {
103
- const index = await seeded();
104
- expect(await index.query(Float32Array.from([1, 0]), 3)).toSucceedAndSatisfy((hits) => {
105
- expect(hits.map((h) => h.target.id)).toEqual(['a', 'c', 'b']);
106
- expect(hits[0].score).toBeCloseTo(1);
107
- expect(hits[1].score).toBeCloseTo(1 / Math.sqrt(2));
108
- expect(hits[2].score).toBeCloseTo(0);
109
- });
110
- });
111
- test('truncates to topK', async () => {
112
- const index = await seeded();
113
- expect(await index.query(Float32Array.from([1, 0]), 2)).toSucceedAndSatisfy((hits) => {
114
- expect(hits.map((h) => h.target.id)).toEqual(['a', 'c']);
115
- });
116
- });
117
- test('returns empty for a non-positive topK', async () => {
118
- const index = await seeded();
119
- expect(await index.query(Float32Array.from([1, 0]), 0)).toSucceedWith([]);
120
- expect(await index.query(Float32Array.from([1, 0]), -1)).toSucceedWith([]);
121
- });
122
- test('returns empty when the index is empty (no dimension check)', async () => {
123
- const index = InMemoryCosineIndex.create().orThrow();
124
- expect(await index.query(Float32Array.from([1, 2, 3, 4]), 5)).toSucceedWith([]);
125
- });
126
- test('fails loudly on a query-dimension mismatch', async () => {
127
- const index = await seeded();
128
- expect(await index.query(Float32Array.from([1, 0, 0]), 3)).toFailWith(/query dimension 3 does not match index dimension 2/i);
129
- });
130
- test('scores a degenerate (zero-magnitude) stored vector as 0 rather than NaN', async () => {
131
- const index = InMemoryCosineIndex.create().orThrow();
132
- (await index.add(target('s', 'zero'), Float32Array.from([0, 0]))).orThrow();
133
- (await index.add(target('s', 'unit'), Float32Array.from([1, 0]))).orThrow();
134
- expect(await index.query(Float32Array.from([1, 0]), 2)).toSucceedAndSatisfy((hits) => {
135
- expect(hits.map((h) => h.target.id)).toEqual(['unit', 'zero']);
136
- expect(hits[1].score).toBe(0);
137
- });
138
- });
139
- test('scores against a degenerate (zero-magnitude) query as 0 rather than NaN', async () => {
140
- const index = InMemoryCosineIndex.create().orThrow();
141
- (await index.add(target('s', 'unit'), Float32Array.from([1, 0]))).orThrow();
142
- expect(await index.query(Float32Array.from([0, 0]), 1)).toSucceedAndSatisfy((hits) => {
143
- expect(hits[0].score).toBe(0);
144
- });
145
- });
146
- });
147
- describe('remove', () => {
148
- test('removes a vector and is reflected in subsequent queries', async () => {
149
- const index = InMemoryCosineIndex.create().orThrow();
150
- const a = target('s', 'a');
151
- const b = target('s', 'b');
152
- (await index.add(a, Float32Array.from([1, 0]))).orThrow();
153
- (await index.add(b, Float32Array.from([0, 1]))).orThrow();
154
- expect(await index.remove(a)).toSucceedWith(a);
155
- expect(index.size).toBe(1);
156
- expect(await index.query(Float32Array.from([1, 0]), 5)).toSucceedAndSatisfy((hits) => {
157
- expect(hits.map((h) => h.target.id)).toEqual(['b']);
158
- });
159
- });
160
- test('removes only the scoped target — a same-stem record in another scope is left intact', async () => {
161
- const index = InMemoryCosineIndex.create().orThrow();
162
- const a = target('conv-a', 'turn-3');
163
- const b = target('conv-b', 'turn-3');
164
- (await index.add(a, Float32Array.from([1, 0]))).orThrow();
165
- (await index.add(b, Float32Array.from([0, 1]))).orThrow();
166
- expect(await index.remove(a)).toSucceedWith(a);
167
- expect(index.size).toBe(1);
168
- // conv-b's embedding survives untouched.
169
- expect(await index.query(Float32Array.from([0, 1]), 5)).toSucceedAndSatisfy((hits) => {
170
- expect(hits).toHaveLength(1);
171
- expect(hits[0].target).toEqual(b);
172
- expect(hits[0].score).toBeCloseTo(1);
173
- });
174
- });
175
- test('is idempotent — removing an absent target still succeeds', async () => {
176
- const index = InMemoryCosineIndex.create().orThrow();
177
- const t = target('s', 'missing');
178
- expect(await index.remove(t)).toSucceedWith(t);
179
- });
180
- });
181
- describe('rebuild', () => {
182
- const embed = (r) => {
183
- // Deterministic: encode the id's first char code into a 2-vector.
184
- const code = r.envelope.id.charCodeAt(0);
185
- return Promise.resolve(succeed(Float32Array.from([code, 1])));
186
- };
187
- test('re-embeds every scoped record from the source and reports the count', async () => {
188
- const index = InMemoryCosineIndex.create().orThrow();
189
- const source = new FakeSource(succeed([scoped('s', 'a'), scoped('s', 'b'), scoped('s', 'c')]));
190
- expect(await index.rebuild(source, embed)).toSucceedWith(3);
191
- expect(index.size).toBe(3);
192
- expect(await index.query(Float32Array.from([99, 1]), 1)).toSucceedAndSatisfy((hits) => {
193
- // 'c' = char code 99, the closest to the query vector.
194
- expect(hits[0].target.id).toBe('c');
195
- });
196
- });
197
- test('keeps same-stem records under different scopes distinct across a rebuild', async () => {
198
- const index = InMemoryCosineIndex.create().orThrow();
199
- const source = new FakeSource(succeed([scoped('conv-a', 'turn-3'), scoped('conv-b', 'turn-3')]));
200
- // The embedder keys only off the (shared) id, so a bare-id rebuild would
201
- // index just one entry; the scoped rebuild indexes both.
202
- expect(await index.rebuild(source, embed)).toSucceedWith(2);
203
- expect(index.size).toBe(2);
204
- expect(await index.query(Float32Array.from([116, 1]), 5)).toSucceedAndSatisfy((hits) => {
205
- expect(hits).toHaveLength(2);
206
- expect(hits.map((h) => h.target.scope).sort()).toEqual(['conv-a', 'conv-b']);
207
- });
208
- });
209
- test('clears prior contents and re-establishes the dimension', async () => {
210
- const index = InMemoryCosineIndex.create().orThrow();
211
- // Seed a 3-dim vector, then rebuild with a 2-dim embedder.
212
- (await index.add(target('s', 'old'), Float32Array.from([1, 2, 3]))).orThrow();
213
- const source = new FakeSource(succeed([scoped('s', 'a')]));
214
- expect(await index.rebuild(source, embed)).toSucceedWith(1);
215
- expect(index.size).toBe(1);
216
- // The 2-dim query now succeeds (dimension was reset by rebuild).
217
- expect(await index.query(Float32Array.from([97, 1]), 1)).toSucceed();
218
- });
219
- test('fails loudly when the source list fails', async () => {
220
- const index = InMemoryCosineIndex.create().orThrow();
221
- // Seed an entry so the reset-before-list rollback is observable, not just "stayed empty".
222
- (await index.add(target('s', 'seed'), Float32Array.from([1, 1]))).orThrow();
223
- const source = new FakeSource(fail('disk gone'));
224
- expect(await index.rebuild(source, embed)).toFailWith(/failed to list records: disk gone/i);
225
- expect(index.size).toBe(0);
226
- });
227
- test('fails loudly and rolls back to empty when an embedding fails mid-rebuild', async () => {
228
- const index = InMemoryCosineIndex.create().orThrow();
229
- // Seed an existing entry so the rollback (not merely "stayed empty") is observable.
230
- (await index.add(target('s', 'seed'), Float32Array.from([1, 1]))).orThrow();
231
- // First record embeds fine, the second fails — so a naive impl would leave
232
- // record 'a' indexed; the rollback must clear it.
233
- let calls = 0;
234
- const flakyEmbed = () => {
235
- calls += 1;
236
- return Promise.resolve(calls === 1 ? succeed(Float32Array.from([1, 1])) : fail('no model'));
237
- };
238
- const source = new FakeSource(succeed([scoped('conv-a', 'turn-1'), scoped('conv-b', 'turn-1')]));
239
- // The failing record's error names its scope-qualified key.
240
- expect(await index.rebuild(source, flakyEmbed)).toFailWith(/embedding 'conv-b\0turn-1' failed: no model/i);
241
- expect(index.size).toBe(0);
242
- });
243
- test('fails loudly and rolls back to empty when adding an embedded vector fails', async () => {
244
- const index = InMemoryCosineIndex.create().orThrow();
245
- const source = new FakeSource(succeed([scoped('s', 'a')]));
246
- const emptyEmbed = () => Promise.resolve(succeed(new Float32Array(0)));
247
- expect(await index.rebuild(source, emptyEmbed)).toFailWith(/empty vector/i);
248
- expect(index.size).toBe(0);
249
- });
250
- });
251
- });
252
- //# sourceMappingURL=inMemoryCosineIndex.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inMemoryCosineIndex.test.js","sourceRoot":"","sources":["../../../../src/test/unit/vector/inMemoryCosineIndex.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAU,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAML,mBAAmB,EAGpB,MAAM,gBAAgB,CAAC;AAExB,0DAA0D;AAC1D,SAAS,MAAM,CAAC,KAAa,EAAE,EAAU;IACvC,OAAO,EAAE,KAAK,EAAE,KAAuB,EAAE,EAAE,EAAE,EAAc,EAAE,CAAC;AAChE,CAAC;AAED,gFAAgF;AAChF,SAAS,MAAM,CAAC,EAAU,EAAE,OAAe,QAAQ,EAAE,EAAE;IACrD,OAAO;QACL,0EAA0E;QAC1E,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAc,EAAwC;QACtE,IAAI;KACL,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,SAAS,MAAM,CAAC,KAAa,EAAE,EAAU,EAAE,IAAa;IACtD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC;AACjE,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU;IAEd,YAAmB,MAAkD;QACnE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IACM,IAAI;QACT,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;CACF;AAED,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,KA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EAA2E,EAAE,KAAK,IAAI,EAAE;YAC3F,MAAM,KAAK,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;YACrD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,UAAU,GAAG,GAAkC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtG,MAAM,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;YAC5E,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport '@fgv/ts-utils-jest';\nimport { Result, fail, succeed } from '@fgv/ts-utils';\nimport {\n IEdgeTarget,\n IMemoryRecord,\n IMemoryRecordSource,\n IScopedMemoryRecord,\n IVectorQueryHit,\n InMemoryCosineIndex,\n MemoryId,\n MemoryScopeKey\n} from '../../../index';\n\n/** A scope-qualified target from a `(scope, id)` pair. */\nfunction target(scope: string, id: string): IEdgeTarget {\n return { scope: scope as MemoryScopeKey, id: id as MemoryId };\n}\n\n/** A trivial record carrying just the id + a marker body, for rebuild tests. */\nfunction record(id: string, body: string = `body-${id}`): IMemoryRecord<unknown> {\n return {\n // The cosine index only reads `envelope.id`; a minimal envelope suffices.\n envelope: { id: id as MemoryId } as IMemoryRecord<unknown>['envelope'],\n body\n };\n}\n\n/** A scope-qualified record entry for a rebuild source. */\nfunction scoped(scope: string, id: string, body?: string): IScopedMemoryRecord {\n return { target: target(scope, id), record: record(id, body) };\n}\n\n/** A scripted record source for `rebuild`. */\nclass FakeSource implements IMemoryRecordSource {\n private readonly _result: Result<ReadonlyArray<IScopedMemoryRecord>>;\n public constructor(result: Result<ReadonlyArray<IScopedMemoryRecord>>) {\n this._result = result;\n }\n public list(): Promise<Result<ReadonlyArray<IScopedMemoryRecord>>> {\n return Promise.resolve(this._result);\n }\n}\n\ndescribe('InMemoryCosineIndex', () => {\n describe('add', () => {\n test('returns the scoped-target key as the embedding ref and tracks size', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n expect(index.size).toBe(0);\n const t = target('conv-a', 'turn-1');\n expect(await index.add(t, Float32Array.from([1, 0]))).toSucceedWith(`conv-a\\0turn-1`);\n expect(index.size).toBe(1);\n });\n\n test('replaces the vector on a same-target add', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const t = target('conv-a', 'turn-1');\n expect(await index.add(t, Float32Array.from([1, 0]))).toSucceed();\n expect(await index.add(t, Float32Array.from([0, 1]))).toSucceed();\n expect(index.size).toBe(1);\n // The query now matches the replacement vector ([0,1]) not the original.\n expect(await index.query(Float32Array.from([0, 1]), 1)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits[0].score).toBeCloseTo(1);\n }\n );\n });\n\n test('same stem in different scopes are distinct entries — the second add does NOT clobber the first', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const a = target('conv-a', 'turn-3');\n const b = target('conv-b', 'turn-3');\n // Two records with the identical stem, orthogonal embeddings.\n expect(await index.add(a, Float32Array.from([1, 0]))).toSucceed();\n expect(await index.add(b, Float32Array.from([0, 1]))).toSucceed();\n // The bug: a bare-id index would have collapsed these to one entry.\n expect(index.size).toBe(2);\n // A query surfaces BOTH as distinct hits carrying distinct scoped targets.\n expect(await index.query(Float32Array.from([1, 1]), 5)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits).toHaveLength(2);\n expect(hits.map((h) => h.target)).toEqual(expect.arrayContaining([a, b]));\n // Each retains its OWN embedding: a matches [1,0], b matches [0,1].\n const byScope = new Map(hits.map((h) => [h.target.scope, h.score]));\n expect(byScope.get('conv-a' as MemoryScopeKey)).toBeCloseTo(1 / Math.sqrt(2));\n expect(byScope.get('conv-b' as MemoryScopeKey)).toBeCloseTo(1 / Math.sqrt(2));\n }\n );\n });\n\n test('fails loudly on an empty vector', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n expect(await index.add(target('conv-a', 'turn-1'), new Float32Array(0))).toFailWith(/empty vector/i);\n });\n\n test('stores a defensive copy — mutating the caller buffer after add does not corrupt the index', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const buffer = Float32Array.from([1, 0]);\n (await index.add(target('conv-a', 'turn-1'), buffer)).orThrow();\n // Mutate the caller's buffer after the add; the stored vector must be unaffected.\n buffer[0] = 0;\n buffer[1] = 1;\n expect(await index.query(Float32Array.from([1, 0]), 1)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n // Still maximally similar to [1,0] — proves the index kept its own copy.\n expect(hits[0].score).toBeCloseTo(1);\n }\n );\n });\n\n test('fails loudly on a dimension mismatch against the established dimension', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n expect(await index.add(target('conv-a', 'a'), Float32Array.from([1, 0]))).toSucceed();\n expect(await index.add(target('conv-a', 'b'), Float32Array.from([1, 0, 0]))).toFailWith(\n /dimension 3 does not match index dimension 2/i\n );\n });\n });\n\n describe('query', () => {\n async function seeded(): Promise<InMemoryCosineIndex> {\n const index = InMemoryCosineIndex.create().orThrow();\n (await index.add(target('s', 'a'), Float32Array.from([1, 0]))).orThrow();\n (await index.add(target('s', 'b'), Float32Array.from([0, 1]))).orThrow();\n (await index.add(target('s', 'c'), Float32Array.from([1, 1]))).orThrow();\n return index;\n }\n\n test('returns hits in descending cosine-similarity order', async () => {\n const index = await seeded();\n expect(await index.query(Float32Array.from([1, 0]), 3)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits.map((h) => h.target.id)).toEqual(['a', 'c', 'b']);\n expect(hits[0].score).toBeCloseTo(1);\n expect(hits[1].score).toBeCloseTo(1 / Math.sqrt(2));\n expect(hits[2].score).toBeCloseTo(0);\n }\n );\n });\n\n test('truncates to topK', async () => {\n const index = await seeded();\n expect(await index.query(Float32Array.from([1, 0]), 2)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits.map((h) => h.target.id)).toEqual(['a', 'c']);\n }\n );\n });\n\n test('returns empty for a non-positive topK', async () => {\n const index = await seeded();\n expect(await index.query(Float32Array.from([1, 0]), 0)).toSucceedWith([]);\n expect(await index.query(Float32Array.from([1, 0]), -1)).toSucceedWith([]);\n });\n\n test('returns empty when the index is empty (no dimension check)', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n expect(await index.query(Float32Array.from([1, 2, 3, 4]), 5)).toSucceedWith([]);\n });\n\n test('fails loudly on a query-dimension mismatch', async () => {\n const index = await seeded();\n expect(await index.query(Float32Array.from([1, 0, 0]), 3)).toFailWith(\n /query dimension 3 does not match index dimension 2/i\n );\n });\n\n test('scores a degenerate (zero-magnitude) stored vector as 0 rather than NaN', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n (await index.add(target('s', 'zero'), Float32Array.from([0, 0]))).orThrow();\n (await index.add(target('s', 'unit'), Float32Array.from([1, 0]))).orThrow();\n expect(await index.query(Float32Array.from([1, 0]), 2)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits.map((h) => h.target.id)).toEqual(['unit', 'zero']);\n expect(hits[1].score).toBe(0);\n }\n );\n });\n\n test('scores against a degenerate (zero-magnitude) query as 0 rather than NaN', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n (await index.add(target('s', 'unit'), Float32Array.from([1, 0]))).orThrow();\n expect(await index.query(Float32Array.from([0, 0]), 1)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits[0].score).toBe(0);\n }\n );\n });\n });\n\n describe('remove', () => {\n test('removes a vector and is reflected in subsequent queries', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const a = target('s', 'a');\n const b = target('s', 'b');\n (await index.add(a, Float32Array.from([1, 0]))).orThrow();\n (await index.add(b, Float32Array.from([0, 1]))).orThrow();\n expect(await index.remove(a)).toSucceedWith(a);\n expect(index.size).toBe(1);\n expect(await index.query(Float32Array.from([1, 0]), 5)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits.map((h) => h.target.id)).toEqual(['b']);\n }\n );\n });\n\n test('removes only the scoped target — a same-stem record in another scope is left intact', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const a = target('conv-a', 'turn-3');\n const b = target('conv-b', 'turn-3');\n (await index.add(a, Float32Array.from([1, 0]))).orThrow();\n (await index.add(b, Float32Array.from([0, 1]))).orThrow();\n expect(await index.remove(a)).toSucceedWith(a);\n expect(index.size).toBe(1);\n // conv-b's embedding survives untouched.\n expect(await index.query(Float32Array.from([0, 1]), 5)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits).toHaveLength(1);\n expect(hits[0].target).toEqual(b);\n expect(hits[0].score).toBeCloseTo(1);\n }\n );\n });\n\n test('is idempotent — removing an absent target still succeeds', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const t = target('s', 'missing');\n expect(await index.remove(t)).toSucceedWith(t);\n });\n });\n\n describe('rebuild', () => {\n const embed = (r: IMemoryRecord<unknown>): Promise<Result<Float32Array>> => {\n // Deterministic: encode the id's first char code into a 2-vector.\n const code: number = (r.envelope.id as string).charCodeAt(0);\n return Promise.resolve(succeed(Float32Array.from([code, 1])));\n };\n\n test('re-embeds every scoped record from the source and reports the count', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const source = new FakeSource(succeed([scoped('s', 'a'), scoped('s', 'b'), scoped('s', 'c')]));\n expect(await index.rebuild(source, embed)).toSucceedWith(3);\n expect(index.size).toBe(3);\n expect(await index.query(Float32Array.from([99, 1]), 1)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n // 'c' = char code 99, the closest to the query vector.\n expect(hits[0].target.id).toBe('c');\n }\n );\n });\n\n test('keeps same-stem records under different scopes distinct across a rebuild', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const source = new FakeSource(succeed([scoped('conv-a', 'turn-3'), scoped('conv-b', 'turn-3')]));\n // The embedder keys only off the (shared) id, so a bare-id rebuild would\n // index just one entry; the scoped rebuild indexes both.\n expect(await index.rebuild(source, embed)).toSucceedWith(2);\n expect(index.size).toBe(2);\n expect(await index.query(Float32Array.from([116, 1]), 5)).toSucceedAndSatisfy(\n (hits: ReadonlyArray<IVectorQueryHit>) => {\n expect(hits).toHaveLength(2);\n expect(hits.map((h) => h.target.scope).sort()).toEqual(['conv-a', 'conv-b']);\n }\n );\n });\n\n test('clears prior contents and re-establishes the dimension', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n // Seed a 3-dim vector, then rebuild with a 2-dim embedder.\n (await index.add(target('s', 'old'), Float32Array.from([1, 2, 3]))).orThrow();\n const source = new FakeSource(succeed([scoped('s', 'a')]));\n expect(await index.rebuild(source, embed)).toSucceedWith(1);\n expect(index.size).toBe(1);\n // The 2-dim query now succeeds (dimension was reset by rebuild).\n expect(await index.query(Float32Array.from([97, 1]), 1)).toSucceed();\n });\n\n test('fails loudly when the source list fails', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n // Seed an entry so the reset-before-list rollback is observable, not just \"stayed empty\".\n (await index.add(target('s', 'seed'), Float32Array.from([1, 1]))).orThrow();\n const source = new FakeSource(fail('disk gone'));\n expect(await index.rebuild(source, embed)).toFailWith(/failed to list records: disk gone/i);\n expect(index.size).toBe(0);\n });\n\n test('fails loudly and rolls back to empty when an embedding fails mid-rebuild', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n // Seed an existing entry so the rollback (not merely \"stayed empty\") is observable.\n (await index.add(target('s', 'seed'), Float32Array.from([1, 1]))).orThrow();\n // First record embeds fine, the second fails — so a naive impl would leave\n // record 'a' indexed; the rollback must clear it.\n let calls: number = 0;\n const flakyEmbed = (): Promise<Result<Float32Array>> => {\n calls += 1;\n return Promise.resolve(calls === 1 ? succeed(Float32Array.from([1, 1])) : fail('no model'));\n };\n const source = new FakeSource(succeed([scoped('conv-a', 'turn-1'), scoped('conv-b', 'turn-1')]));\n // The failing record's error names its scope-qualified key.\n expect(await index.rebuild(source, flakyEmbed)).toFailWith(\n /embedding 'conv-b\\0turn-1' failed: no model/i\n );\n expect(index.size).toBe(0);\n });\n\n test('fails loudly and rolls back to empty when adding an embedded vector fails', async () => {\n const index = InMemoryCosineIndex.create().orThrow();\n const source = new FakeSource(succeed([scoped('s', 'a')]));\n const emptyEmbed = (): Promise<Result<Float32Array>> => Promise.resolve(succeed(new Float32Array(0)));\n expect(await index.rebuild(source, emptyEmbed)).toFailWith(/empty vector/i);\n expect(index.size).toBe(0);\n });\n });\n});\n"]}