cactus-react-native 1.2.1 → 1.5.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 (238) hide show
  1. package/README.md +765 -33
  2. package/android/CMakeLists.txt +4 -3
  3. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +20 -1
  4. package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
  5. package/android/src/main/jniLibs/arm64-v8a/libcactus_util.a +0 -0
  6. package/cpp/HybridCactus.cpp +231 -19
  7. package/cpp/HybridCactus.hpp +25 -3
  8. package/cpp/HybridCactusIndex.cpp +325 -0
  9. package/cpp/HybridCactusIndex.hpp +43 -0
  10. package/cpp/HybridCactusUtil.cpp +3 -3
  11. package/cpp/HybridCactusUtil.hpp +2 -1
  12. package/cpp/cactus_ffi.h +107 -2
  13. package/cpp/cactus_util.h +1 -1
  14. package/ios/HybridCactusFileSystem.swift +23 -2
  15. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +2 -0
  16. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +107 -2
  17. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_telemetry.h +656 -0
  18. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +145 -18
  19. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +135 -7
  20. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gemma_tools.h +549 -0
  21. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +193 -26
  22. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +54 -195
  23. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +399 -140
  24. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
  25. package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
  26. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +2 -0
  27. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +107 -2
  28. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_telemetry.h +656 -0
  29. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +145 -18
  30. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +135 -7
  31. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/gemma_tools.h +549 -0
  32. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +193 -26
  33. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +54 -195
  34. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +399 -140
  35. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
  36. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
  37. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
  38. package/ios/cactus_util.xcframework/Info.plist +4 -4
  39. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +1 -1
  40. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/database.h +27 -0
  41. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Info.plist +0 -0
  42. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/cactus_util +0 -0
  43. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/cactus_util.h +1 -1
  44. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/database.h +27 -0
  45. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Info.plist +0 -0
  46. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/_CodeSignature/CodeResources +3 -3
  47. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
  48. package/lib/module/api/Database.js +12 -95
  49. package/lib/module/api/Database.js.map +1 -1
  50. package/lib/module/classes/CactusIndex.js +45 -0
  51. package/lib/module/classes/CactusIndex.js.map +1 -0
  52. package/lib/module/classes/CactusLM.js +65 -17
  53. package/lib/module/classes/CactusLM.js.map +1 -1
  54. package/lib/module/classes/CactusSTT.js +104 -17
  55. package/lib/module/classes/CactusSTT.js.map +1 -1
  56. package/lib/module/config/CactusConfig.js +2 -0
  57. package/lib/module/config/CactusConfig.js.map +1 -1
  58. package/lib/module/constants/packageVersion.js +1 -1
  59. package/lib/module/hooks/useCactusIndex.js +175 -0
  60. package/lib/module/hooks/useCactusIndex.js.map +1 -0
  61. package/lib/module/hooks/useCactusLM.js +68 -7
  62. package/lib/module/hooks/useCactusLM.js.map +1 -1
  63. package/lib/module/hooks/useCactusSTT.js +102 -6
  64. package/lib/module/hooks/useCactusSTT.js.map +1 -1
  65. package/lib/module/index.js +2 -0
  66. package/lib/module/index.js.map +1 -1
  67. package/lib/module/models.js +336 -0
  68. package/lib/module/models.js.map +1 -0
  69. package/lib/module/native/Cactus.js +61 -13
  70. package/lib/module/native/Cactus.js.map +1 -1
  71. package/lib/module/native/CactusFileSystem.js +3 -0
  72. package/lib/module/native/CactusFileSystem.js.map +1 -1
  73. package/lib/module/native/CactusIndex.js +32 -0
  74. package/lib/module/native/CactusIndex.js.map +1 -0
  75. package/lib/module/native/CactusUtil.js +16 -3
  76. package/lib/module/native/CactusUtil.js.map +1 -1
  77. package/lib/module/native/index.js +1 -0
  78. package/lib/module/native/index.js.map +1 -1
  79. package/lib/module/specs/CactusIndex.nitro.js +4 -0
  80. package/lib/module/specs/CactusIndex.nitro.js.map +1 -0
  81. package/lib/module/telemetry/Telemetry.js +3 -1
  82. package/lib/module/telemetry/Telemetry.js.map +1 -1
  83. package/lib/module/types/CactusIndex.js +2 -0
  84. package/lib/module/types/{CactusModel.js.map → CactusIndex.js.map} +1 -1
  85. package/lib/module/types/CactusLM.js +2 -0
  86. package/lib/module/types/CactusSTT.js +2 -0
  87. package/lib/module/types/common.js +2 -0
  88. package/lib/module/types/{CactusSTTModel.js.map → common.js.map} +1 -1
  89. package/lib/typescript/src/api/Database.d.ts +4 -7
  90. package/lib/typescript/src/api/Database.d.ts.map +1 -1
  91. package/lib/typescript/src/classes/CactusIndex.d.ts +15 -0
  92. package/lib/typescript/src/classes/CactusIndex.d.ts.map +1 -0
  93. package/lib/typescript/src/classes/CactusLM.d.ts +12 -5
  94. package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
  95. package/lib/typescript/src/classes/CactusSTT.d.ts +15 -5
  96. package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
  97. package/lib/typescript/src/config/CactusConfig.d.ts +1 -0
  98. package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -1
  99. package/lib/typescript/src/constants/packageVersion.d.ts +1 -1
  100. package/lib/typescript/src/hooks/useCactusIndex.d.ts +14 -0
  101. package/lib/typescript/src/hooks/useCactusIndex.d.ts.map +1 -0
  102. package/lib/typescript/src/hooks/useCactusLM.d.ts +6 -4
  103. package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
  104. package/lib/typescript/src/hooks/useCactusSTT.d.ts +13 -5
  105. package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
  106. package/lib/typescript/src/index.d.ts +6 -4
  107. package/lib/typescript/src/index.d.ts.map +1 -1
  108. package/lib/typescript/src/models.d.ts +6 -0
  109. package/lib/typescript/src/models.d.ts.map +1 -0
  110. package/lib/typescript/src/native/Cactus.d.ts +10 -3
  111. package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
  112. package/lib/typescript/src/native/CactusFileSystem.d.ts +1 -0
  113. package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -1
  114. package/lib/typescript/src/native/CactusIndex.d.ts +12 -0
  115. package/lib/typescript/src/native/CactusIndex.d.ts.map +1 -0
  116. package/lib/typescript/src/native/CactusUtil.d.ts.map +1 -1
  117. package/lib/typescript/src/native/index.d.ts +1 -0
  118. package/lib/typescript/src/native/index.d.ts.map +1 -1
  119. package/lib/typescript/src/specs/Cactus.nitro.d.ts +9 -2
  120. package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
  121. package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts +1 -0
  122. package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts.map +1 -1
  123. package/lib/typescript/src/specs/CactusIndex.nitro.d.ts +24 -0
  124. package/lib/typescript/src/specs/CactusIndex.nitro.d.ts.map +1 -0
  125. package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +1 -1
  126. package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +1 -1
  127. package/lib/typescript/src/types/CactusIndex.d.ts +34 -0
  128. package/lib/typescript/src/types/CactusIndex.d.ts.map +1 -0
  129. package/lib/typescript/src/types/CactusLM.d.ts +19 -0
  130. package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
  131. package/lib/typescript/src/types/CactusSTT.d.ts +21 -1
  132. package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
  133. package/lib/typescript/src/types/common.d.ts +28 -0
  134. package/lib/typescript/src/types/common.d.ts.map +1 -0
  135. package/nitro.json +3 -0
  136. package/nitrogen/generated/android/c++/JDeviceInfo.hpp +1 -1
  137. package/nitrogen/generated/android/c++/JFunc_void_double.hpp +1 -1
  138. package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +1 -1
  139. package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +1 -1
  140. package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +1 -1
  141. package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +1 -1
  142. package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.cpp +17 -1
  143. package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.hpp +2 -1
  144. package/nitrogen/generated/android/c++/JHybridCactusImageSpec.cpp +1 -1
  145. package/nitrogen/generated/android/c++/JHybridCactusImageSpec.hpp +1 -1
  146. package/nitrogen/generated/android/cactus+autolinking.cmake +2 -1
  147. package/nitrogen/generated/android/cactus+autolinking.gradle +1 -1
  148. package/nitrogen/generated/android/cactusOnLoad.cpp +11 -1
  149. package/nitrogen/generated/android/cactusOnLoad.hpp +1 -1
  150. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +1 -1
  151. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/Func_void_double.kt +1 -1
  152. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +1 -1
  153. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +1 -1
  154. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusFileSystemSpec.kt +5 -1
  155. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusImageSpec.kt +1 -1
  156. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/cactusOnLoad.kt +1 -1
  157. package/nitrogen/generated/ios/Cactus+autolinking.rb +1 -1
  158. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +1 -1
  159. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +1 -1
  160. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +1 -1
  161. package/nitrogen/generated/ios/CactusAutolinking.mm +11 -1
  162. package/nitrogen/generated/ios/CactusAutolinking.swift +1 -1
  163. package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +1 -1
  164. package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +1 -1
  165. package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +1 -1
  166. package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +1 -1
  167. package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.cpp +1 -1
  168. package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.hpp +9 -1
  169. package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.cpp +1 -1
  170. package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.hpp +1 -1
  171. package/nitrogen/generated/ios/swift/DeviceInfo.swift +1 -1
  172. package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
  173. package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +1 -1
  174. package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
  175. package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
  176. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
  177. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +1 -1
  178. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
  179. package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +1 -1
  180. package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +1 -1
  181. package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +1 -1
  182. package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +1 -1
  183. package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec.swift +2 -1
  184. package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec_cxx.swift +20 -1
  185. package/nitrogen/generated/ios/swift/HybridCactusImageSpec.swift +1 -1
  186. package/nitrogen/generated/ios/swift/HybridCactusImageSpec_cxx.swift +1 -1
  187. package/nitrogen/generated/shared/c++/CactusIndexGetResult.hpp +84 -0
  188. package/nitrogen/generated/shared/c++/CactusIndexQueryResult.hpp +79 -0
  189. package/nitrogen/generated/shared/c++/DeviceInfo.hpp +1 -1
  190. package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +1 -1
  191. package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +1 -1
  192. package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +1 -1
  193. package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +1 -1
  194. package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.cpp +2 -1
  195. package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.hpp +2 -1
  196. package/nitrogen/generated/shared/c++/HybridCactusImageSpec.cpp +1 -1
  197. package/nitrogen/generated/shared/c++/HybridCactusImageSpec.hpp +1 -1
  198. package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.cpp +27 -0
  199. package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.hpp +76 -0
  200. package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +8 -1
  201. package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +11 -3
  202. package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +1 -1
  203. package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +2 -2
  204. package/package.json +2 -2
  205. package/src/api/Database.ts +14 -135
  206. package/src/classes/CactusIndex.ts +58 -0
  207. package/src/classes/CactusLM.ts +87 -19
  208. package/src/classes/CactusSTT.ts +134 -20
  209. package/src/config/CactusConfig.ts +3 -0
  210. package/src/constants/packageVersion.ts +1 -1
  211. package/src/hooks/useCactusIndex.ts +195 -0
  212. package/src/hooks/useCactusLM.ts +88 -8
  213. package/src/hooks/useCactusSTT.ts +119 -7
  214. package/src/index.tsx +22 -2
  215. package/src/models.ts +344 -0
  216. package/src/native/Cactus.ts +95 -13
  217. package/src/native/CactusFileSystem.ts +4 -0
  218. package/src/native/CactusIndex.ts +54 -0
  219. package/src/native/CactusUtil.ts +19 -3
  220. package/src/native/index.ts +1 -0
  221. package/src/specs/Cactus.nitro.ts +18 -2
  222. package/src/specs/CactusFileSystem.nitro.ts +2 -0
  223. package/src/specs/CactusIndex.nitro.ts +31 -0
  224. package/src/specs/CactusUtil.nitro.ts +1 -1
  225. package/src/telemetry/Telemetry.ts +1 -1
  226. package/src/types/CactusIndex.ts +40 -0
  227. package/src/types/CactusLM.ts +24 -0
  228. package/src/types/CactusSTT.ts +27 -1
  229. package/src/types/common.ts +28 -0
  230. package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
  231. package/lib/module/types/CactusModel.js +0 -2
  232. package/lib/module/types/CactusSTTModel.js +0 -2
  233. package/lib/typescript/src/types/CactusModel.d.ts +0 -13
  234. package/lib/typescript/src/types/CactusModel.d.ts.map +0 -1
  235. package/lib/typescript/src/types/CactusSTTModel.d.ts +0 -8
  236. package/lib/typescript/src/types/CactusSTTModel.d.ts.map +0 -1
  237. package/src/types/CactusModel.ts +0 -15
  238. package/src/types/CactusSTTModel.ts +0 -10
package/README.md CHANGED
@@ -78,6 +78,32 @@ const App = () => {
78
78
 
79
79
  ## Language Model
80
80
 
81
+ ### Model Options
82
+
83
+ Choose model quantization and NPU acceleration with Pro models.
84
+
85
+ ```typescript
86
+ import { CactusLM } from 'cactus-react-native';
87
+
88
+ // Use int4 for faster performance and smaller file size
89
+ const cactusLM = new CactusLM({
90
+ model: 'lfm2-vl-450m',
91
+ options: {
92
+ quantization: 'int4', // 'int4' or 'int8'
93
+ pro: false
94
+ }
95
+ });
96
+
97
+ // Use pro models for NPU acceleration
98
+ const cactusPro = new CactusLM({
99
+ model: 'lfm2-vl-450m',
100
+ options: {
101
+ quantization: 'int4',
102
+ pro: true
103
+ }
104
+ });
105
+ ```
106
+
81
107
  ### Completion
82
108
 
83
109
  Generate text responses from the model by providing a conversation history.
@@ -298,6 +324,82 @@ const App = () => {
298
324
  };
299
325
  ```
300
326
 
327
+ ### Tokenization
328
+
329
+ Convert text into tokens using the model's tokenizer.
330
+
331
+ #### Class
332
+
333
+ ```typescript
334
+ import { CactusLM } from 'cactus-react-native';
335
+
336
+ const cactusLM = new CactusLM();
337
+
338
+ const result = await cactusLM.tokenize({ text: 'Hello, World!' });
339
+ console.log('Token IDs:', result.tokens);
340
+ ```
341
+
342
+ #### Hook
343
+
344
+ ```tsx
345
+ import { useCactusLM } from 'cactus-react-native';
346
+
347
+ const App = () => {
348
+ const cactusLM = useCactusLM();
349
+
350
+ const handleTokenize = async () => {
351
+ const result = await cactusLM.tokenize({ text: 'Hello, World!' });
352
+ console.log('Token IDs:', result.tokens);
353
+ };
354
+
355
+ return <Button title="Tokenize" onPress={handleTokenize} />;
356
+ };
357
+ ```
358
+
359
+ ### Score Window
360
+
361
+ Calculate perplexity scores for a window of tokens within a sequence.
362
+
363
+ #### Class
364
+
365
+ ```typescript
366
+ import { CactusLM } from 'cactus-react-native';
367
+
368
+ const cactusLM = new CactusLM();
369
+
370
+ const tokens = [123, 456, 789, 101, 112];
371
+ const result = await cactusLM.scoreWindow({
372
+ tokens,
373
+ start: 1,
374
+ end: 3,
375
+ context: 2
376
+ });
377
+ console.log('Score:', result.score);
378
+ ```
379
+
380
+ #### Hook
381
+
382
+ ```tsx
383
+ import { useCactusLM } from 'cactus-react-native';
384
+
385
+ const App = () => {
386
+ const cactusLM = useCactusLM();
387
+
388
+ const handleScoreWindow = async () => {
389
+ const tokens = [123, 456, 789, 101, 112];
390
+ const result = await cactusLM.scoreWindow({
391
+ tokens,
392
+ start: 1,
393
+ end: 3,
394
+ context: 2
395
+ });
396
+ console.log('Score:', result.score);
397
+ };
398
+
399
+ return <Button title="Score Window" onPress={handleScoreWindow} />;
400
+ };
401
+ ```
402
+
301
403
  ### Embedding
302
404
 
303
405
  Convert text and images into numerical vector representations that capture semantic meaning, useful for similarity search and semantic understanding.
@@ -423,7 +525,7 @@ The `CactusSTT` class provides audio transcription and audio embedding capabilit
423
525
 
424
526
  ### Transcription
425
527
 
426
- Transcribe audio files to text with streaming support.
528
+ Transcribe audio to text with streaming support. Accepts either a file path or raw PCM audio samples.
427
529
 
428
530
  #### Class
429
531
 
@@ -434,12 +536,22 @@ const cactusSTT = new CactusSTT({ model: 'whisper-small' });
434
536
 
435
537
  await cactusSTT.init();
436
538
 
539
+ // Transcribe from file path
437
540
  const result = await cactusSTT.transcribe({
438
- audioFilePath: 'path/to/audio.wav',
541
+ audio: 'path/to/audio.wav',
439
542
  onToken: (token) => console.log('Token:', token)
440
543
  });
441
544
 
442
545
  console.log('Transcription:', result.response);
546
+
547
+ // Or transcribe from raw PCM samples
548
+ const pcmSamples: number[] = [/* ... */];
549
+ const result2 = await cactusSTT.transcribe({
550
+ audio: pcmSamples,
551
+ onToken: (token) => console.log('Token:', token)
552
+ });
553
+
554
+ console.log('Transcription:', result2.response);
443
555
  ```
444
556
 
445
557
  #### Hook
@@ -451,10 +563,17 @@ const App = () => {
451
563
  const cactusSTT = useCactusSTT({ model: 'whisper-small' });
452
564
 
453
565
  const handleTranscribe = async () => {
566
+ // Transcribe from file path
454
567
  const result = await cactusSTT.transcribe({
455
- audioFilePath: 'path/to/audio.wav',
568
+ audio: 'path/to/audio.wav',
456
569
  });
457
570
  console.log('Transcription:', result.response);
571
+
572
+ const pcmSamples: number[] = [/* ... */];
573
+ const result2 = await cactusSTT.transcribe({
574
+ audio: pcmSamples,
575
+ });
576
+ console.log('Transcription:', result2.response);
458
577
  };
459
578
 
460
579
  return (
@@ -466,6 +585,60 @@ const App = () => {
466
585
  };
467
586
  ```
468
587
 
588
+ ### Streaming Transcription
589
+
590
+ Transcribe audio in real-time with incremental results.
591
+
592
+ #### Class
593
+
594
+ ```typescript
595
+ import { CactusSTT } from 'cactus-react-native';
596
+
597
+ const cactusSTT = new CactusSTT({ model: 'whisper-small' });
598
+
599
+ await cactusSTT.streamTranscribeInit();
600
+
601
+ const audioChunk: number[] = [/* PCM samples */];
602
+ await cactusSTT.streamTranscribeInsert({ audio: audioChunk });
603
+
604
+ const result = await cactusSTT.streamTranscribeProcess({
605
+ options: { confirmationThreshold: 0.95 }
606
+ });
607
+
608
+ console.log('Confirmed:', result.confirmed);
609
+ console.log('Pending:', result.pending);
610
+
611
+ const final = await cactusSTT.streamTranscribeFinalize();
612
+ await cactusSTT.streamTranscribeDestroy();
613
+ ```
614
+
615
+ #### Hook
616
+
617
+ ```tsx
618
+ import { useCactusSTT } from 'cactus-react-native';
619
+
620
+ const App = () => {
621
+ const cactusSTT = useCactusSTT({ model: 'whisper-small' });
622
+
623
+ const handleStream = async () => {
624
+ await cactusSTT.streamTranscribeInit();
625
+
626
+ const audioChunk: number[] = [/* PCM samples */];
627
+ await cactusSTT.streamTranscribeInsert({ audio: audioChunk });
628
+
629
+ await cactusSTT.streamTranscribeProcess();
630
+ };
631
+
632
+ return (
633
+ <>
634
+ <Button onPress={handleStream} title="Stream" />
635
+ <Text>{cactusSTT.streamTranscribeConfirmed}</Text>
636
+ <Text>{cactusSTT.streamTranscribePending}</Text>
637
+ </>
638
+ );
639
+ };
640
+ ```
641
+
469
642
  ### Audio Embedding
470
643
 
471
644
  Generate embeddings from audio files for audio understanding.
@@ -507,6 +680,251 @@ const App = () => {
507
680
  };
508
681
  ```
509
682
 
683
+ ## Vector Index
684
+
685
+ The `CactusIndex` class provides a vector database for storing and querying embeddings with metadata. Enabling similarity search and retrieval.
686
+
687
+ ### Creating and Initializing an Index
688
+
689
+ #### Class
690
+
691
+ ```typescript
692
+ import { CactusIndex } from 'cactus-react-native';
693
+
694
+ const cactusIndex = new CactusIndex('my-index', 1024);
695
+ await cactusIndex.init();
696
+ ```
697
+
698
+ #### Hook
699
+
700
+ ```tsx
701
+ import { useCactusIndex } from 'cactus-react-native';
702
+
703
+ const App = () => {
704
+ const cactusIndex = useCactusIndex({
705
+ name: 'my-index',
706
+ embeddingDim: 1024
707
+ });
708
+
709
+ const handleInit = async () => {
710
+ await cactusIndex.init();
711
+ };
712
+
713
+ return <Button title="Initialize Index" onPress={handleInit} />
714
+ };
715
+ ```
716
+
717
+ ### Adding Documents
718
+
719
+ Add documents with their embeddings and metadata to the index.
720
+
721
+ #### Class
722
+
723
+ ```typescript
724
+ import { CactusIndex } from 'cactus-react-native';
725
+
726
+ const cactusIndex = new CactusIndex('my-index', 1024);
727
+ await cactusIndex.init();
728
+
729
+ await cactusIndex.add({
730
+ ids: [1, 2, 3],
731
+ documents: ['First document', 'Second document', 'Third document'],
732
+ embeddings: [
733
+ [0.1, 0.2, ...],
734
+ [0.3, 0.4, ...],
735
+ [0.5, 0.6, ...]
736
+ ],
737
+ metadatas: ['metadata1', 'metadata2', 'metadata3']
738
+ });
739
+ ```
740
+
741
+ #### Hook
742
+
743
+ ```tsx
744
+ import { useCactusIndex } from 'cactus-react-native';
745
+
746
+ const App = () => {
747
+ const cactusIndex = useCactusIndex({
748
+ name: 'my-index',
749
+ embeddingDim: 1024
750
+ });
751
+
752
+ const handleAdd = async () => {
753
+ await cactusIndex.add({
754
+ ids: [1, 2, 3],
755
+ documents: ['First document', 'Second document', 'Third document'],
756
+ embeddings: [
757
+ [0.1, 0.2, ...],
758
+ [0.3, 0.4, ...],
759
+ [0.5, 0.6, ...]
760
+ ],
761
+ metadatas: ['metadata1', 'metadata2', 'metadata3']
762
+ });
763
+ };
764
+
765
+ return <Button title="Add Documents" onPress={handleAdd} />;
766
+ };
767
+ ```
768
+
769
+ ### Querying the Index
770
+
771
+ Search for similar documents using embedding vectors.
772
+
773
+ #### Class
774
+
775
+ ```typescript
776
+ import { CactusIndex } from 'cactus-react-native';
777
+
778
+ const cactusIndex = new CactusIndex('my-index', 1024);
779
+ await cactusIndex.init();
780
+
781
+ const result = await cactusIndex.query({
782
+ embeddings: [[0.1, 0.2, ...]],
783
+ options: {
784
+ topK: 5,
785
+ scoreThreshold: 0.7
786
+ }
787
+ });
788
+
789
+ console.log('IDs:', result.ids);
790
+ console.log('Scores:', result.scores);
791
+ ```
792
+
793
+ #### Hook
794
+
795
+ ```tsx
796
+ import { useCactusIndex } from 'cactus-react-native';
797
+
798
+ const App = () => {
799
+ const cactusIndex = useCactusIndex({
800
+ name: 'my-index',
801
+ embeddingDim: 1024
802
+ });
803
+
804
+ const handleQuery = async () => {
805
+ const result = await cactusIndex.query({
806
+ embeddings: [[0.1, 0.2, ...]],
807
+ options: {
808
+ topK: 5,
809
+ scoreThreshold: 0.7
810
+ }
811
+ });
812
+ console.log('IDs:', result.ids);
813
+ console.log('Scores:', result.scores);
814
+ };
815
+
816
+ return <Button title="Query Index" onPress={handleQuery} />;
817
+ };
818
+ ```
819
+
820
+ ### Retrieving Documents
821
+
822
+ Get documents by their IDs.
823
+
824
+ #### Class
825
+
826
+ ```typescript
827
+ import { CactusIndex } from 'cactus-react-native';
828
+
829
+ const cactusIndex = new CactusIndex('my-index', 1024);
830
+ await cactusIndex.init();
831
+
832
+ const result = await cactusIndex.get({ ids: [1, 2, 3] });
833
+ console.log('Documents:', result.documents);
834
+ console.log('Metadatas:', result.metadatas);
835
+ console.log('Embeddings:', result.embeddings);
836
+ ```
837
+
838
+ #### Hook
839
+
840
+ ```tsx
841
+ import { useCactusIndex } from 'cactus-react-native';
842
+
843
+ const App = () => {
844
+ const cactusIndex = useCactusIndex({
845
+ name: 'my-index',
846
+ embeddingDim: 1024
847
+ });
848
+
849
+ const handleGet = async () => {
850
+ const result = await cactusIndex.get({ ids: [1, 2, 3] });
851
+ console.log('Documents:', result.documents);
852
+ console.log('Metadatas:', result.metadatas);
853
+ console.log('Embeddings:', result.embeddings);
854
+ };
855
+
856
+ return <Button title="Get Documents" onPress={handleGet} />;
857
+ };
858
+ ```
859
+
860
+ ### Deleting Documents
861
+
862
+ Mark documents as deleted by their IDs.
863
+
864
+ #### Class
865
+
866
+ ```typescript
867
+ import { CactusIndex } from 'cactus-react-native';
868
+
869
+ const cactusIndex = new CactusIndex('my-index', 1024);
870
+ await cactusIndex.init();
871
+
872
+ await cactusIndex.delete({ ids: [1, 2, 3] });
873
+ ```
874
+
875
+ #### Hook
876
+
877
+ ```tsx
878
+ import { useCactusIndex } from 'cactus-react-native';
879
+
880
+ const App = () => {
881
+ const cactusIndex = useCactusIndex({
882
+ name: 'my-index',
883
+ embeddingDim: 1024
884
+ });
885
+
886
+ const handleDelete = async () => {
887
+ await cactusIndex.delete({ ids: [1, 2, 3] });
888
+ };
889
+
890
+ return <Button title="Delete Documents" onPress={handleDelete} />;
891
+ };
892
+ ```
893
+
894
+ ### Compacting the Index
895
+
896
+ Optimize the index by removing deleted documents and reorganizing data.
897
+
898
+ #### Class
899
+
900
+ ```typescript
901
+ import { CactusIndex } from 'cactus-react-native';
902
+
903
+ const cactusIndex = new CactusIndex('my-index', 1024);
904
+ await cactusIndex.init();
905
+
906
+ await cactusIndex.compact();
907
+ ```
908
+
909
+ #### Hook
910
+
911
+ ```tsx
912
+ import { useCactusIndex } from 'cactus-react-native';
913
+
914
+ const App = () => {
915
+ const cactusIndex = useCactusIndex({
916
+ name: 'my-index',
917
+ embeddingDim: 1024
918
+ });
919
+
920
+ const handleCompact = async () => {
921
+ await cactusIndex.compact();
922
+ };
923
+
924
+ return <Button title="Compact Index" onPress={handleCompact} />;
925
+ };
926
+ ```
927
+
510
928
  ## API Reference
511
929
 
512
930
  ### CactusLM Class
@@ -516,9 +934,12 @@ const App = () => {
516
934
  **`new CactusLM(params?: CactusLMParams)`**
517
935
 
518
936
  **Parameters:**
519
- - `model` - Model slug (default: `'qwen3-0.6'`).
937
+ - `model` - Model slug or absolute path to Cactus model (default: `'qwen3-0.6b'`).
520
938
  - `contextSize` - Context window size (default: `2048`).
521
939
  - `corpusDir` - Directory containing text files for RAG (default: `undefined`).
940
+ - `options` - Model options for quantization and NPU acceleration:
941
+ - `quantization` - Quantization type: `'int4'` | `'int8'` (default: `'int4'`).
942
+ - `pro` - Enable NPU-accelerated models (default: `false`).
522
943
 
523
944
  #### Methods
524
945
 
@@ -545,16 +966,35 @@ Performs text completion with optional streaming and tool support. Automatically
545
966
  - `topK` - Top-K sampling limit (default: model-optimized).
546
967
  - `maxTokens` - Maximum number of tokens to generate (default: `512`).
547
968
  - `stopSequences` - Array of strings to stop generation (default: `undefined`).
969
+ - `forceTools` - Force the model to call one of the provided tools (default: `false`).
548
970
  - `tools` - Array of `Tool` objects for function calling (default: `undefined`).
549
971
  - `onToken` - Callback for streaming tokens.
550
972
  - `mode` - Completion mode: `'local'` | `'hybrid'` (default: `'local'`)
551
973
 
974
+ **`tokenize(params: CactusLMTokenizeParams): Promise<CactusLMTokenizeResult>`**
975
+
976
+ Converts text into tokens using the model's tokenizer.
977
+
978
+ **Parameters:**
979
+ - `text` - Text to tokenize.
980
+
981
+ **`scoreWindow(params: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult>`**
982
+
983
+ Calculates perplexity scores for a window of tokens within a sequence.
984
+
985
+ **Parameters:**
986
+ - `tokens` - Array of token IDs.
987
+ - `start` - Start index of the window.
988
+ - `end` - End index of the window.
989
+ - `context` - Number of context tokens before the window.
990
+
552
991
  **`embed(params: CactusLMEmbedParams): Promise<CactusLMEmbedResult>`**
553
992
 
554
993
  Generates embeddings for the given text. Automatically calls `init()` if not already initialized. Throws an error if a generation (completion or embedding) is already in progress.
555
994
 
556
995
  **Parameters:**
557
996
  - `text` - Text to embed.
997
+ - `normalize` - Whether to normalize the embedding vector (default: `false`).
558
998
 
559
999
  **`imageEmbed(params: CactusLMImageEmbedParams): Promise<CactusLMImageEmbedResult>`**
560
1000
 
@@ -575,13 +1015,13 @@ Resets the model's internal state, clearing any cached context. Automatically ca
575
1015
 
576
1016
  Releases all resources associated with the model. Automatically calls `stop()` first. Safe to call even if the model is not initialized.
577
1017
 
578
- **`getModels(): Promise<CactusModel[]>`**
1018
+ **`getModels(): CactusModel[]`**
579
1019
 
580
- Fetches available models from the database and checks their download status.
1020
+ Returns available models.
581
1021
 
582
1022
  ### useCactusLM Hook
583
1023
 
584
- The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When model parameters (`model`, `contextSize`, or `corpusDir`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1024
+ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When model parameters (`model`, `contextSize`, `corpusDir`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
585
1025
 
586
1026
  #### State
587
1027
 
@@ -598,12 +1038,14 @@ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When m
598
1038
  - `download(params?: CactusLMDownloadParams): Promise<void>` - Downloads the model. Updates `isDownloading` and `downloadProgress` state during download. Sets `isDownloaded` to `true` on success.
599
1039
  - `init(): Promise<void>` - Initializes the model for inference. Sets `isInitializing` to `true` during initialization.
600
1040
  - `complete(params: CactusLMCompleteParams): Promise<CactusLMCompleteResult>` - Generates text completions. Automatically accumulates tokens in the `completion` state during streaming. Sets `isGenerating` to `true` while generating. Clears `completion` before starting.
1041
+ - `tokenize(params: CactusLMTokenizeParams): Promise<CactusLMTokenizeResult>` - Converts text into tokens. Sets `isGenerating` to `true` during operation.
1042
+ - `scoreWindow(params: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult>` - Calculates perplexity scores for a window of tokens. Sets `isGenerating` to `true` during operation.
601
1043
  - `embed(params: CactusLMEmbedParams): Promise<CactusLMEmbedResult>` - Generates embeddings for the given text. Sets `isGenerating` to `true` during operation.
602
1044
  - `imageEmbed(params: CactusLMImageEmbedParams): Promise<CactusLMImageEmbedResult>` - Generates embeddings for the given image. Sets `isGenerating` to `true` while generating.
603
1045
  - `stop(): Promise<void>` - Stops ongoing generation. Clears any errors.
604
1046
  - `reset(): Promise<void>` - Resets the model's internal state, clearing cached context. Also clears the `completion` state.
605
1047
  - `destroy(): Promise<void>` - Releases all resources associated with the model. Clears the `completion` state. Automatically called when the component unmounts.
606
- - `getModels(): Promise<CactusModel[]>` - Fetches available models from the database and checks their download status.
1048
+ - `getModels(): CactusModel[]` - Returns available models.
607
1049
 
608
1050
  ### CactusSTT Class
609
1051
 
@@ -612,8 +1054,11 @@ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When m
612
1054
  **`new CactusSTT(params?: CactusSTTParams)`**
613
1055
 
614
1056
  **Parameters:**
615
- - `model` - Model slug (default: `'whisper-small'`).
1057
+ - `model` - Model slug or absolute path to Cactus model (default: `'whisper-small'`).
616
1058
  - `contextSize` - Context window size (default: `2048`).
1059
+ - `options` - Model options for quantization and NPU acceleration:
1060
+ - `quantization` - Quantization type: `'int4'` | `'int8'` (default: `'int4'`).
1061
+ - `pro` - Enable NPU-accelerated models (default: `false`).
617
1062
 
618
1063
  #### Methods
619
1064
 
@@ -630,10 +1075,10 @@ Initializes the model and prepares it for inference. Safe to call multiple times
630
1075
 
631
1076
  **`transcribe(params: CactusSTTTranscribeParams): Promise<CactusSTTTranscribeResult>`**
632
1077
 
633
- Transcribes audio to text with optional streaming support. Automatically calls `init()` if not already initialized. Throws an error if a generation is already in progress.
1078
+ Transcribes audio to text with optional streaming support. Accepts either a file path or raw PCM audio samples. Automatically calls `init()` if not already initialized. Throws an error if a generation is already in progress.
634
1079
 
635
1080
  **Parameters:**
636
- - `audioFilePath` - Path to the audio file.
1081
+ - `audio` - Path to the audio file or raw PCM samples.
637
1082
  - `prompt` - Optional prompt to guide transcription (default: `'<|startoftranscript|><|en|><|transcribe|><|notimestamps|>'`).
638
1083
  - `options` - Transcription options:
639
1084
  - `temperature` - Sampling temperature (default: model-optimized).
@@ -650,6 +1095,33 @@ Generates embeddings for the given audio file. Automatically calls `init()` if n
650
1095
  **Parameters:**
651
1096
  - `audioPath` - Path to the audio file.
652
1097
 
1098
+ **`streamTranscribeInit(): Promise<void>`**
1099
+
1100
+ Initializes a streaming transcription session. Automatically calls `init()` if not already initialized.
1101
+
1102
+ **`streamTranscribeInsert(params: CactusSTTStreamTranscribeInsertParams): Promise<void>`**
1103
+
1104
+ Inserts PCM audio samples into the streaming buffer.
1105
+
1106
+ **Parameters:**
1107
+ - `audio` - Array of PCM audio samples.
1108
+
1109
+ **`streamTranscribeProcess(params?: CactusSTTStreamTranscribeProcessParams): Promise<CactusSTTStreamTranscribeProcessResult>`**
1110
+
1111
+ Processes accumulated audio and returns incremental transcription results.
1112
+
1113
+ **Parameters:**
1114
+ - `options` - Processing options:
1115
+ - `confirmationThreshold` - Confidence threshold for confirming text.
1116
+
1117
+ **`streamTranscribeFinalize(): Promise<CactusSTTStreamTranscribeFinalizeResult>`**
1118
+
1119
+ Finalizes the streaming session and returns remaining transcription text.
1120
+
1121
+ **`streamTranscribeDestroy(): Promise<void>`**
1122
+
1123
+ Destroys the streaming session and releases resources.
1124
+
653
1125
  **`stop(): Promise<void>`**
654
1126
 
655
1127
  Stops ongoing transcription or embedding generation.
@@ -662,18 +1134,21 @@ Resets the model's internal state. Automatically calls `stop()` first.
662
1134
 
663
1135
  Releases all resources associated with the model. Automatically calls `stop()` first. Safe to call even if the model is not initialized.
664
1136
 
665
- **`getModels(): Promise<CactusSTTModel[]>`**
1137
+ **`getModels(): CactusModel[]`**
666
1138
 
667
- Fetches available STT models from the database and checks their download status.
1139
+ Returns available speech-to-text models.
668
1140
 
669
1141
  ### useCactusSTT Hook
670
1142
 
671
- The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When model parameters (`model`, `contextSize`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1143
+ The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When model parameters (`model`, `contextSize`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
672
1144
 
673
1145
  #### State
674
1146
 
675
1147
  - `transcription: string` - Current transcription text. Automatically accumulated during streaming. Cleared before each new transcription and when calling `reset()` or `destroy()`.
1148
+ - `streamTranscribeConfirmed: string` - Accumulated confirmed text from streaming transcription.
1149
+ - `streamTranscribePending: string` - Current pending text from streaming transcription.
676
1150
  - `isGenerating: boolean` - Whether the model is currently generating (transcription or embedding). Both operations share this flag.
1151
+ - `isStreamTranscribing: boolean` - Whether a streaming transcription session is active.
677
1152
  - `isInitializing: boolean` - Whether the model is initializing.
678
1153
  - `isDownloaded: boolean` - Whether the model is downloaded locally. Automatically checked when the hook mounts or model changes.
679
1154
  - `isDownloading: boolean` - Whether the model is being downloaded.
@@ -686,10 +1161,93 @@ The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When
686
1161
  - `init(): Promise<void>` - Initializes the model for inference. Sets `isInitializing` to `true` during initialization.
687
1162
  - `transcribe(params: CactusSTTTranscribeParams): Promise<CactusSTTTranscribeResult>` - Transcribes audio to text. Automatically accumulates tokens in the `transcription` state during streaming. Sets `isGenerating` to `true` while generating. Clears `transcription` before starting.
688
1163
  - `audioEmbed(params: CactusSTTAudioEmbedParams): Promise<CactusSTTAudioEmbedResult>` - Generates embeddings for the given audio. Sets `isGenerating` to `true` during operation.
1164
+ - `streamTranscribeInit(): Promise<void>` - Initializes a streaming transcription session. Sets `isStreamTranscribing` to `true`.
1165
+ - `streamTranscribeInsert(params: CactusSTTStreamTranscribeInsertParams): Promise<void>` - Inserts audio chunks into the streaming buffer.
1166
+ - `streamTranscribeProcess(params?: CactusSTTStreamTranscribeProcessParams): Promise<CactusSTTStreamTranscribeProcessResult>` - Processes audio and returns results. Automatically accumulates confirmed text in `streamTranscribeConfirmed` and updates `streamTranscribePending`.
1167
+ - `streamTranscribeFinalize(): Promise<CactusSTTStreamTranscribeFinalizeResult>` - Finalizes streaming and returns remaining text.
1168
+ - `streamTranscribeDestroy(): Promise<void>` - Destroys the streaming session. Sets `isStreamTranscribing` to `false`.
689
1169
  - `stop(): Promise<void>` - Stops ongoing generation. Clears any errors.
690
1170
  - `reset(): Promise<void>` - Resets the model's internal state. Also clears the `transcription` state.
691
1171
  - `destroy(): Promise<void>` - Releases all resources associated with the model. Clears the `transcription` state. Automatically called when the component unmounts.
692
- - `getModels(): Promise<CactusSTTModel[]>` - Fetches available STT models from the database and checks their download status.
1172
+ - `getModels(): CactusModel[]` - Returns available speech-to-text models.
1173
+
1174
+ ### CactusIndex Class
1175
+
1176
+ #### Constructor
1177
+
1178
+ **`new CactusIndex(name: string, embeddingDim: number)`**
1179
+
1180
+ **Parameters:**
1181
+ - `name` - Name of the index.
1182
+ - `embeddingDim` - Dimension of the embedding vectors.
1183
+
1184
+ #### Methods
1185
+
1186
+ **`init(): Promise<void>`**
1187
+
1188
+ Initializes the index and prepares it for operations. Must be called before using any other methods.
1189
+
1190
+ **`add(params: CactusIndexAddParams): Promise<void>`**
1191
+
1192
+ Adds documents with their embeddings and metadata to the index.
1193
+
1194
+ **Parameters:**
1195
+ - `ids` - Array of document IDs.
1196
+ - `documents` - Array of document texts.
1197
+ - `embeddings` - Array of embedding vectors (each vector must match `embeddingDim`).
1198
+ - `metadatas` - Optional array of metadata strings.
1199
+
1200
+ **`query(params: CactusIndexQueryParams): Promise<CactusIndexQueryResult>`**
1201
+
1202
+ Searches for similar documents using embedding vectors.
1203
+
1204
+ **Parameters:**
1205
+ - `embeddings` - Array of query embedding vectors.
1206
+ - `options` - Query options:
1207
+ - `topK` - Number of top results to return (default: 10).
1208
+ - `scoreThreshold` - Minimum similarity score threshold (default: -1.0).
1209
+
1210
+ **`get(params: CactusIndexGetParams): Promise<CactusIndexGetResult>`**
1211
+
1212
+ Retrieves documents by their IDs.
1213
+
1214
+ **Parameters:**
1215
+ - `ids` - Array of document IDs to retrieve.
1216
+
1217
+ **`delete(params: CactusIndexDeleteParams): Promise<void>`**
1218
+
1219
+ Deletes documents from the index by their IDs.
1220
+
1221
+ **Parameters:**
1222
+ - `ids` - Array of document IDs to delete.
1223
+
1224
+ **`compact(): Promise<void>`**
1225
+
1226
+ Optimizes the index by removing deleted documents and reorganizing data for better performance. Call after a series of deletions.
1227
+
1228
+ **`destroy(): Promise<void>`**
1229
+
1230
+ Releases all resources associated with the index from memory.
1231
+
1232
+ ### useCactusIndex Hook
1233
+
1234
+ The `useCactusIndex` hook manages a `CactusIndex` instance with reactive state. When index parameters (`name` or `embeddingDim`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1235
+
1236
+ #### State
1237
+
1238
+ - `isInitializing: boolean` - Whether the index is initializing.
1239
+ - `isProcessing: boolean` - Whether the index is processing an operation (add, query, get, delete, or compact).
1240
+ - `error: string | null` - Last error message from any operation, or `null` if there is no error. Cleared before starting new operations.
1241
+
1242
+ #### Methods
1243
+
1244
+ - `init(): Promise<void>` - Initializes the index. Sets `isInitializing` to `true` during initialization.
1245
+ - `add(params: CactusIndexAddParams): Promise<void>` - Adds documents to the index. Sets `isProcessing` to `true` during operation.
1246
+ - `query(params: CactusIndexQueryParams): Promise<CactusIndexQueryResult>` - Searches for similar documents. Sets `isProcessing` to `true` during operation.
1247
+ - `get(params: CactusIndexGetParams): Promise<CactusIndexGetResult>` - Retrieves documents by IDs. Sets `isProcessing` to `true` during operation.
1248
+ - `delete(params: CactusIndexDeleteParams): Promise<void>` - Deletes documents. Sets `isProcessing` to `true` during operation.
1249
+ - `compact(): Promise<void>` - Optimizes the index. Sets `isProcessing` to `true` during operation.
1250
+ - `destroy(): Promise<void>` - Releases all resources. Automatically called when the component unmounts.
693
1251
 
694
1252
  ## Type Definitions
695
1253
 
@@ -700,6 +1258,7 @@ interface CactusLMParams {
700
1258
  model?: string;
701
1259
  contextSize?: number;
702
1260
  corpusDir?: string;
1261
+ options?: ModelOptions;
703
1262
  }
704
1263
  ```
705
1264
 
@@ -730,6 +1289,7 @@ interface CompleteOptions {
730
1289
  topK?: number;
731
1290
  maxTokens?: number;
732
1291
  stopSequences?: string[];
1292
+ forceTools?: boolean;
733
1293
  }
734
1294
  ```
735
1295
 
@@ -783,11 +1343,47 @@ interface CactusLMCompleteResult {
783
1343
  }
784
1344
  ```
785
1345
 
1346
+ ### CactusLMTokenizeParams
1347
+
1348
+ ```typescript
1349
+ interface CactusLMTokenizeParams {
1350
+ text: string;
1351
+ }
1352
+ ```
1353
+
1354
+ ### CactusLMTokenizeResult
1355
+
1356
+ ```typescript
1357
+ interface CactusLMTokenizeResult {
1358
+ tokens: number[];
1359
+ }
1360
+ ```
1361
+
1362
+ ### CactusLMScoreWindowParams
1363
+
1364
+ ```typescript
1365
+ interface CactusLMScoreWindowParams {
1366
+ tokens: number[];
1367
+ start: number;
1368
+ end: number;
1369
+ context: number;
1370
+ }
1371
+ ```
1372
+
1373
+ ### CactusLMScoreWindowResult
1374
+
1375
+ ```typescript
1376
+ interface CactusLMScoreWindowResult {
1377
+ score: number;
1378
+ }
1379
+ ```
1380
+
786
1381
  ### CactusLMEmbedParams
787
1382
 
788
1383
  ```typescript
789
1384
  interface CactusLMEmbedParams {
790
1385
  text: string;
1386
+ normalize?: boolean;
791
1387
  }
792
1388
  ```
793
1389
 
@@ -819,28 +1415,36 @@ interface CactusLMImageEmbedResult {
819
1415
 
820
1416
  ```typescript
821
1417
  interface CactusModel {
822
- name: string;
823
- slug: string;
824
- quantization: number;
825
- sizeMb: number;
826
- downloadUrl: string;
827
- supportsToolCalling: boolean;
828
- supportsVision: boolean;
829
- supportsCompletion: boolean;
830
- createdAt: Date;
831
- isDownloaded: boolean;
1418
+ completion: boolean;
1419
+ tools: boolean;
1420
+ vision: boolean;
1421
+ embed: boolean;
1422
+ speech: boolean;
1423
+ quantization: {
1424
+ int4: {
1425
+ sizeMb: number;
1426
+ url: string;
1427
+ pro?: {
1428
+ apple: string;
1429
+ };
1430
+ };
1431
+ int8: {
1432
+ sizeMb: number;
1433
+ url: string;
1434
+ pro?: {
1435
+ apple: string;
1436
+ };
1437
+ };
1438
+ };
832
1439
  }
833
1440
  ```
834
1441
 
835
- ### CactusSTTModel
1442
+ ### ModelOptions
836
1443
 
837
1444
  ```typescript
838
- interface CactusSTTModel {
839
- slug: string;
840
- sizeMb: number;
841
- downloadUrl: string;
842
- createdAt: Date;
843
- isDownloaded: boolean;
1445
+ interface ModelOptions {
1446
+ quantization: 'int4' | 'int8';
1447
+ pro: boolean;
844
1448
  }
845
1449
  ```
846
1450
 
@@ -850,6 +1454,7 @@ interface CactusSTTModel {
850
1454
  interface CactusSTTParams {
851
1455
  model?: string;
852
1456
  contextSize?: number;
1457
+ options?: ModelOptions;
853
1458
  }
854
1459
  ```
855
1460
 
@@ -878,7 +1483,7 @@ interface TranscribeOptions {
878
1483
 
879
1484
  ```typescript
880
1485
  interface CactusSTTTranscribeParams {
881
- audioFilePath: string;
1486
+ audio: string | number[];
882
1487
  prompt?: string;
883
1488
  options?: TranscribeOptions;
884
1489
  onToken?: (token: string) => void;
@@ -917,6 +1522,122 @@ interface CactusSTTAudioEmbedResult {
917
1522
  }
918
1523
  ```
919
1524
 
1525
+ ### CactusSTTStreamTranscribeInsertParams
1526
+
1527
+ ```typescript
1528
+ interface CactusSTTStreamTranscribeInsertParams {
1529
+ audio: number[];
1530
+ }
1531
+ ```
1532
+
1533
+ ### StreamTranscribeProcessOptions
1534
+
1535
+ ```typescript
1536
+ interface StreamTranscribeProcessOptions {
1537
+ confirmationThreshold?: number;
1538
+ }
1539
+ ```
1540
+
1541
+ ### CactusSTTStreamTranscribeProcessParams
1542
+
1543
+ ```typescript
1544
+ interface CactusSTTStreamTranscribeProcessParams {
1545
+ options?: StreamTranscribeProcessOptions;
1546
+ }
1547
+ ```
1548
+
1549
+ ### CactusSTTStreamTranscribeProcessResult
1550
+
1551
+ ```typescript
1552
+ interface CactusSTTStreamTranscribeProcessResult {
1553
+ success: boolean;
1554
+ confirmed: string;
1555
+ pending: string;
1556
+ }
1557
+ ```
1558
+
1559
+ ### CactusSTTStreamTranscribeFinalizeResult
1560
+
1561
+ ```typescript
1562
+ interface CactusSTTStreamTranscribeFinalizeResult {
1563
+ success: boolean;
1564
+ confirmed: string;
1565
+ }
1566
+ ```
1567
+
1568
+ ### CactusIndexParams
1569
+
1570
+ ```typescript
1571
+ interface CactusIndexParams {
1572
+ name: string;
1573
+ embeddingDim: number;
1574
+ }
1575
+ ```
1576
+
1577
+ ### CactusIndexAddParams
1578
+
1579
+ ```typescript
1580
+ interface CactusIndexAddParams {
1581
+ ids: number[];
1582
+ documents: string[];
1583
+ embeddings: number[][];
1584
+ metadatas?: string[];
1585
+ }
1586
+ ```
1587
+
1588
+ ### CactusIndexGetParams
1589
+
1590
+ ```typescript
1591
+ interface CactusIndexGetParams {
1592
+ ids: number[];
1593
+ }
1594
+ ```
1595
+
1596
+ ### CactusIndexGetResult
1597
+
1598
+ ```typescript
1599
+ interface CactusIndexGetResult {
1600
+ documents: string[];
1601
+ metadatas: string[];
1602
+ embeddings: number[][];
1603
+ }
1604
+ ```
1605
+
1606
+ ### IndexQueryOptions
1607
+
1608
+ ```typescript
1609
+ interface IndexQueryOptions {
1610
+ topK?: number;
1611
+ scoreThreshold?: number;
1612
+ }
1613
+ ```
1614
+
1615
+ ### CactusIndexQueryParams
1616
+
1617
+ ```typescript
1618
+ interface CactusIndexQueryParams {
1619
+ embeddings: number[][];
1620
+ options?: IndexQueryOptions;
1621
+ }
1622
+ ```
1623
+
1624
+ ### CactusIndexQueryResult
1625
+
1626
+ ```typescript
1627
+ interface CactusIndexQueryResult {
1628
+ ids: number[][];
1629
+ scores: number[][];
1630
+ }
1631
+ ```
1632
+
1633
+ ### CactusIndexDeleteParams
1634
+
1635
+ ```typescript
1636
+ interface CactusIndexDeleteParams {
1637
+ ids: number[];
1638
+ }
1639
+ ```
1640
+
920
1641
  ## Configuration
921
1642
 
922
1643
  ### Telemetry
@@ -944,6 +1665,17 @@ import { CactusConfig } from 'cactus-react-native';
944
1665
  CactusConfig.cactusToken = 'your-cactus-token-here';
945
1666
  ```
946
1667
 
1668
+ ### Cactus Pro
1669
+
1670
+ Enable NPU-accelerated models for enhanced performance.
1671
+
1672
+ ```typescript
1673
+ import { CactusConfig } from 'cactus-react-native';
1674
+
1675
+ // Set your Cactus Pro key
1676
+ CactusConfig.cactusProKey = 'your-cactus-pro-key-here';
1677
+ ```
1678
+
947
1679
  ## Performance Tips
948
1680
 
949
1681
  - **Model Selection** - Choose smaller models for faster inference on mobile devices.