@soulcraft/brainy 0.11.0 → 0.13.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.demo.md +1 -1
- package/README.md +8 -64
- package/dist/brainyData.d.ts +41 -0
- package/dist/patched-platform-node.d.ts +17 -0
- package/dist/setup.d.ts +16 -0
- package/dist/storage/fileSystemStorage.d.ts.map +1 -1
- package/dist/unified.d.ts +5 -3
- package/dist/unified.js +902 -294
- package/dist/unified.min.js +765 -749
- package/dist/utils/distance.d.ts.map +1 -1
- package/dist/utils/embedding.d.ts +68 -5
- package/dist/utils/embedding.d.ts.map +1 -1
- package/dist/utils/environment.d.ts.map +1 -1
- package/dist/utils/textEncoding.d.ts +13 -20
- package/dist/utils/textEncoding.d.ts.map +1 -1
- package/dist/utils/version.d.ts +1 -1
- package/package.json +32 -13
- package/dist/augmentations/huggingfaceActivation.d.ts +0 -57
- package/dist/augmentations/huggingfaceActivation.d.ts.map +0 -1
- package/dist/augmentations/huggingfaceActivationRegistration.d.ts +0 -6
- package/dist/augmentations/huggingfaceActivationRegistration.d.ts.map +0 -1
- package/dist/brainy.js +0 -87290
- package/dist/brainy.min.js +0 -12495
- package/dist/cli.d.ts +0 -7
- package/dist/utils/distance-js.d.ts +0 -38
- package/dist/utils/distance-js.d.ts.map +0 -1
- package/dist/utils/distance-wasm.d.ts +0 -36
- package/dist/utils/distance-wasm.d.ts.map +0 -1
- package/dist/utils/huggingfaceEmbedding.d.ts +0 -53
- package/dist/utils/huggingfaceEmbedding.d.ts.map +0 -1
- package/dist/utils/tensorflowBridge.d.ts +0 -14
- package/dist/utils/tensorflowBridge.d.ts.map +0 -1
- package/dist/utils/textEncoderPolyfill.d.ts +0 -6
- package/dist/utils/textEncoderPolyfill.d.ts.map +0 -1
- package/dist/utils/universalDebug.d.ts +0 -21
- package/dist/utils/universalDebug.d.ts.map +0 -1
- package/dist/utils/universalUuid.d.ts +0 -26
- package/dist/utils/universalUuid.d.ts.map +0 -1
package/README.demo.md
CHANGED
|
@@ -35,7 +35,7 @@ npx http-server
|
|
|
35
35
|
If you see the error "Could not load Brainy library. Please ensure the project is built and served over HTTP", check the
|
|
36
36
|
following:
|
|
37
37
|
|
|
38
|
-
1. Make sure you've built the project with `npm run build:
|
|
38
|
+
1. Make sure you've built the project with `npm run build && npm run build:browser`
|
|
39
39
|
2. Ensure you're accessing the demo through HTTP (not by opening the file directly)
|
|
40
40
|
3. Check your browser's console for additional error messages
|
|
41
41
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://nodejs.org/)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](CONTRIBUTING.md)
|
|
9
|
-
[](https://www.npmjs.com/package/@soulcraft/brainy)
|
|
10
10
|
|
|
11
11
|
[//]: # ([](https://github.com/sodal-project/cartographer))
|
|
12
12
|
|
|
@@ -62,12 +62,7 @@ GitHub Pages that showcases Brainy's main features.
|
|
|
62
62
|
npm install @soulcraft/brainy
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
TensorFlow.js packages are included as
|
|
66
|
-
dependency conflicts, you may need to use the `--legacy-peer-deps` flag:
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
npm install @soulcraft/brainy --legacy-peer-deps
|
|
70
|
-
```
|
|
65
|
+
TensorFlow.js packages are included as bundled dependencies and will be automatically installed without any additional configuration.
|
|
71
66
|
|
|
72
67
|
## 🏁 Quick Start
|
|
73
68
|
|
|
@@ -110,14 +105,9 @@ import { BrainyData } from '@soulcraft/brainy'
|
|
|
110
105
|
|
|
111
106
|
// Minified version for production
|
|
112
107
|
import { BrainyData } from '@soulcraft/brainy/min'
|
|
113
|
-
|
|
114
|
-
// CLI functionality (only imported when needed)
|
|
115
|
-
import '@soulcraft/brainy/cli'
|
|
116
108
|
```
|
|
117
109
|
|
|
118
|
-
> **Note**: The CLI functionality
|
|
119
|
-
> Node.js applications. The CLI is only built and loaded when explicitly imported or when using the command-line
|
|
120
|
-
> interface.
|
|
110
|
+
> **Note**: The CLI functionality is available as a separate package `@soulcraft/brainy-cli` to reduce the bundle size of the main package. Install it globally with `npm install -g @soulcraft/brainy-cli` to use the command-line interface.
|
|
121
111
|
|
|
122
112
|
### Browser Usage
|
|
123
113
|
|
|
@@ -417,18 +407,13 @@ brainy visualize --root <id> --depth 3
|
|
|
417
407
|
|
|
418
408
|
### Using the CLI in Your Code
|
|
419
409
|
|
|
420
|
-
If you need
|
|
421
|
-
|
|
422
|
-
```typescript
|
|
423
|
-
// Import the CLI functionality
|
|
424
|
-
import '@soulcraft/brainy/cli'
|
|
410
|
+
The CLI functionality is available as a separate package `@soulcraft/brainy-cli`. If you need CLI functionality in your application, install the CLI package:
|
|
425
411
|
|
|
426
|
-
|
|
427
|
-
|
|
412
|
+
```bash
|
|
413
|
+
npm install @soulcraft/brainy-cli
|
|
428
414
|
```
|
|
429
415
|
|
|
430
|
-
|
|
431
|
-
the CLI.
|
|
416
|
+
Then you can use the CLI commands programmatically or through the command line interface.
|
|
432
417
|
|
|
433
418
|
### Available Commands
|
|
434
419
|
|
|
@@ -933,8 +918,7 @@ the augmentation pipeline as tools:
|
|
|
933
918
|
Environment compatibility:
|
|
934
919
|
|
|
935
920
|
- **BrainyMCPAdapter** and **MCPAugmentationToolset** can run in any environment (browser, Node.js, server)
|
|
936
|
-
- **BrainyMCPService** core functionality works in any environment
|
|
937
|
-
cloud-wrapper project
|
|
921
|
+
- **BrainyMCPService** core functionality works in any environment
|
|
938
922
|
|
|
939
923
|
For detailed documentation and usage examples, see the [MCP documentation](src/mcp/README.md).
|
|
940
924
|
|
|
@@ -984,46 +968,6 @@ Works in all modern browsers:
|
|
|
984
968
|
|
|
985
969
|
For browsers without OPFS support, falls back to in-memory storage.
|
|
986
970
|
|
|
987
|
-
## Cloud Deployment
|
|
988
|
-
|
|
989
|
-
Brainy can be deployed as a standalone web service on various cloud platforms using the included cloud wrapper:
|
|
990
|
-
|
|
991
|
-
- **AWS Lambda and API Gateway**: Deploy as a serverless function with API Gateway
|
|
992
|
-
- **Google Cloud Run**: Deploy as a containerized service
|
|
993
|
-
- **Cloudflare Workers**: Deploy as a serverless function on the edge
|
|
994
|
-
|
|
995
|
-
The cloud wrapper provides both RESTful and WebSocket APIs for all Brainy operations, enabling both request-response and
|
|
996
|
-
real-time communication patterns. It supports multiple storage backends and can be configured via environment variables.
|
|
997
|
-
|
|
998
|
-
Key features of the cloud wrapper:
|
|
999
|
-
|
|
1000
|
-
- RESTful API for standard CRUD operations
|
|
1001
|
-
- WebSocket API for real-time updates and subscriptions
|
|
1002
|
-
- Model Control Protocol (MCP) service for external model access
|
|
1003
|
-
- Support for multiple storage backends (Memory, FileSystem, S3)
|
|
1004
|
-
- Configurable via environment variables
|
|
1005
|
-
- Deployment scripts for AWS, Google Cloud, and Cloudflare
|
|
1006
|
-
|
|
1007
|
-
### Deploying to the Cloud
|
|
1008
|
-
|
|
1009
|
-
You can deploy the cloud wrapper to various cloud platforms using the following npm scripts from the root directory:
|
|
1010
|
-
|
|
1011
|
-
```bash
|
|
1012
|
-
# Deploy to AWS Lambda and API Gateway
|
|
1013
|
-
npm run deploy:cloud:aws
|
|
1014
|
-
|
|
1015
|
-
# Deploy to Google Cloud Run
|
|
1016
|
-
npm run deploy:cloud:gcp
|
|
1017
|
-
|
|
1018
|
-
# Deploy to Cloudflare Workers
|
|
1019
|
-
npm run deploy:cloud:cloudflare
|
|
1020
|
-
|
|
1021
|
-
# Show available deployment options
|
|
1022
|
-
npm run deploy:cloud
|
|
1023
|
-
```
|
|
1024
|
-
|
|
1025
|
-
Before deploying, make sure to configure the appropriate environment variables in the `cloud-wrapper/.env` file. See
|
|
1026
|
-
the [Cloud Wrapper README](cloud-wrapper/README.md) for detailed configuration instructions and API documentation.
|
|
1027
971
|
|
|
1028
972
|
## Related Projects
|
|
1029
973
|
|
package/dist/brainyData.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ import { NounType, VerbType } from './types/graphTypes.js';
|
|
|
8
8
|
import { WebSocketConnection } from './types/augmentations.js';
|
|
9
9
|
import { BrainyDataInterface } from './types/brainyDataInterface.js';
|
|
10
10
|
export interface BrainyDataConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Vector dimensions (required if not using an embedding function that auto-detects dimensions)
|
|
13
|
+
*/
|
|
14
|
+
dimensions?: number;
|
|
11
15
|
/**
|
|
12
16
|
* HNSW index configuration
|
|
13
17
|
*/
|
|
@@ -85,6 +89,17 @@ export interface BrainyDataConfig {
|
|
|
85
89
|
*/
|
|
86
90
|
autoConnect?: boolean;
|
|
87
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Logging configuration
|
|
94
|
+
*/
|
|
95
|
+
logging?: {
|
|
96
|
+
/**
|
|
97
|
+
* Whether to enable verbose logging
|
|
98
|
+
* When false, suppresses non-essential log messages like model loading progress
|
|
99
|
+
* Default: true
|
|
100
|
+
*/
|
|
101
|
+
verbose?: boolean;
|
|
102
|
+
};
|
|
88
103
|
}
|
|
89
104
|
export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
90
105
|
private index;
|
|
@@ -97,9 +112,23 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
97
112
|
private readOnly;
|
|
98
113
|
private storageConfig;
|
|
99
114
|
private useOptimizedIndex;
|
|
115
|
+
private _dimensions;
|
|
116
|
+
private loggingConfig;
|
|
100
117
|
private remoteServerConfig;
|
|
101
118
|
private serverSearchConduit;
|
|
102
119
|
private serverConnection;
|
|
120
|
+
/**
|
|
121
|
+
* Get the vector dimensions
|
|
122
|
+
*/
|
|
123
|
+
get dimensions(): number;
|
|
124
|
+
/**
|
|
125
|
+
* Get the maximum connections parameter from HNSW configuration
|
|
126
|
+
*/
|
|
127
|
+
get maxConnections(): number;
|
|
128
|
+
/**
|
|
129
|
+
* Get the efConstruction parameter from HNSW configuration
|
|
130
|
+
*/
|
|
131
|
+
get efConstruction(): number;
|
|
103
132
|
/**
|
|
104
133
|
* Create a new vector database
|
|
105
134
|
*/
|
|
@@ -134,6 +163,18 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
134
163
|
addToRemote?: boolean;
|
|
135
164
|
id?: string;
|
|
136
165
|
}): Promise<string>;
|
|
166
|
+
/**
|
|
167
|
+
* Add a text item to the database with automatic embedding
|
|
168
|
+
* This is a convenience method for adding text data with metadata
|
|
169
|
+
* @param text Text data to add
|
|
170
|
+
* @param metadata Metadata to associate with the text
|
|
171
|
+
* @param options Additional options
|
|
172
|
+
* @returns The ID of the added item
|
|
173
|
+
*/
|
|
174
|
+
addItem(text: string, metadata?: T, options?: {
|
|
175
|
+
addToRemote?: boolean;
|
|
176
|
+
id?: string;
|
|
177
|
+
}): Promise<string>;
|
|
137
178
|
/**
|
|
138
179
|
* Add data to both local and remote Brainy instances
|
|
139
180
|
* @param vectorOrData Vector or data to add
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom patched implementation of TensorFlow.js PlatformNode class
|
|
3
|
+
* This resolves the TextEncoder/TextDecoder constructor issues
|
|
4
|
+
*/
|
|
5
|
+
export declare class PatchedPlatformNode {
|
|
6
|
+
util: {
|
|
7
|
+
TextEncoder: typeof TextEncoder;
|
|
8
|
+
TextDecoder: typeof TextDecoder;
|
|
9
|
+
isFloat32Array: (arr: any) => boolean;
|
|
10
|
+
isTypedArray: (arr: any) => boolean;
|
|
11
|
+
};
|
|
12
|
+
textEncoder: TextEncoder;
|
|
13
|
+
textDecoder: TextDecoder;
|
|
14
|
+
constructor();
|
|
15
|
+
isFloat32Array(arr: any): boolean;
|
|
16
|
+
isTypedArray(arr: any): boolean;
|
|
17
|
+
}
|
package/dist/setup.d.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRITICAL: This file is imported for its side effects to patch the environment
|
|
3
|
+
* for TensorFlow.js before any other library code runs.
|
|
4
|
+
*
|
|
5
|
+
* It ensures that by the time TensorFlow.js is imported by any other
|
|
6
|
+
* module, the necessary compatibility fixes for the current Node.js
|
|
7
|
+
* environment are already in place.
|
|
8
|
+
*
|
|
9
|
+
* This file MUST be imported as the first import in unified.ts to prevent
|
|
10
|
+
* race conditions with TensorFlow.js initialization. Failure to do so will
|
|
11
|
+
* result in errors like "TextEncoder is not a constructor" when the package
|
|
12
|
+
* is used in Node.js environments.
|
|
13
|
+
*
|
|
14
|
+
* The package.json file marks this file as having side effects to prevent
|
|
15
|
+
* tree-shaking by bundlers, ensuring the patch is always applied.
|
|
16
|
+
*/
|
|
1
17
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileSystemStorage.d.ts","sourceRoot":"","sources":["../../src/storage/fileSystemStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AA4DrE;;GAEG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACtD,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,aAAa,CAAQ;gBAEjB,aAAa,CAAC,EAAE,MAAM;IAelC;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"fileSystemStorage.d.ts","sourceRoot":"","sources":["../../src/storage/fileSystemStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,M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AM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAMrE;;;;OAIG;IACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAMrE;;;;OAIG;IACU,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAMlD,WAAW,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAoBnC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAalD;;;;OAIG;IACU,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnE;;;;OAIG;IACU,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAc5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4DtB,gBAAgB,IAAI,OAAO,CAAC;QACvC,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAC9B,CAAC;CAyCH"}
|
package/dist/unified.d.ts
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* This file exports everything from index.ts
|
|
4
4
|
* Environment detection is handled here and made available to all components
|
|
5
5
|
*/
|
|
6
|
+
import './setup.js';
|
|
6
7
|
export declare const environment: {
|
|
7
|
-
isBrowser: boolean;
|
|
8
|
-
isNode:
|
|
9
|
-
isServerless: boolean;
|
|
8
|
+
readonly isBrowser: boolean;
|
|
9
|
+
readonly isNode: boolean;
|
|
10
|
+
readonly isServerless: boolean;
|
|
10
11
|
};
|
|
11
12
|
export * from './index.js';
|
|
13
|
+
export { applyTensorFlowPatch } from './utils/textEncoding.js';
|