@soulcraft/brainy 0.9.5
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/LICENSE +21 -0
- package/README.demo.md +59 -0
- package/README.md +1257 -0
- package/brainy.png +0 -0
- package/cli-wrapper.js +56 -0
- package/dist/augmentationFactory.d.ts +87 -0
- package/dist/augmentationPipeline.d.ts +205 -0
- package/dist/augmentationRegistry.d.ts +48 -0
- package/dist/augmentationRegistryLoader.d.ts +147 -0
- package/dist/augmentations/conduitAugmentations.d.ts +173 -0
- package/dist/augmentations/memoryAugmentations.d.ts +71 -0
- package/dist/augmentations/serverSearchAugmentations.d.ts +168 -0
- package/dist/brainy.js +116929 -0
- package/dist/brainy.min.js +16107 -0
- package/dist/brainyData.d.ts +507 -0
- package/dist/cli.d.ts +7 -0
- package/dist/coreTypes.d.ts +131 -0
- package/dist/examples/basicUsage.d.ts +5 -0
- package/dist/hnsw/hnswIndex.d.ts +96 -0
- package/dist/hnsw/hnswIndexOptimized.d.ts +167 -0
- package/dist/index.d.ts +49 -0
- package/dist/mcp/brainyMCPAdapter.d.ts +69 -0
- package/dist/mcp/brainyMCPService.d.ts +99 -0
- package/dist/mcp/index.d.ts +14 -0
- package/dist/mcp/mcpAugmentationToolset.d.ts +68 -0
- package/dist/pipeline.d.ts +281 -0
- package/dist/sequentialPipeline.d.ts +114 -0
- package/dist/storage/fileSystemStorage.d.ts +123 -0
- package/dist/storage/opfsStorage.d.ts +244 -0
- package/dist/storage/s3CompatibleStorage.d.ts +158 -0
- package/dist/types/augmentations.d.ts +324 -0
- package/dist/types/augmentations.d.ts.map +1 -0
- package/dist/types/brainyDataInterface.d.ts +51 -0
- package/dist/types/brainyDataInterface.d.ts.map +1 -0
- package/dist/types/fileSystemTypes.d.ts +6 -0
- package/dist/types/fileSystemTypes.d.ts.map +1 -0
- package/dist/types/graphTypes.d.ts +134 -0
- package/dist/types/graphTypes.d.ts.map +1 -0
- package/dist/types/mcpTypes.d.ts +140 -0
- package/dist/types/mcpTypes.d.ts.map +1 -0
- package/dist/types/pipelineTypes.d.ts +27 -0
- package/dist/types/pipelineTypes.d.ts.map +1 -0
- package/dist/types/tensorflowTypes.d.ts +7 -0
- package/dist/types/tensorflowTypes.d.ts.map +1 -0
- package/dist/unified.d.ts +12 -0
- package/dist/unified.js +117122 -0
- package/dist/unified.min.js +16107 -0
- package/dist/utils/distance.d.ts +32 -0
- package/dist/utils/embedding.d.ts +55 -0
- package/dist/utils/environment.d.ts +28 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/version.d.ts +6 -0
- package/dist/utils/workerUtils.d.ts +28 -0
- package/package.json +156 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Distance functions for vector similarity calculations
|
|
3
|
+
* Optimized for Node.js 23.11+ using enhanced array methods
|
|
4
|
+
*/
|
|
5
|
+
import { DistanceFunction } from '../coreTypes.js';
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the Euclidean distance between two vectors
|
|
8
|
+
* Lower values indicate higher similarity
|
|
9
|
+
* Optimized using array methods for Node.js 23.11+
|
|
10
|
+
*/
|
|
11
|
+
export declare const euclideanDistance: DistanceFunction;
|
|
12
|
+
/**
|
|
13
|
+
* Calculates the cosine distance between two vectors
|
|
14
|
+
* Lower values indicate higher similarity
|
|
15
|
+
* Range: 0 (identical) to 2 (opposite)
|
|
16
|
+
* Optimized using array methods for Node.js 23.11+
|
|
17
|
+
*/
|
|
18
|
+
export declare const cosineDistance: DistanceFunction;
|
|
19
|
+
/**
|
|
20
|
+
* Calculates the Manhattan (L1) distance between two vectors
|
|
21
|
+
* Lower values indicate higher similarity
|
|
22
|
+
* Optimized using array methods for Node.js 23.11+
|
|
23
|
+
*/
|
|
24
|
+
export declare const manhattanDistance: DistanceFunction;
|
|
25
|
+
/**
|
|
26
|
+
* Calculates the dot product similarity between two vectors
|
|
27
|
+
* Higher values indicate higher similarity
|
|
28
|
+
* Converted to a distance metric (lower is better)
|
|
29
|
+
* Optimized using array methods for Node.js 23.11+
|
|
30
|
+
*/
|
|
31
|
+
export declare const dotProductDistance: DistanceFunction;
|
|
32
|
+
//# sourceMappingURL=distance.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding functions for converting data to vectors
|
|
3
|
+
*/
|
|
4
|
+
import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.js';
|
|
5
|
+
/**
|
|
6
|
+
* TensorFlow Universal Sentence Encoder embedding model
|
|
7
|
+
* This model provides high-quality text embeddings using TensorFlow.js
|
|
8
|
+
* The required TensorFlow.js dependencies are automatically installed with this package
|
|
9
|
+
*/
|
|
10
|
+
export declare class UniversalSentenceEncoder implements EmbeddingModel {
|
|
11
|
+
private model;
|
|
12
|
+
private initialized;
|
|
13
|
+
private tf;
|
|
14
|
+
private use;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the embedding model
|
|
17
|
+
*/
|
|
18
|
+
init(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Embed text into a vector using Universal Sentence Encoder
|
|
21
|
+
* @param data Text to embed
|
|
22
|
+
*/
|
|
23
|
+
embed(data: string | string[]): Promise<Vector>;
|
|
24
|
+
/**
|
|
25
|
+
* Dispose of the model resources
|
|
26
|
+
*/
|
|
27
|
+
dispose(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create an embedding function from an embedding model
|
|
31
|
+
* @param model Embedding model to use
|
|
32
|
+
*/
|
|
33
|
+
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
|
+
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
|
+
/**
|
|
49
|
+
* Default embedding function
|
|
50
|
+
* Uses UniversalSentenceEncoder for all text embeddings
|
|
51
|
+
* TensorFlow.js is required for this to work
|
|
52
|
+
* Uses threading when available for better performance
|
|
53
|
+
*/
|
|
54
|
+
export declare const defaultEmbeddingFunction: EmbeddingFunction;
|
|
55
|
+
//# sourceMappingURL=embedding.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for environment detection
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Check if code is running in a browser environment
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBrowser(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Check if code is running in a Node.js environment
|
|
10
|
+
*/
|
|
11
|
+
export declare function isNode(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Check if code is running in a Web Worker environment
|
|
14
|
+
*/
|
|
15
|
+
export declare function isWebWorker(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Check if Web Workers are available in the current environment
|
|
18
|
+
*/
|
|
19
|
+
export declare function areWebWorkersAvailable(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if Worker Threads are available in the current environment (Node.js)
|
|
22
|
+
*/
|
|
23
|
+
export declare function areWorkerThreadsAvailable(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Determine if threading is available in the current environment
|
|
26
|
+
*/
|
|
27
|
+
export declare function isThreadingAvailable(): boolean;
|
|
28
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with Web Workers and Worker Threads
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Execute a function in a Web Worker (browser environment)
|
|
6
|
+
*
|
|
7
|
+
* @param fn The function to execute
|
|
8
|
+
* @param args The arguments to pass to the function
|
|
9
|
+
* @returns A promise that resolves with the result of the function
|
|
10
|
+
*/
|
|
11
|
+
export declare function executeInWebWorker<T>(fn: Function, ...args: any[]): Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Execute a function in a Worker Thread (Node.js environment)
|
|
14
|
+
*
|
|
15
|
+
* @param fn The function to execute
|
|
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>(fn: Function, ...args: any[]): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Execute a function in a separate thread based on the environment
|
|
22
|
+
*
|
|
23
|
+
* @param fn The function to execute
|
|
24
|
+
* @param args The arguments to pass to the function
|
|
25
|
+
* @returns A promise that resolves with the result of the function
|
|
26
|
+
*/
|
|
27
|
+
export declare function executeInThread<T>(fn: Function, ...args: any[]): Promise<T>;
|
|
28
|
+
//# sourceMappingURL=workerUtils.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@soulcraft/brainy",
|
|
3
|
+
"version": "0.9.5",
|
|
4
|
+
"description": "A vector graph database using HNSW indexing with Origin Private File System storage",
|
|
5
|
+
"main": "dist/unified.js",
|
|
6
|
+
"module": "dist/unified.js",
|
|
7
|
+
"types": "dist/unified.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/unified.js",
|
|
13
|
+
"types": "./dist/unified.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./min": {
|
|
16
|
+
"import": "./dist/unified.min.js"
|
|
17
|
+
},
|
|
18
|
+
"./types/graphTypes": {
|
|
19
|
+
"import": "./dist/types/graphTypes.js",
|
|
20
|
+
"types": "./dist/types/graphTypes.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./types/augmentations": {
|
|
23
|
+
"import": "./dist/types/augmentations.js",
|
|
24
|
+
"types": "./dist/types/augmentations.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=23.11.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"prebuild": "node scripts/generate-version.js",
|
|
32
|
+
"build": "BUILD_TYPE=unified rollup -c rollup.config.js",
|
|
33
|
+
"build:browser": "BUILD_TYPE=browser rollup -c rollup.config.js",
|
|
34
|
+
"start": "node dist/unified.js",
|
|
35
|
+
"demo": "npm run build && npm run build:browser && npx http-server -o /index.html",
|
|
36
|
+
"cli": "node ./cli-wrapper.js",
|
|
37
|
+
"version:patch": "npm version patch",
|
|
38
|
+
"version:minor": "npm version minor",
|
|
39
|
+
"version:major": "npm version major",
|
|
40
|
+
"deploy": "npm run build && npm publish",
|
|
41
|
+
"deploy:cloud:aws": "cd cloud-wrapper && npm run build && npm run deploy:aws",
|
|
42
|
+
"deploy:cloud:gcp": "cd cloud-wrapper && npm run build && npm run deploy:gcp",
|
|
43
|
+
"deploy:cloud:cloudflare": "cd cloud-wrapper && npm run build && npm run deploy:cloudflare",
|
|
44
|
+
"deploy:cloud": "echo 'Please use one of the following commands to deploy to a specific cloud provider:' && echo ' npm run deploy:cloud:aws' && echo ' npm run deploy:cloud:gcp' && echo ' npm run deploy:cloud:cloudflare'",
|
|
45
|
+
"postinstall": "echo 'Note: If you encounter dependency conflicts with TensorFlow.js packages, please use: npm install --legacy-peer-deps'"
|
|
46
|
+
},
|
|
47
|
+
"bin": {
|
|
48
|
+
"brainy": "cli-wrapper.js"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"vector-database",
|
|
52
|
+
"hnsw",
|
|
53
|
+
"opfs",
|
|
54
|
+
"origin-private-file-system",
|
|
55
|
+
"embeddings",
|
|
56
|
+
"graph-database",
|
|
57
|
+
"streaming-data"
|
|
58
|
+
],
|
|
59
|
+
"author": "David Snelling (david@soulcraft.com)",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"private": false,
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://github.com/soulcraft-research/brainy",
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/soulcraft-research/brainy/issues"
|
|
68
|
+
},
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "https://github.com/soulcraft-research/brainy.git"
|
|
72
|
+
},
|
|
73
|
+
"files": [
|
|
74
|
+
"dist/**/*.js",
|
|
75
|
+
"dist/**/*.d.ts",
|
|
76
|
+
"dist/types/",
|
|
77
|
+
"LICENSE",
|
|
78
|
+
"README.md",
|
|
79
|
+
"cli-wrapper.js",
|
|
80
|
+
"brainy.png"
|
|
81
|
+
],
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
84
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
85
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
86
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
87
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
88
|
+
"@types/jest": "^29.5.3",
|
|
89
|
+
"@types/node": "^20.4.5",
|
|
90
|
+
"@types/omelette": "^0.4.5",
|
|
91
|
+
"@types/uuid": "^10.0.0",
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
93
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
94
|
+
"eslint": "^8.45.0",
|
|
95
|
+
"jest": "^29.6.2",
|
|
96
|
+
"rollup": "^4.12.0",
|
|
97
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
98
|
+
"ts-jest": "^29.1.1",
|
|
99
|
+
"tslib": "^2.8.1",
|
|
100
|
+
"typescript": "^5.1.6"
|
|
101
|
+
},
|
|
102
|
+
"dependencies": {
|
|
103
|
+
"@aws-sdk/client-s3": "^3.427.0",
|
|
104
|
+
"@tensorflow-models/universal-sentence-encoder": "^1.3.3",
|
|
105
|
+
"@tensorflow/tfjs": "^4.22.0",
|
|
106
|
+
"@tensorflow/tfjs-backend-cpu": "^4.22.0",
|
|
107
|
+
"@tensorflow/tfjs-converter": "^4.22.0",
|
|
108
|
+
"@tensorflow/tfjs-core": "^4.22.0",
|
|
109
|
+
"@tensorflow/tfjs-layers": "^4.22.0",
|
|
110
|
+
"buffer": "^6.0.3",
|
|
111
|
+
"commander": "^14.0.0",
|
|
112
|
+
"omelette": "^0.4.17",
|
|
113
|
+
"uuid": "^9.0.0"
|
|
114
|
+
},
|
|
115
|
+
"prettier": {
|
|
116
|
+
"arrowParens": "always",
|
|
117
|
+
"bracketSameLine": true,
|
|
118
|
+
"bracketSpacing": true,
|
|
119
|
+
"htmlWhitespaceSensitivity": "css",
|
|
120
|
+
"printWidth": 80,
|
|
121
|
+
"proseWrap": "preserve",
|
|
122
|
+
"semi": false,
|
|
123
|
+
"singleQuote": true,
|
|
124
|
+
"tabWidth": 2,
|
|
125
|
+
"trailingComma": "none",
|
|
126
|
+
"useTabs": false
|
|
127
|
+
},
|
|
128
|
+
"eslintConfig": {
|
|
129
|
+
"root": true,
|
|
130
|
+
"extends": [
|
|
131
|
+
"eslint:recommended",
|
|
132
|
+
"plugin:@typescript-eslint/recommended"
|
|
133
|
+
],
|
|
134
|
+
"parser": "@typescript-eslint/parser",
|
|
135
|
+
"plugins": [
|
|
136
|
+
"@typescript-eslint"
|
|
137
|
+
],
|
|
138
|
+
"rules": {
|
|
139
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
140
|
+
"no-unused-vars": "off",
|
|
141
|
+
"@typescript-eslint/no-unused-vars": [
|
|
142
|
+
"warn",
|
|
143
|
+
{
|
|
144
|
+
"args": "after-used",
|
|
145
|
+
"argsIgnorePattern": "^_"
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
"semi": "off",
|
|
149
|
+
"@typescript-eslint/semi": [
|
|
150
|
+
"error",
|
|
151
|
+
"never"
|
|
152
|
+
],
|
|
153
|
+
"no-extra-semi": "off"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|