cactus-react-native 1.2.0 → 1.4.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.
- package/README.md +573 -13
- package/android/CMakeLists.txt +4 -3
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +21 -4
- package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.a +0 -0
- package/cpp/HybridCactus.cpp +112 -19
- package/cpp/HybridCactus.hpp +12 -3
- package/cpp/HybridCactusIndex.cpp +325 -0
- package/cpp/HybridCactusIndex.hpp +43 -0
- package/cpp/HybridCactusUtil.cpp +3 -3
- package/cpp/HybridCactusUtil.hpp +2 -1
- package/cpp/cactus_ffi.h +83 -2
- package/cpp/cactus_util.h +1 -1
- package/ios/HybridCactusFileSystem.swift +23 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +2 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +83 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_telemetry.h +656 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +104 -17
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +117 -7
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +91 -5
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +15 -6
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +2 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +83 -2
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_telemetry.h +656 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +104 -17
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +117 -7
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +91 -5
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +15 -6
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus_util.xcframework/Info.plist +4 -4
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +1 -1
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/database.h +27 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/cactus_util +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/cactus_util.h +1 -1
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/database.h +27 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/_CodeSignature/CodeResources +3 -3
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +57 -3
- package/lib/module/api/Database.js.map +1 -1
- package/lib/module/classes/CactusIndex.js +45 -0
- package/lib/module/classes/CactusIndex.js.map +1 -0
- package/lib/module/classes/CactusLM.js +35 -10
- package/lib/module/classes/CactusLM.js.map +1 -1
- package/lib/module/classes/CactusSTT.js +20 -12
- package/lib/module/classes/CactusSTT.js.map +1 -1
- package/lib/module/config/CactusConfig.js +2 -0
- package/lib/module/config/CactusConfig.js.map +1 -1
- package/lib/module/constants/packageVersion.js +1 -1
- package/lib/module/hooks/useCactusIndex.js +175 -0
- package/lib/module/hooks/useCactusIndex.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +54 -2
- package/lib/module/hooks/useCactusLM.js.map +1 -1
- package/lib/module/hooks/useCactusSTT.js +2 -2
- package/lib/module/hooks/useCactusSTT.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/Cactus.js +21 -5
- package/lib/module/native/Cactus.js.map +1 -1
- package/lib/module/native/CactusFileSystem.js +3 -0
- package/lib/module/native/CactusFileSystem.js.map +1 -1
- package/lib/module/native/CactusIndex.js +32 -0
- package/lib/module/native/CactusIndex.js.map +1 -0
- package/lib/module/native/CactusUtil.js +16 -3
- package/lib/module/native/CactusUtil.js.map +1 -1
- package/lib/module/native/index.js +1 -0
- package/lib/module/native/index.js.map +1 -1
- package/lib/module/specs/CactusIndex.nitro.js +4 -0
- package/lib/module/specs/CactusIndex.nitro.js.map +1 -0
- package/lib/module/telemetry/Telemetry.js +3 -1
- package/lib/module/telemetry/Telemetry.js.map +1 -1
- package/lib/module/types/CactusIndex.js +2 -0
- package/lib/module/types/CactusIndex.js.map +1 -0
- package/lib/module/types/CactusSTTModel.js +2 -0
- package/lib/module/types/CactusSTTModel.js.map +1 -0
- package/lib/typescript/src/api/Database.d.ts +7 -1
- package/lib/typescript/src/api/Database.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusIndex.d.ts +15 -0
- package/lib/typescript/src/classes/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/classes/CactusLM.d.ts +5 -3
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +4 -4
- package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/config/CactusConfig.d.ts +1 -0
- package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -1
- package/lib/typescript/src/constants/packageVersion.d.ts +1 -1
- package/lib/typescript/src/hooks/useCactusIndex.d.ts +14 -0
- package/lib/typescript/src/hooks/useCactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +4 -2
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts +3 -3
- package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/native/Cactus.d.ts +4 -2
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusFileSystem.d.ts +1 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusIndex.d.ts +12 -0
- package/lib/typescript/src/native/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusUtil.d.ts.map +1 -1
- package/lib/typescript/src/native/index.d.ts +1 -0
- package/lib/typescript/src/native/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +4 -2
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts +1 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/CactusIndex.nitro.d.ts +24 -0
- package/lib/typescript/src/specs/CactusIndex.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusIndex.d.ts +34 -0
- package/lib/typescript/src/types/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusLM.d.ts +17 -0
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusModel.d.ts +1 -0
- package/lib/typescript/src/types/CactusModel.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTTModel.d.ts +8 -0
- package/lib/typescript/src/types/CactusSTTModel.d.ts.map +1 -0
- package/nitro.json +3 -0
- package/nitrogen/generated/android/c++/JDeviceInfo.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.cpp +17 -1
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.hpp +2 -1
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.hpp +1 -1
- package/nitrogen/generated/android/cactus+autolinking.cmake +2 -1
- package/nitrogen/generated/android/cactus+autolinking.gradle +1 -1
- package/nitrogen/generated/android/cactusOnLoad.cpp +11 -1
- package/nitrogen/generated/android/cactusOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/Func_void_double.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusFileSystemSpec.kt +5 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusImageSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/cactusOnLoad.kt +1 -1
- package/nitrogen/generated/ios/Cactus+autolinking.rb +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/CactusAutolinking.mm +11 -1
- package/nitrogen/generated/ios/CactusAutolinking.swift +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.hpp +9 -1
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec_cxx.swift +20 -1
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec_cxx.swift +1 -1
- package/nitrogen/generated/shared/c++/CactusIndexGetResult.hpp +84 -0
- package/nitrogen/generated/shared/c++/CactusIndexQueryResult.hpp +79 -0
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.hpp +2 -1
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +3 -1
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +6 -3
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +2 -2
- package/package.json +2 -2
- package/src/api/Database.ts +80 -2
- package/src/classes/CactusIndex.ts +58 -0
- package/src/classes/CactusLM.ts +41 -11
- package/src/classes/CactusSTT.ts +24 -16
- package/src/config/CactusConfig.ts +3 -0
- package/src/constants/packageVersion.ts +1 -1
- package/src/hooks/useCactusIndex.ts +195 -0
- package/src/hooks/useCactusLM.ts +63 -3
- package/src/hooks/useCactusSTT.ts +4 -4
- package/src/index.tsx +17 -0
- package/src/native/Cactus.ts +39 -4
- package/src/native/CactusFileSystem.ts +4 -0
- package/src/native/CactusIndex.ts +54 -0
- package/src/native/CactusUtil.ts +19 -3
- package/src/native/index.ts +1 -0
- package/src/specs/Cactus.nitro.ts +13 -2
- package/src/specs/CactusFileSystem.nitro.ts +2 -0
- package/src/specs/CactusIndex.nitro.ts +31 -0
- package/src/specs/CactusUtil.nitro.ts +1 -1
- package/src/telemetry/Telemetry.ts +1 -1
- package/src/types/CactusIndex.ts +40 -0
- package/src/types/CactusLM.ts +21 -0
- package/src/types/CactusModel.ts +1 -0
- package/src/types/CactusSTT.ts +1 -1
- package/src/types/CactusSTTModel.ts +10 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
package/README.md
CHANGED
|
@@ -298,6 +298,82 @@ const App = () => {
|
|
|
298
298
|
};
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
+
### Tokenization
|
|
302
|
+
|
|
303
|
+
Convert text into tokens using the model's tokenizer.
|
|
304
|
+
|
|
305
|
+
#### Class
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { CactusLM } from 'cactus-react-native';
|
|
309
|
+
|
|
310
|
+
const cactusLM = new CactusLM();
|
|
311
|
+
|
|
312
|
+
const result = await cactusLM.tokenize({ text: 'Hello, World!' });
|
|
313
|
+
console.log('Token IDs:', result.tokens);
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
#### Hook
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
import { useCactusLM } from 'cactus-react-native';
|
|
320
|
+
|
|
321
|
+
const App = () => {
|
|
322
|
+
const cactusLM = useCactusLM();
|
|
323
|
+
|
|
324
|
+
const handleTokenize = async () => {
|
|
325
|
+
const result = await cactusLM.tokenize({ text: 'Hello, World!' });
|
|
326
|
+
console.log('Token IDs:', result.tokens);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
return <Button title="Tokenize" onPress={handleTokenize} />;
|
|
330
|
+
};
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Score Window
|
|
334
|
+
|
|
335
|
+
Calculate perplexity scores for a window of tokens within a sequence.
|
|
336
|
+
|
|
337
|
+
#### Class
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
import { CactusLM } from 'cactus-react-native';
|
|
341
|
+
|
|
342
|
+
const cactusLM = new CactusLM();
|
|
343
|
+
|
|
344
|
+
const tokens = [123, 456, 789, 101, 112];
|
|
345
|
+
const result = await cactusLM.scoreWindow({
|
|
346
|
+
tokens,
|
|
347
|
+
start: 1,
|
|
348
|
+
end: 3,
|
|
349
|
+
context: 2
|
|
350
|
+
});
|
|
351
|
+
console.log('Score:', result.score);
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
#### Hook
|
|
355
|
+
|
|
356
|
+
```tsx
|
|
357
|
+
import { useCactusLM } from 'cactus-react-native';
|
|
358
|
+
|
|
359
|
+
const App = () => {
|
|
360
|
+
const cactusLM = useCactusLM();
|
|
361
|
+
|
|
362
|
+
const handleScoreWindow = async () => {
|
|
363
|
+
const tokens = [123, 456, 789, 101, 112];
|
|
364
|
+
const result = await cactusLM.scoreWindow({
|
|
365
|
+
tokens,
|
|
366
|
+
start: 1,
|
|
367
|
+
end: 3,
|
|
368
|
+
context: 2
|
|
369
|
+
});
|
|
370
|
+
console.log('Score:', result.score);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
return <Button title="Score Window" onPress={handleScoreWindow} />;
|
|
374
|
+
};
|
|
375
|
+
```
|
|
376
|
+
|
|
301
377
|
### Embedding
|
|
302
378
|
|
|
303
379
|
Convert text and images into numerical vector representations that capture semantic meaning, useful for similarity search and semantic understanding.
|
|
@@ -423,7 +499,7 @@ The `CactusSTT` class provides audio transcription and audio embedding capabilit
|
|
|
423
499
|
|
|
424
500
|
### Transcription
|
|
425
501
|
|
|
426
|
-
Transcribe audio
|
|
502
|
+
Transcribe audio to text with streaming support. Accepts either a file path or raw PCM audio samples.
|
|
427
503
|
|
|
428
504
|
#### Class
|
|
429
505
|
|
|
@@ -434,12 +510,22 @@ const cactusSTT = new CactusSTT({ model: 'whisper-small' });
|
|
|
434
510
|
|
|
435
511
|
await cactusSTT.init();
|
|
436
512
|
|
|
513
|
+
// Transcribe from file path
|
|
437
514
|
const result = await cactusSTT.transcribe({
|
|
438
|
-
|
|
515
|
+
audio: 'path/to/audio.wav',
|
|
439
516
|
onToken: (token) => console.log('Token:', token)
|
|
440
517
|
});
|
|
441
518
|
|
|
442
519
|
console.log('Transcription:', result.response);
|
|
520
|
+
|
|
521
|
+
// Or transcribe from raw PCM samples
|
|
522
|
+
const pcmSamples: number[] = [/* ... */];
|
|
523
|
+
const result2 = await cactusSTT.transcribe({
|
|
524
|
+
audio: pcmSamples,
|
|
525
|
+
onToken: (token) => console.log('Token:', token)
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
console.log('Transcription:', result2.response);
|
|
443
529
|
```
|
|
444
530
|
|
|
445
531
|
#### Hook
|
|
@@ -451,10 +537,17 @@ const App = () => {
|
|
|
451
537
|
const cactusSTT = useCactusSTT({ model: 'whisper-small' });
|
|
452
538
|
|
|
453
539
|
const handleTranscribe = async () => {
|
|
540
|
+
// Transcribe from file path
|
|
454
541
|
const result = await cactusSTT.transcribe({
|
|
455
|
-
|
|
542
|
+
audio: 'path/to/audio.wav',
|
|
456
543
|
});
|
|
457
544
|
console.log('Transcription:', result.response);
|
|
545
|
+
|
|
546
|
+
const pcmSamples: number[] = [/* ... */];
|
|
547
|
+
const result2 = await cactusSTT.transcribe({
|
|
548
|
+
audio: pcmSamples,
|
|
549
|
+
});
|
|
550
|
+
console.log('Transcription:', result2.response);
|
|
458
551
|
};
|
|
459
552
|
|
|
460
553
|
return (
|
|
@@ -507,6 +600,251 @@ const App = () => {
|
|
|
507
600
|
};
|
|
508
601
|
```
|
|
509
602
|
|
|
603
|
+
## Vector Index
|
|
604
|
+
|
|
605
|
+
The `CactusIndex` class provides a vector database for storing and querying embeddings with metadata. Enabling similarity search and retrieval.
|
|
606
|
+
|
|
607
|
+
### Creating and Initializing an Index
|
|
608
|
+
|
|
609
|
+
#### Class
|
|
610
|
+
|
|
611
|
+
```typescript
|
|
612
|
+
import { CactusIndex } from 'cactus-react-native';
|
|
613
|
+
|
|
614
|
+
const cactusIndex = new CactusIndex('my-index', 1024);
|
|
615
|
+
await cactusIndex.init();
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
#### Hook
|
|
619
|
+
|
|
620
|
+
```tsx
|
|
621
|
+
import { useCactusIndex } from 'cactus-react-native';
|
|
622
|
+
|
|
623
|
+
const App = () => {
|
|
624
|
+
const cactusIndex = useCactusIndex({
|
|
625
|
+
name: 'my-index',
|
|
626
|
+
embeddingDim: 1024
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
const handleInit = async () => {
|
|
630
|
+
await cactusIndex.init();
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
return <Button title="Initialize Index" onPress={handleInit} />
|
|
634
|
+
};
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
### Adding Documents
|
|
638
|
+
|
|
639
|
+
Add documents with their embeddings and metadata to the index.
|
|
640
|
+
|
|
641
|
+
#### Class
|
|
642
|
+
|
|
643
|
+
```typescript
|
|
644
|
+
import { CactusIndex } from 'cactus-react-native';
|
|
645
|
+
|
|
646
|
+
const cactusIndex = new CactusIndex('my-index', 1024);
|
|
647
|
+
await cactusIndex.init();
|
|
648
|
+
|
|
649
|
+
await cactusIndex.add({
|
|
650
|
+
ids: [1, 2, 3],
|
|
651
|
+
documents: ['First document', 'Second document', 'Third document'],
|
|
652
|
+
embeddings: [
|
|
653
|
+
[0.1, 0.2, ...],
|
|
654
|
+
[0.3, 0.4, ...],
|
|
655
|
+
[0.5, 0.6, ...]
|
|
656
|
+
],
|
|
657
|
+
metadatas: ['metadata1', 'metadata2', 'metadata3']
|
|
658
|
+
});
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
#### Hook
|
|
662
|
+
|
|
663
|
+
```tsx
|
|
664
|
+
import { useCactusIndex } from 'cactus-react-native';
|
|
665
|
+
|
|
666
|
+
const App = () => {
|
|
667
|
+
const cactusIndex = useCactusIndex({
|
|
668
|
+
name: 'my-index',
|
|
669
|
+
embeddingDim: 1024
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
const handleAdd = async () => {
|
|
673
|
+
await cactusIndex.add({
|
|
674
|
+
ids: [1, 2, 3],
|
|
675
|
+
documents: ['First document', 'Second document', 'Third document'],
|
|
676
|
+
embeddings: [
|
|
677
|
+
[0.1, 0.2, ...],
|
|
678
|
+
[0.3, 0.4, ...],
|
|
679
|
+
[0.5, 0.6, ...]
|
|
680
|
+
],
|
|
681
|
+
metadatas: ['metadata1', 'metadata2', 'metadata3']
|
|
682
|
+
});
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
return <Button title="Add Documents" onPress={handleAdd} />;
|
|
686
|
+
};
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
### Querying the Index
|
|
690
|
+
|
|
691
|
+
Search for similar documents using embedding vectors.
|
|
692
|
+
|
|
693
|
+
#### Class
|
|
694
|
+
|
|
695
|
+
```typescript
|
|
696
|
+
import { CactusIndex } from 'cactus-react-native';
|
|
697
|
+
|
|
698
|
+
const cactusIndex = new CactusIndex('my-index', 1024);
|
|
699
|
+
await cactusIndex.init();
|
|
700
|
+
|
|
701
|
+
const result = await cactusIndex.query({
|
|
702
|
+
embeddings: [[0.1, 0.2, ...]],
|
|
703
|
+
options: {
|
|
704
|
+
topK: 5,
|
|
705
|
+
scoreThreshold: 0.7
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
console.log('IDs:', result.ids);
|
|
710
|
+
console.log('Scores:', result.scores);
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
#### Hook
|
|
714
|
+
|
|
715
|
+
```tsx
|
|
716
|
+
import { useCactusIndex } from 'cactus-react-native';
|
|
717
|
+
|
|
718
|
+
const App = () => {
|
|
719
|
+
const cactusIndex = useCactusIndex({
|
|
720
|
+
name: 'my-index',
|
|
721
|
+
embeddingDim: 1024
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
const handleQuery = async () => {
|
|
725
|
+
const result = await cactusIndex.query({
|
|
726
|
+
embeddings: [[0.1, 0.2, ...]],
|
|
727
|
+
options: {
|
|
728
|
+
topK: 5,
|
|
729
|
+
scoreThreshold: 0.7
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
console.log('IDs:', result.ids);
|
|
733
|
+
console.log('Scores:', result.scores);
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
return <Button title="Query Index" onPress={handleQuery} />;
|
|
737
|
+
};
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
### Retrieving Documents
|
|
741
|
+
|
|
742
|
+
Get documents by their IDs.
|
|
743
|
+
|
|
744
|
+
#### Class
|
|
745
|
+
|
|
746
|
+
```typescript
|
|
747
|
+
import { CactusIndex } from 'cactus-react-native';
|
|
748
|
+
|
|
749
|
+
const cactusIndex = new CactusIndex('my-index', 1024);
|
|
750
|
+
await cactusIndex.init();
|
|
751
|
+
|
|
752
|
+
const result = await cactusIndex.get({ ids: [1, 2, 3] });
|
|
753
|
+
console.log('Documents:', result.documents);
|
|
754
|
+
console.log('Metadatas:', result.metadatas);
|
|
755
|
+
console.log('Embeddings:', result.embeddings);
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
#### Hook
|
|
759
|
+
|
|
760
|
+
```tsx
|
|
761
|
+
import { useCactusIndex } from 'cactus-react-native';
|
|
762
|
+
|
|
763
|
+
const App = () => {
|
|
764
|
+
const cactusIndex = useCactusIndex({
|
|
765
|
+
name: 'my-index',
|
|
766
|
+
embeddingDim: 1024
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
const handleGet = async () => {
|
|
770
|
+
const result = await cactusIndex.get({ ids: [1, 2, 3] });
|
|
771
|
+
console.log('Documents:', result.documents);
|
|
772
|
+
console.log('Metadatas:', result.metadatas);
|
|
773
|
+
console.log('Embeddings:', result.embeddings);
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
return <Button title="Get Documents" onPress={handleGet} />;
|
|
777
|
+
};
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
### Deleting Documents
|
|
781
|
+
|
|
782
|
+
Mark documents as deleted by their IDs.
|
|
783
|
+
|
|
784
|
+
#### Class
|
|
785
|
+
|
|
786
|
+
```typescript
|
|
787
|
+
import { CactusIndex } from 'cactus-react-native';
|
|
788
|
+
|
|
789
|
+
const cactusIndex = new CactusIndex('my-index', 1024);
|
|
790
|
+
await cactusIndex.init();
|
|
791
|
+
|
|
792
|
+
await cactusIndex.delete({ ids: [1, 2, 3] });
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
#### Hook
|
|
796
|
+
|
|
797
|
+
```tsx
|
|
798
|
+
import { useCactusIndex } from 'cactus-react-native';
|
|
799
|
+
|
|
800
|
+
const App = () => {
|
|
801
|
+
const cactusIndex = useCactusIndex({
|
|
802
|
+
name: 'my-index',
|
|
803
|
+
embeddingDim: 1024
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
const handleDelete = async () => {
|
|
807
|
+
await cactusIndex.delete({ ids: [1, 2, 3] });
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
return <Button title="Delete Documents" onPress={handleDelete} />;
|
|
811
|
+
};
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
### Compacting the Index
|
|
815
|
+
|
|
816
|
+
Optimize the index by removing deleted documents and reorganizing data.
|
|
817
|
+
|
|
818
|
+
#### Class
|
|
819
|
+
|
|
820
|
+
```typescript
|
|
821
|
+
import { CactusIndex } from 'cactus-react-native';
|
|
822
|
+
|
|
823
|
+
const cactusIndex = new CactusIndex('my-index', 1024);
|
|
824
|
+
await cactusIndex.init();
|
|
825
|
+
|
|
826
|
+
await cactusIndex.compact();
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
#### Hook
|
|
830
|
+
|
|
831
|
+
```tsx
|
|
832
|
+
import { useCactusIndex } from 'cactus-react-native';
|
|
833
|
+
|
|
834
|
+
const App = () => {
|
|
835
|
+
const cactusIndex = useCactusIndex({
|
|
836
|
+
name: 'my-index',
|
|
837
|
+
embeddingDim: 1024
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
const handleCompact = async () => {
|
|
841
|
+
await cactusIndex.compact();
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
return <Button title="Compact Index" onPress={handleCompact} />;
|
|
845
|
+
};
|
|
846
|
+
```
|
|
847
|
+
|
|
510
848
|
## API Reference
|
|
511
849
|
|
|
512
850
|
### CactusLM Class
|
|
@@ -516,7 +854,7 @@ const App = () => {
|
|
|
516
854
|
**`new CactusLM(params?: CactusLMParams)`**
|
|
517
855
|
|
|
518
856
|
**Parameters:**
|
|
519
|
-
- `model` - Model slug (default: `'qwen3-0.6'`).
|
|
857
|
+
- `model` - Model slug or absolute path to Cactus model (default: `'qwen3-0.6'`).
|
|
520
858
|
- `contextSize` - Context window size (default: `2048`).
|
|
521
859
|
- `corpusDir` - Directory containing text files for RAG (default: `undefined`).
|
|
522
860
|
|
|
@@ -545,16 +883,35 @@ Performs text completion with optional streaming and tool support. Automatically
|
|
|
545
883
|
- `topK` - Top-K sampling limit (default: model-optimized).
|
|
546
884
|
- `maxTokens` - Maximum number of tokens to generate (default: `512`).
|
|
547
885
|
- `stopSequences` - Array of strings to stop generation (default: `undefined`).
|
|
886
|
+
- `forceTools` - Force the model to call one of the provided tools (default: `false`).
|
|
548
887
|
- `tools` - Array of `Tool` objects for function calling (default: `undefined`).
|
|
549
888
|
- `onToken` - Callback for streaming tokens.
|
|
550
889
|
- `mode` - Completion mode: `'local'` | `'hybrid'` (default: `'local'`)
|
|
551
890
|
|
|
891
|
+
**`tokenize(params: CactusLMTokenizeParams): Promise<CactusLMTokenizeResult>`**
|
|
892
|
+
|
|
893
|
+
Converts text into tokens using the model's tokenizer.
|
|
894
|
+
|
|
895
|
+
**Parameters:**
|
|
896
|
+
- `text` - Text to tokenize.
|
|
897
|
+
|
|
898
|
+
**`scoreWindow(params: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult>`**
|
|
899
|
+
|
|
900
|
+
Calculates perplexity scores for a window of tokens within a sequence.
|
|
901
|
+
|
|
902
|
+
**Parameters:**
|
|
903
|
+
- `tokens` - Array of token IDs.
|
|
904
|
+
- `start` - Start index of the window.
|
|
905
|
+
- `end` - End index of the window.
|
|
906
|
+
- `context` - Number of context tokens before the window.
|
|
907
|
+
|
|
552
908
|
**`embed(params: CactusLMEmbedParams): Promise<CactusLMEmbedResult>`**
|
|
553
909
|
|
|
554
910
|
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
911
|
|
|
556
912
|
**Parameters:**
|
|
557
913
|
- `text` - Text to embed.
|
|
914
|
+
- `normalize` - Whether to normalize the embedding vector (default: `false`).
|
|
558
915
|
|
|
559
916
|
**`imageEmbed(params: CactusLMImageEmbedParams): Promise<CactusLMImageEmbedResult>`**
|
|
560
917
|
|
|
@@ -577,7 +934,7 @@ Releases all resources associated with the model. Automatically calls `stop()` f
|
|
|
577
934
|
|
|
578
935
|
**`getModels(): Promise<CactusModel[]>`**
|
|
579
936
|
|
|
580
|
-
Fetches available models from the database and checks their download status.
|
|
937
|
+
Fetches available models from the database and checks their download status.
|
|
581
938
|
|
|
582
939
|
### useCactusLM Hook
|
|
583
940
|
|
|
@@ -598,12 +955,14 @@ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When m
|
|
|
598
955
|
- `download(params?: CactusLMDownloadParams): Promise<void>` - Downloads the model. Updates `isDownloading` and `downloadProgress` state during download. Sets `isDownloaded` to `true` on success.
|
|
599
956
|
- `init(): Promise<void>` - Initializes the model for inference. Sets `isInitializing` to `true` during initialization.
|
|
600
957
|
- `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.
|
|
958
|
+
- `tokenize(params: CactusLMTokenizeParams): Promise<CactusLMTokenizeResult>` - Converts text into tokens. Sets `isGenerating` to `true` during operation.
|
|
959
|
+
- `scoreWindow(params: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult>` - Calculates perplexity scores for a window of tokens. Sets `isGenerating` to `true` during operation.
|
|
601
960
|
- `embed(params: CactusLMEmbedParams): Promise<CactusLMEmbedResult>` - Generates embeddings for the given text. Sets `isGenerating` to `true` during operation.
|
|
602
961
|
- `imageEmbed(params: CactusLMImageEmbedParams): Promise<CactusLMImageEmbedResult>` - Generates embeddings for the given image. Sets `isGenerating` to `true` while generating.
|
|
603
962
|
- `stop(): Promise<void>` - Stops ongoing generation. Clears any errors.
|
|
604
963
|
- `reset(): Promise<void>` - Resets the model's internal state, clearing cached context. Also clears the `completion` state.
|
|
605
964
|
- `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.
|
|
965
|
+
- `getModels(): Promise<CactusModel[]>` - Fetches available models from the database and checks their download status.
|
|
607
966
|
|
|
608
967
|
### CactusSTT Class
|
|
609
968
|
|
|
@@ -612,7 +971,7 @@ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When m
|
|
|
612
971
|
**`new CactusSTT(params?: CactusSTTParams)`**
|
|
613
972
|
|
|
614
973
|
**Parameters:**
|
|
615
|
-
- `model` - Model slug (default: `'
|
|
974
|
+
- `model` - Model slug or absolute path to Cactus model (default: `'qwen3-0.6'`).
|
|
616
975
|
- `contextSize` - Context window size (default: `2048`).
|
|
617
976
|
|
|
618
977
|
#### Methods
|
|
@@ -630,10 +989,10 @@ Initializes the model and prepares it for inference. Safe to call multiple times
|
|
|
630
989
|
|
|
631
990
|
**`transcribe(params: CactusSTTTranscribeParams): Promise<CactusSTTTranscribeResult>`**
|
|
632
991
|
|
|
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.
|
|
992
|
+
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
993
|
|
|
635
994
|
**Parameters:**
|
|
636
|
-
- `
|
|
995
|
+
- `audio` - Path to the audio file or raw PCM samples.
|
|
637
996
|
- `prompt` - Optional prompt to guide transcription (default: `'<|startoftranscript|><|en|><|transcribe|><|notimestamps|>'`).
|
|
638
997
|
- `options` - Transcription options:
|
|
639
998
|
- `temperature` - Sampling temperature (default: model-optimized).
|
|
@@ -662,9 +1021,9 @@ Resets the model's internal state. Automatically calls `stop()` first.
|
|
|
662
1021
|
|
|
663
1022
|
Releases all resources associated with the model. Automatically calls `stop()` first. Safe to call even if the model is not initialized.
|
|
664
1023
|
|
|
665
|
-
**`getModels(): Promise<
|
|
1024
|
+
**`getModels(): Promise<CactusSTTModel[]>`**
|
|
666
1025
|
|
|
667
|
-
Fetches available models from the database and checks their download status.
|
|
1026
|
+
Fetches available STT models from the database and checks their download status.
|
|
668
1027
|
|
|
669
1028
|
### useCactusSTT Hook
|
|
670
1029
|
|
|
@@ -689,7 +1048,85 @@ The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When
|
|
|
689
1048
|
- `stop(): Promise<void>` - Stops ongoing generation. Clears any errors.
|
|
690
1049
|
- `reset(): Promise<void>` - Resets the model's internal state. Also clears the `transcription` state.
|
|
691
1050
|
- `destroy(): Promise<void>` - Releases all resources associated with the model. Clears the `transcription` state. Automatically called when the component unmounts.
|
|
692
|
-
- `getModels(): Promise<
|
|
1051
|
+
- `getModels(): Promise<CactusSTTModel[]>` - Fetches available STT models from the database and checks their download status.
|
|
1052
|
+
|
|
1053
|
+
### CactusIndex Class
|
|
1054
|
+
|
|
1055
|
+
#### Constructor
|
|
1056
|
+
|
|
1057
|
+
**`new CactusIndex(name: string, embeddingDim: number)`**
|
|
1058
|
+
|
|
1059
|
+
**Parameters:**
|
|
1060
|
+
- `name` - Name of the index.
|
|
1061
|
+
- `embeddingDim` - Dimension of the embedding vectors.
|
|
1062
|
+
|
|
1063
|
+
#### Methods
|
|
1064
|
+
|
|
1065
|
+
**`init(): Promise<void>`**
|
|
1066
|
+
|
|
1067
|
+
Initializes the index and prepares it for operations. Must be called before using any other methods.
|
|
1068
|
+
|
|
1069
|
+
**`add(params: CactusIndexAddParams): Promise<void>`**
|
|
1070
|
+
|
|
1071
|
+
Adds documents with their embeddings and metadata to the index.
|
|
1072
|
+
|
|
1073
|
+
**Parameters:**
|
|
1074
|
+
- `ids` - Array of document IDs.
|
|
1075
|
+
- `documents` - Array of document texts.
|
|
1076
|
+
- `embeddings` - Array of embedding vectors (each vector must match `embeddingDim`).
|
|
1077
|
+
- `metadatas` - Optional array of metadata strings.
|
|
1078
|
+
|
|
1079
|
+
**`query(params: CactusIndexQueryParams): Promise<CactusIndexQueryResult>`**
|
|
1080
|
+
|
|
1081
|
+
Searches for similar documents using embedding vectors.
|
|
1082
|
+
|
|
1083
|
+
**Parameters:**
|
|
1084
|
+
- `embeddings` - Array of query embedding vectors.
|
|
1085
|
+
- `options` - Query options:
|
|
1086
|
+
- `topK` - Number of top results to return (default: 10).
|
|
1087
|
+
- `scoreThreshold` - Minimum similarity score threshold (default: -1.0).
|
|
1088
|
+
|
|
1089
|
+
**`get(params: CactusIndexGetParams): Promise<CactusIndexGetResult>`**
|
|
1090
|
+
|
|
1091
|
+
Retrieves documents by their IDs.
|
|
1092
|
+
|
|
1093
|
+
**Parameters:**
|
|
1094
|
+
- `ids` - Array of document IDs to retrieve.
|
|
1095
|
+
|
|
1096
|
+
**`delete(params: CactusIndexDeleteParams): Promise<void>`**
|
|
1097
|
+
|
|
1098
|
+
Deletes documents from the index by their IDs.
|
|
1099
|
+
|
|
1100
|
+
**Parameters:**
|
|
1101
|
+
- `ids` - Array of document IDs to delete.
|
|
1102
|
+
|
|
1103
|
+
**`compact(): Promise<void>`**
|
|
1104
|
+
|
|
1105
|
+
Optimizes the index by removing deleted documents and reorganizing data for better performance. Call after a series of deletions.
|
|
1106
|
+
|
|
1107
|
+
**`destroy(): Promise<void>`**
|
|
1108
|
+
|
|
1109
|
+
Releases all resources associated with the index from memory.
|
|
1110
|
+
|
|
1111
|
+
### useCactusIndex Hook
|
|
1112
|
+
|
|
1113
|
+
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.
|
|
1114
|
+
|
|
1115
|
+
#### State
|
|
1116
|
+
|
|
1117
|
+
- `isInitializing: boolean` - Whether the index is initializing.
|
|
1118
|
+
- `isProcessing: boolean` - Whether the index is processing an operation (add, query, get, delete, or compact).
|
|
1119
|
+
- `error: string | null` - Last error message from any operation, or `null` if there is no error. Cleared before starting new operations.
|
|
1120
|
+
|
|
1121
|
+
#### Methods
|
|
1122
|
+
|
|
1123
|
+
- `init(): Promise<void>` - Initializes the index. Sets `isInitializing` to `true` during initialization.
|
|
1124
|
+
- `add(params: CactusIndexAddParams): Promise<void>` - Adds documents to the index. Sets `isProcessing` to `true` during operation.
|
|
1125
|
+
- `query(params: CactusIndexQueryParams): Promise<CactusIndexQueryResult>` - Searches for similar documents. Sets `isProcessing` to `true` during operation.
|
|
1126
|
+
- `get(params: CactusIndexGetParams): Promise<CactusIndexGetResult>` - Retrieves documents by IDs. Sets `isProcessing` to `true` during operation.
|
|
1127
|
+
- `delete(params: CactusIndexDeleteParams): Promise<void>` - Deletes documents. Sets `isProcessing` to `true` during operation.
|
|
1128
|
+
- `compact(): Promise<void>` - Optimizes the index. Sets `isProcessing` to `true` during operation.
|
|
1129
|
+
- `destroy(): Promise<void>` - Releases all resources. Automatically called when the component unmounts.
|
|
693
1130
|
|
|
694
1131
|
## Type Definitions
|
|
695
1132
|
|
|
@@ -730,6 +1167,7 @@ interface CompleteOptions {
|
|
|
730
1167
|
topK?: number;
|
|
731
1168
|
maxTokens?: number;
|
|
732
1169
|
stopSequences?: string[];
|
|
1170
|
+
forceTools?: boolean;
|
|
733
1171
|
}
|
|
734
1172
|
```
|
|
735
1173
|
|
|
@@ -783,11 +1221,47 @@ interface CactusLMCompleteResult {
|
|
|
783
1221
|
}
|
|
784
1222
|
```
|
|
785
1223
|
|
|
1224
|
+
### CactusLMTokenizeParams
|
|
1225
|
+
|
|
1226
|
+
```typescript
|
|
1227
|
+
interface CactusLMTokenizeParams {
|
|
1228
|
+
text: string;
|
|
1229
|
+
}
|
|
1230
|
+
```
|
|
1231
|
+
|
|
1232
|
+
### CactusLMTokenizeResult
|
|
1233
|
+
|
|
1234
|
+
```typescript
|
|
1235
|
+
interface CactusLMTokenizeResult {
|
|
1236
|
+
tokens: number[];
|
|
1237
|
+
}
|
|
1238
|
+
```
|
|
1239
|
+
|
|
1240
|
+
### CactusLMScoreWindowParams
|
|
1241
|
+
|
|
1242
|
+
```typescript
|
|
1243
|
+
interface CactusLMScoreWindowParams {
|
|
1244
|
+
tokens: number[];
|
|
1245
|
+
start: number;
|
|
1246
|
+
end: number;
|
|
1247
|
+
context: number;
|
|
1248
|
+
}
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
### CactusLMScoreWindowResult
|
|
1252
|
+
|
|
1253
|
+
```typescript
|
|
1254
|
+
interface CactusLMScoreWindowResult {
|
|
1255
|
+
score: number;
|
|
1256
|
+
}
|
|
1257
|
+
```
|
|
1258
|
+
|
|
786
1259
|
### CactusLMEmbedParams
|
|
787
1260
|
|
|
788
1261
|
```typescript
|
|
789
1262
|
interface CactusLMEmbedParams {
|
|
790
1263
|
text: string;
|
|
1264
|
+
normalize?: boolean;
|
|
791
1265
|
}
|
|
792
1266
|
```
|
|
793
1267
|
|
|
@@ -826,6 +1300,19 @@ interface CactusModel {
|
|
|
826
1300
|
downloadUrl: string;
|
|
827
1301
|
supportsToolCalling: boolean;
|
|
828
1302
|
supportsVision: boolean;
|
|
1303
|
+
supportsCompletion: boolean;
|
|
1304
|
+
createdAt: Date;
|
|
1305
|
+
isDownloaded: boolean;
|
|
1306
|
+
}
|
|
1307
|
+
```
|
|
1308
|
+
|
|
1309
|
+
### CactusSTTModel
|
|
1310
|
+
|
|
1311
|
+
```typescript
|
|
1312
|
+
interface CactusSTTModel {
|
|
1313
|
+
slug: string;
|
|
1314
|
+
sizeMb: number;
|
|
1315
|
+
downloadUrl: string;
|
|
829
1316
|
createdAt: Date;
|
|
830
1317
|
isDownloaded: boolean;
|
|
831
1318
|
}
|
|
@@ -865,7 +1352,7 @@ interface TranscribeOptions {
|
|
|
865
1352
|
|
|
866
1353
|
```typescript
|
|
867
1354
|
interface CactusSTTTranscribeParams {
|
|
868
|
-
|
|
1355
|
+
audio: string | number[];
|
|
869
1356
|
prompt?: string;
|
|
870
1357
|
options?: TranscribeOptions;
|
|
871
1358
|
onToken?: (token: string) => void;
|
|
@@ -904,6 +1391,79 @@ interface CactusSTTAudioEmbedResult {
|
|
|
904
1391
|
}
|
|
905
1392
|
```
|
|
906
1393
|
|
|
1394
|
+
### CactusIndexParams
|
|
1395
|
+
|
|
1396
|
+
```typescript
|
|
1397
|
+
interface CactusIndexParams {
|
|
1398
|
+
name: string;
|
|
1399
|
+
embeddingDim: number;
|
|
1400
|
+
}
|
|
1401
|
+
```
|
|
1402
|
+
|
|
1403
|
+
### CactusIndexAddParams
|
|
1404
|
+
|
|
1405
|
+
```typescript
|
|
1406
|
+
interface CactusIndexAddParams {
|
|
1407
|
+
ids: number[];
|
|
1408
|
+
documents: string[];
|
|
1409
|
+
embeddings: number[][];
|
|
1410
|
+
metadatas?: string[];
|
|
1411
|
+
}
|
|
1412
|
+
```
|
|
1413
|
+
|
|
1414
|
+
### CactusIndexGetParams
|
|
1415
|
+
|
|
1416
|
+
```typescript
|
|
1417
|
+
interface CactusIndexGetParams {
|
|
1418
|
+
ids: number[];
|
|
1419
|
+
}
|
|
1420
|
+
```
|
|
1421
|
+
|
|
1422
|
+
### CactusIndexGetResult
|
|
1423
|
+
|
|
1424
|
+
```typescript
|
|
1425
|
+
interface CactusIndexGetResult {
|
|
1426
|
+
documents: string[];
|
|
1427
|
+
metadatas: string[];
|
|
1428
|
+
embeddings: number[][];
|
|
1429
|
+
}
|
|
1430
|
+
```
|
|
1431
|
+
|
|
1432
|
+
### IndexQueryOptions
|
|
1433
|
+
|
|
1434
|
+
```typescript
|
|
1435
|
+
interface IndexQueryOptions {
|
|
1436
|
+
topK?: number;
|
|
1437
|
+
scoreThreshold?: number;
|
|
1438
|
+
}
|
|
1439
|
+
```
|
|
1440
|
+
|
|
1441
|
+
### CactusIndexQueryParams
|
|
1442
|
+
|
|
1443
|
+
```typescript
|
|
1444
|
+
interface CactusIndexQueryParams {
|
|
1445
|
+
embeddings: number[][];
|
|
1446
|
+
options?: IndexQueryOptions;
|
|
1447
|
+
}
|
|
1448
|
+
```
|
|
1449
|
+
|
|
1450
|
+
### CactusIndexQueryResult
|
|
1451
|
+
|
|
1452
|
+
```typescript
|
|
1453
|
+
interface CactusIndexQueryResult {
|
|
1454
|
+
ids: number[][];
|
|
1455
|
+
scores: number[][];
|
|
1456
|
+
}
|
|
1457
|
+
```
|
|
1458
|
+
|
|
1459
|
+
### CactusIndexDeleteParams
|
|
1460
|
+
|
|
1461
|
+
```typescript
|
|
1462
|
+
interface CactusIndexDeleteParams {
|
|
1463
|
+
ids: number[];
|
|
1464
|
+
}
|
|
1465
|
+
```
|
|
1466
|
+
|
|
907
1467
|
## Configuration
|
|
908
1468
|
|
|
909
1469
|
### Telemetry
|