@soulcraft/brainy 6.5.0 → 6.6.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.
@@ -1,60 +1,37 @@
1
1
  /**
2
- * Embedding functions for converting data to vectors using Transformers.js
3
- * Complete rewrite to eliminate TensorFlow.js and use ONNX-based models
2
+ * Embedding functions for converting data to vectors
3
+ *
4
+ * Uses direct ONNX WASM for universal compatibility.
5
+ * No transformers.js dependency - clean, production-grade implementation.
4
6
  */
5
7
  import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.js';
6
8
  /**
7
- * Detect the best available GPU device for the current environment
8
- */
9
- export declare function detectBestDevice(): Promise<'cpu' | 'webgpu' | 'cuda'>;
10
- /**
11
- * Resolve device string to actual device configuration
12
- */
13
- export declare function resolveDevice(device?: string): Promise<string>;
14
- /**
15
- * Transformers.js Sentence Encoder embedding model
16
- * Uses ONNX Runtime for fast, offline embeddings with smaller models
17
- * Default model: all-MiniLM-L6-v2 (384 dimensions, ~90MB)
9
+ * TransformerEmbedding options (kept for backward compatibility)
18
10
  */
19
11
  export interface TransformerEmbeddingOptions {
20
- /** Model name/path to use - defaults to all-MiniLM-L6-v2 */
12
+ /** Model name - only all-MiniLM-L6-v2 is supported */
21
13
  model?: string;
22
14
  /** Whether to enable verbose logging */
23
15
  verbose?: boolean;
24
- /** Custom cache directory for models */
16
+ /** Custom cache directory - ignored (model is bundled) */
25
17
  cacheDir?: string;
26
- /** Force local files only (no downloads) */
18
+ /** Force local files only - ignored (model is bundled) */
27
19
  localFilesOnly?: boolean;
28
- /** Model precision: 'q8' = 75% smaller quantized model, 'fp32' = full precision (default) */
20
+ /** Model precision - always q8 */
29
21
  precision?: 'fp32' | 'q8';
30
- /** Device to run inference on - 'auto' detects best available */
22
+ /** Device - always WASM */
31
23
  device?: 'auto' | 'cpu' | 'webgpu' | 'cuda' | 'gpu';
32
24
  }
25
+ /**
26
+ * TransformerEmbedding - Sentence embeddings using WASM ONNX
27
+ *
28
+ * This class delegates all work to EmbeddingManager which uses
29
+ * the direct ONNX WASM engine. Kept for backward compatibility.
30
+ */
33
31
  export declare class TransformerEmbedding implements EmbeddingModel {
34
- private extractor;
35
32
  private initialized;
36
33
  private verbose;
37
- private options;
38
- /**
39
- * Create a new TransformerEmbedding instance
40
- */
41
34
  constructor(options?: TransformerEmbeddingOptions);
42
- /**
43
- * Get the default cache directory for models
44
- */
45
- private getDefaultCacheDir;
46
- /**
47
- * Check if we're running in a test environment
48
- */
49
- private isTestEnvironment;
50
- /**
51
- * Log message only if verbose mode is enabled
52
- */
53
- private logger;
54
- /**
55
- * Generate mock embeddings for unit tests
56
- */
57
- private getMockEmbedding;
58
35
  /**
59
36
  * Initialize the embedding model
60
37
  */
@@ -64,45 +41,51 @@ export declare class TransformerEmbedding implements EmbeddingModel {
64
41
  */
65
42
  embed(data: string | string[]): Promise<Vector>;
66
43
  /**
67
- * Dispose of the model and free resources
44
+ * Get the embedding function
68
45
  */
69
- dispose(): Promise<void>;
46
+ getEmbeddingFunction(): EmbeddingFunction;
70
47
  /**
71
- * Get the dimension of embeddings produced by this model
48
+ * Check if initialized
72
49
  */
73
- getDimension(): number;
50
+ isInitialized(): boolean;
74
51
  /**
75
- * Check if the model is initialized
52
+ * Dispose resources (no-op for WASM engine)
76
53
  */
77
- isInitialized(): boolean;
54
+ dispose(): Promise<void>;
78
55
  }
79
- export declare const UniversalSentenceEncoder: typeof TransformerEmbedding;
80
56
  /**
81
- * Create a new embedding model instance
57
+ * Create a simple embedding function using the default TransformerEmbedding
58
+ * This is the recommended way to create an embedding function for Brainy
82
59
  */
83
- export declare function createEmbeddingModel(options?: TransformerEmbeddingOptions): EmbeddingModel;
60
+ export declare function createEmbeddingFunction(options?: TransformerEmbeddingOptions): EmbeddingFunction;
84
61
  /**
85
- * Default embedding function using the unified EmbeddingManager
86
- * Simple, clean, reliable - no more layers of indirection
62
+ * Create a TransformerEmbedding instance (backward compatibility)
63
+ */
64
+ export declare function createTransformerEmbedding(options?: TransformerEmbeddingOptions): TransformerEmbedding;
65
+ /**
66
+ * Convenience function to detect best device (always returns 'wasm')
67
+ */
68
+ export declare function detectBestDevice(): Promise<'cpu' | 'webgpu' | 'cuda' | 'wasm'>;
69
+ /**
70
+ * Resolve device string (always returns 'wasm')
71
+ */
72
+ export declare function resolveDevice(_device?: string): Promise<string>;
73
+ /**
74
+ * Default embedding function (backward compatibility)
87
75
  */
88
76
  export declare const defaultEmbeddingFunction: EmbeddingFunction;
89
77
  /**
90
- * Create an embedding function with custom options
91
- * NOTE: Options are validated but the singleton EmbeddingManager is always used
78
+ * UniversalSentenceEncoder alias (backward compatibility)
92
79
  */
93
- export declare function createEmbeddingFunction(options?: TransformerEmbeddingOptions): EmbeddingFunction;
80
+ export declare const UniversalSentenceEncoder: typeof TransformerEmbedding;
94
81
  /**
95
- * Batch embedding function for processing multiple texts efficiently
82
+ * Batch embed function (backward compatibility)
96
83
  */
97
- export declare function batchEmbed(texts: string[], options?: TransformerEmbeddingOptions): Promise<Vector[]>;
84
+ export declare function batchEmbed(texts: string[]): Promise<Vector[]>;
98
85
  /**
99
- * Embedding functions for specific model types
86
+ * Embedding functions registry (backward compatibility)
100
87
  */
101
88
  export declare const embeddingFunctions: {
102
- /** Default lightweight model (all-MiniLM-L6-v2, 384 dimensions) */
103
- default: EmbeddingFunction;
104
- /** Create custom embedding function */
105
- create: typeof createEmbeddingFunction;
106
- /** Batch processing */
107
- batch: typeof batchEmbed;
89
+ transformer: typeof createEmbeddingFunction;
90
+ default: typeof createEmbeddingFunction;
108
91
  };