@soulcraft/brainy 0.9.10 → 0.9.11

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,8 +1,9 @@
1
1
  /**
2
2
  * Distance functions for vector similarity calculations
3
3
  * Optimized for Node.js 23.11+ using enhanced array methods
4
+ * GPU-accelerated versions available for high-performance computing
4
5
  */
5
- import { DistanceFunction } from '../coreTypes.js';
6
+ import { DistanceFunction, Vector } from '../coreTypes.js';
6
7
  /**
7
8
  * Calculates the Euclidean distance between two vectors
8
9
  * Lower values indicate higher similarity
@@ -29,4 +30,14 @@ export declare const manhattanDistance: DistanceFunction;
29
30
  * Optimized using array methods for Node.js 23.11+
30
31
  */
31
32
  export declare const dotProductDistance: DistanceFunction;
33
+ /**
34
+ * Batch distance calculation
35
+ * Uses TensorFlow.js with CPU backend for optimized performance
36
+ *
37
+ * @param queryVector The query vector to compare against all vectors
38
+ * @param vectors Array of vectors to compare against
39
+ * @param distanceFunction The distance function to use
40
+ * @returns Promise resolving to array of distances
41
+ */
42
+ export declare function calculateDistancesBatch(queryVector: Vector, vectors: Vector[], distanceFunction?: DistanceFunction): Promise<number[]>;
32
43
  //# sourceMappingURL=distance.d.ts.map
@@ -6,12 +6,16 @@ import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.js';
6
6
  * TensorFlow Universal Sentence Encoder embedding model
7
7
  * This model provides high-quality text embeddings using TensorFlow.js
8
8
  * The required TensorFlow.js dependencies are automatically installed with this package
9
+ *
10
+ * This implementation attempts to use GPU processing when available for better performance,
11
+ * falling back to CPU processing for compatibility across all environments.
9
12
  */
10
13
  export declare class UniversalSentenceEncoder implements EmbeddingModel {
11
14
  private model;
12
15
  private initialized;
13
16
  private tf;
14
17
  private use;
18
+ private backend;
15
19
  /**
16
20
  * Initialize the embedding model
17
21
  */
@@ -21,6 +25,13 @@ export declare class UniversalSentenceEncoder implements EmbeddingModel {
21
25
  * @param data Text to embed
22
26
  */
23
27
  embed(data: string | string[]): Promise<Vector>;
28
+ /**
29
+ * Embed multiple texts into vectors using Universal Sentence Encoder
30
+ * This is more efficient than calling embed() multiple times
31
+ * @param dataArray Array of texts to embed
32
+ * @returns Array of embedding vectors
33
+ */
34
+ embedBatch(dataArray: string[]): Promise<Vector[]>;
24
35
  /**
25
36
  * Dispose of the model resources
26
37
  */
@@ -31,25 +42,19 @@ export declare class UniversalSentenceEncoder implements EmbeddingModel {
31
42
  * @param model Embedding model to use
32
43
  */
33
44
  export declare function createEmbeddingFunction(model: EmbeddingModel): EmbeddingFunction;
34
- /**
35
- * Creates a TensorFlow-based Universal Sentence Encoder embedding function
36
- * This is the required embedding function for all text embeddings
37
- */
38
45
  export declare function createTensorFlowEmbeddingFunction(): EmbeddingFunction;
39
- /**
40
- * Creates a TensorFlow-based Universal Sentence Encoder embedding function that runs in a separate thread
41
- * This provides better performance for CPU-intensive embedding operations
42
- * @param options Configuration options
43
- * @returns An embedding function that runs in a separate thread
44
- */
45
- export declare function createThreadedEmbeddingFunction(options?: {
46
- fallbackToMain?: boolean;
47
- }): EmbeddingFunction;
48
46
  /**
49
47
  * Default embedding function
50
48
  * Uses UniversalSentenceEncoder for all text embeddings
51
49
  * TensorFlow.js is required for this to work
52
- * Uses threading when available for better performance
50
+ * Uses CPU for compatibility
53
51
  */
54
52
  export declare const defaultEmbeddingFunction: EmbeddingFunction;
53
+ export declare const defaultBatchEmbeddingFunction: (dataArray: string[]) => Promise<Vector[]>;
54
+ /**
55
+ * Creates an embedding function that runs in a separate thread
56
+ * This is a wrapper around createEmbeddingFunction that uses executeInThread
57
+ * @param model Embedding model to use
58
+ */
59
+ export declare function createThreadedEmbeddingFunction(model: EmbeddingModel): EmbeddingFunction;
55
60
  //# sourceMappingURL=embedding.d.ts.map
@@ -23,6 +23,7 @@ export declare function areWebWorkersAvailable(): boolean;
23
23
  export declare function areWorkerThreadsAvailable(): boolean;
24
24
  /**
25
25
  * Determine if threading is available in the current environment
26
+ * Always returns false since multithreading has been removed
26
27
  */
27
28
  export declare function isThreadingAvailable(): boolean;
28
29
  //# sourceMappingURL=environment.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export * from './distance.js';
2
2
  export * from './embedding.js';
3
+ export * from './workerUtils.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -2,5 +2,5 @@
2
2
  * This file is auto-generated during the build process.
3
3
  * Do not modify this file directly.
4
4
  */
5
- export declare const VERSION = "0.9.10";
5
+ export declare const VERSION = "0.9.11";
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,28 +1,18 @@
1
1
  /**
2
- * Utility functions for working with Web Workers and Worker Threads
2
+ * Utility functions for executing functions (without Web Workers or Worker Threads)
3
+ * This is a replacement for the original multithreaded implementation
3
4
  */
4
5
  /**
5
- * Execute a function in a Web Worker (browser environment)
6
+ * Execute a function directly in the main thread
6
7
  *
7
8
  * @param fnString The function to execute as a string
8
9
  * @param args The arguments to pass to the function
9
10
  * @returns A promise that resolves with the result of the function
10
11
  */
11
- export declare function executeInWebWorker<T>(fnString: string, args: any): Promise<T>;
12
- /**
13
- * Execute a function in a Worker Thread (Node.js environment)
14
- *
15
- * @param fnString The function to execute as a string
16
- * @param args The arguments to pass to the function
17
- * @returns A promise that resolves with the result of the function
18
- */
19
- export declare function executeInWorkerThread<T>(fnString: string, args: any): Promise<T>;
12
+ export declare function executeInThread<T>(fnString: string, args: any): Promise<T>;
20
13
  /**
21
- * Execute a function in a separate thread based on the environment
22
- *
23
- * @param fnString The function to execute as a string
24
- * @param args The arguments to pass to the function
25
- * @returns A promise that resolves with the result of the function
14
+ * No-op function for backward compatibility
15
+ * This function does nothing since there are no worker pools to clean up
26
16
  */
27
- export declare function executeInThread<T>(fnString: string, args: any): Promise<T>;
17
+ export declare function cleanupWorkerPools(): void;
28
18
  //# sourceMappingURL=workerUtils.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "A vector graph database using HNSW indexing with Origin Private File System storage",
5
5
  "main": "dist/unified.js",
6
6
  "module": "dist/unified.js",
@@ -102,9 +102,9 @@
102
102
  "@tensorflow-models/universal-sentence-encoder": "^1.3.3",
103
103
  "@tensorflow/tfjs": "^4.22.0",
104
104
  "@tensorflow/tfjs-backend-cpu": "^4.22.0",
105
+ "@tensorflow/tfjs-backend-webgl": "^4.22.0",
105
106
  "@tensorflow/tfjs-converter": "^4.22.0",
106
107
  "@tensorflow/tfjs-core": "^4.22.0",
107
- "@tensorflow/tfjs-layers": "^4.22.0",
108
108
  "buffer": "^6.0.3",
109
109
  "commander": "^14.0.0",
110
110
  "omelette": "^0.4.17",