@soulcraft/brainy 0.9.10 → 0.9.12
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 +50 -22
- package/dist/brainy.js +36414 -66507
- package/dist/brainy.min.js +1112 -4724
- package/dist/brainyData.d.ts +2 -0
- package/dist/hnsw/hnswIndex.d.ts +2 -0
- package/dist/unified.js +36414 -66507
- package/dist/unified.min.js +1112 -4724
- package/dist/utils/distance.d.ts +12 -1
- package/dist/utils/embedding.d.ts +19 -14
- package/dist/utils/environment.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/version.d.ts +1 -1
- package/dist/utils/workerUtils.d.ts +7 -17
- package/package.json +7 -2
package/dist/utils/distance.d.ts
CHANGED
|
@@ -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
|
|
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
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/version.d.ts
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Utility functions for
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.9.12",
|
|
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",
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"version:patch": "npm version patch",
|
|
39
39
|
"version:minor": "npm version minor",
|
|
40
40
|
"version:major": "npm version major",
|
|
41
|
+
"lint": "eslint --ext .ts,.js src/",
|
|
42
|
+
"lint:fix": "eslint --ext .ts,.js src/ --fix",
|
|
43
|
+
"format": "prettier --write \"src/**/*.{ts,js}\"",
|
|
44
|
+
"check-format": "prettier --check \"src/**/*.{ts,js}\"",
|
|
45
|
+
"check-style": "node scripts/check-code-style.js",
|
|
41
46
|
"deploy": "npm run build && npm publish",
|
|
42
47
|
"deploy:cloud:aws": "cd cloud-wrapper && npm run build && npm run deploy:aws",
|
|
43
48
|
"deploy:cloud:gcp": "cd cloud-wrapper && npm run build && npm run deploy:gcp",
|
|
@@ -102,9 +107,9 @@
|
|
|
102
107
|
"@tensorflow-models/universal-sentence-encoder": "^1.3.3",
|
|
103
108
|
"@tensorflow/tfjs": "^4.22.0",
|
|
104
109
|
"@tensorflow/tfjs-backend-cpu": "^4.22.0",
|
|
110
|
+
"@tensorflow/tfjs-backend-webgl": "^4.22.0",
|
|
105
111
|
"@tensorflow/tfjs-converter": "^4.22.0",
|
|
106
112
|
"@tensorflow/tfjs-core": "^4.22.0",
|
|
107
|
-
"@tensorflow/tfjs-layers": "^4.22.0",
|
|
108
113
|
"buffer": "^6.0.3",
|
|
109
114
|
"commander": "^14.0.0",
|
|
110
115
|
"omelette": "^0.4.17",
|