@soulcraft/cortex 1.3.1
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 +16 -0
- package/README.md +125 -0
- package/dist/graph/NativeGraphAdjacencyIndex.d.ts +92 -0
- package/dist/graph/NativeGraphAdjacencyIndex.js +671 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +23 -0
- package/dist/license.d.ts +18 -0
- package/dist/license.js +172 -0
- package/dist/native/NativeEmbeddingEngine.d.ts +79 -0
- package/dist/native/NativeEmbeddingEngine.js +302 -0
- package/dist/native/NativeRoaringBitmap32.d.ts +114 -0
- package/dist/native/NativeRoaringBitmap32.js +221 -0
- package/dist/native/ffi.d.ts +20 -0
- package/dist/native/ffi.js +48 -0
- package/dist/native/index.d.ts +30 -0
- package/dist/native/index.js +58 -0
- package/dist/native/napi.d.ts +21 -0
- package/dist/native/napi.js +88 -0
- package/dist/native/types.d.ts +710 -0
- package/dist/native/types.js +16 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.js +115 -0
- package/dist/storage/mmapFileSystemStorage.d.ts +24 -0
- package/dist/storage/mmapFileSystemStorage.js +73 -0
- package/dist/utils/NativeMetadataIndex.d.ts +185 -0
- package/dist/utils/NativeMetadataIndex.js +1274 -0
- package/dist/utils/nativeEntityIdMapper.d.ts +84 -0
- package/dist/utils/nativeEntityIdMapper.js +134 -0
- package/native/brainy-native.darwin-arm64.node +0 -0
- package/native/brainy-native.darwin-x64.node +0 -0
- package/native/brainy-native.linux-arm64-gnu.node +0 -0
- package/native/brainy-native.linux-x64-gnu.node +0 -0
- package/native/brainy-native.win32-x64-msvc.node +0 -0
- package/native/index.d.ts +1068 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Soulcraft Cortex - Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Soulcraft Labs. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software is proprietary and confidential. Unauthorized copying, distribution,
|
|
6
|
+
modification, or use of this software, via any medium, is strictly prohibited.
|
|
7
|
+
|
|
8
|
+
A valid license key is required to use this software. License keys can be purchased
|
|
9
|
+
at https://soulcraft.com/pricing?focus=pro.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
12
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
13
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
14
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
15
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
16
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @soulcraft/cortex
|
|
2
|
+
|
|
3
|
+
Native Rust acceleration for [Brainy](https://github.com/soulcraftlabs/brainy). Drop-in performance upgrade — zero configuration required.
|
|
4
|
+
|
|
5
|
+
## Pricing
|
|
6
|
+
|
|
7
|
+
Cortex is a commercial add-on for Brainy. A license key is required after the 14-day trial.
|
|
8
|
+
|
|
9
|
+
| Plan | Price | For |
|
|
10
|
+
|------|-------|-----|
|
|
11
|
+
| **Standard** | $199/year | Individuals and small teams |
|
|
12
|
+
| **Enterprise** | $999/year | Companies, priority support |
|
|
13
|
+
|
|
14
|
+
**[Purchase a license at soulcraft.com/pricing](https://soulcraft.com/pricing?focus=pro)**
|
|
15
|
+
|
|
16
|
+
**14-day free trial** — starts automatically on first use, no signup required.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @soulcraft/cortex
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
That's it. Brainy auto-detects cortex during `init()` and uses native implementations where available.
|
|
25
|
+
|
|
26
|
+
## License Setup
|
|
27
|
+
|
|
28
|
+
After purchasing, set your license key via environment variable or file:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Option 1: Environment variable
|
|
32
|
+
export SOULCRAFT_LICENSE=sc_cortex_<your-key>
|
|
33
|
+
|
|
34
|
+
# Option 2: License file
|
|
35
|
+
echo "sc_cortex_<your-key>" > ~/.soulcraft/license
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
License validation is offline-only — no network calls, no telemetry.
|
|
39
|
+
|
|
40
|
+
## What Gets Accelerated
|
|
41
|
+
|
|
42
|
+
| Subsystem | Native Implementation | Impact |
|
|
43
|
+
|-----------|----------------------|--------|
|
|
44
|
+
| Distance functions | SIMD cosine/euclidean/manhattan/dot product | Every vector search uses native distance |
|
|
45
|
+
| Vector quantization | SIMD SQ8/SQ4 distance on compressed vectors | 4-8x memory reduction |
|
|
46
|
+
| Product quantization | Native PQ codebook training and ADC lookup | 16-32x compression for large datasets |
|
|
47
|
+
| Graph compression | Delta-varint encoded connection lists | 2-3x smaller graph storage |
|
|
48
|
+
| Metadata index | Full Rust query/mutation engine with bitmap operations | Faster metadata filtering and mutations |
|
|
49
|
+
| Graph adjacency | 4 LSM-trees with verb tracking in Rust | Faster relationship queries |
|
|
50
|
+
| Embeddings | Candle ML (CPU, CUDA, Metal) | Native inference, no WASM compilation |
|
|
51
|
+
| Roaring bitmaps | CRoaring bindings (binary-compatible) | Faster set operations on entity IDs |
|
|
52
|
+
| Msgpack | Native encode/decode | Faster serialization |
|
|
53
|
+
| Storage | MmapFileSystemStorage with zero-copy SSTables | Faster disk I/O for graph data |
|
|
54
|
+
|
|
55
|
+
## Platform Support
|
|
56
|
+
|
|
57
|
+
| Platform | Architecture | Status |
|
|
58
|
+
|----------|-------------|--------|
|
|
59
|
+
| Linux | x64 (glibc) | Supported |
|
|
60
|
+
| Linux | arm64 (glibc) | Supported |
|
|
61
|
+
| macOS | arm64 (Apple Silicon) | Supported |
|
|
62
|
+
| macOS | x64 (Intel) | Supported |
|
|
63
|
+
| Windows | x64 | Supported |
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import Brainy from '@soulcraft/brainy'
|
|
69
|
+
|
|
70
|
+
// cortex is auto-detected — no import or config needed
|
|
71
|
+
const brain = new Brainy({ storage: { type: 'filesystem', rootDirectory: './data' } })
|
|
72
|
+
await brain.init()
|
|
73
|
+
|
|
74
|
+
// Check if native acceleration is active
|
|
75
|
+
console.log(brain.getActivePlugins())
|
|
76
|
+
// → ['@soulcraft/cortex']
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Manual Registration
|
|
80
|
+
|
|
81
|
+
If auto-detection doesn't suit your setup, register the plugin manually:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import Brainy from '@soulcraft/brainy'
|
|
85
|
+
import cortexPlugin from '@soulcraft/cortex'
|
|
86
|
+
|
|
87
|
+
const brain = new Brainy({ storage: { type: 'memory' } })
|
|
88
|
+
brain.use(cortexPlugin)
|
|
89
|
+
await brain.init()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### MmapFileSystemStorage
|
|
93
|
+
|
|
94
|
+
When cortex is installed, a new storage adapter becomes available:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const brain = new Brainy({
|
|
98
|
+
storage: { type: 'mmap-filesystem', rootDirectory: './data' }
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This extends the standard FileSystemStorage with binary blob support for zero-copy mmap access to LSM-tree SSTables.
|
|
103
|
+
|
|
104
|
+
## Requirements
|
|
105
|
+
|
|
106
|
+
- `@soulcraft/brainy` >= 7.0.0
|
|
107
|
+
- Node.js >= 22 or Bun >= 1.3.0
|
|
108
|
+
- Platform: Linux/macOS/Windows (see table above)
|
|
109
|
+
|
|
110
|
+
## Direct Access
|
|
111
|
+
|
|
112
|
+
For advanced use cases, you can access native bindings directly:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { loadNativeModule, isNativeAvailable } from '@soulcraft/cortex'
|
|
116
|
+
|
|
117
|
+
if (isNativeAvailable()) {
|
|
118
|
+
const native = loadNativeModule()
|
|
119
|
+
const distance = native.cosineDistance(vectorA, vectorB)
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
Commercial. See [LICENSE](./LICENSE) for details.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeGraphAdjacencyIndex — Thin TS wrapper around the Rust graph engine
|
|
3
|
+
*
|
|
4
|
+
* Handles async storage I/O while the Rust engine handles all in-memory
|
|
5
|
+
* data operations (4 LSM-trees, verb tracking, relationship counts).
|
|
6
|
+
*
|
|
7
|
+
* Storage pattern: adapter-controlled I/O with 3-tier fallback.
|
|
8
|
+
* - Tier 1 (mmap): saveBinaryBlob + getBinaryBlobPath → zero-copy queries
|
|
9
|
+
* - Tier 2 (binary blob): saveBinaryBlob only → binary format in memory
|
|
10
|
+
* - Tier 3 (legacy): saveMetadata → base64 JSON
|
|
11
|
+
*
|
|
12
|
+
* UnifiedCache integration stays in TS (getVerbCached, getVerbsBatchCached)
|
|
13
|
+
* since it coordinates cross-subsystem caching and requires async storage access.
|
|
14
|
+
*/
|
|
15
|
+
import type { GraphVerb, StorageAdapter } from '@soulcraft/brainy';
|
|
16
|
+
export interface GraphIndexConfig {
|
|
17
|
+
maxIndexSize?: number;
|
|
18
|
+
rebuildThreshold?: number;
|
|
19
|
+
autoOptimize?: boolean;
|
|
20
|
+
flushInterval?: number;
|
|
21
|
+
memTableThreshold?: number;
|
|
22
|
+
maxSSTablesPerLevel?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface GraphIndexStats {
|
|
25
|
+
totalRelationships: number;
|
|
26
|
+
sourceNodes: number;
|
|
27
|
+
targetNodes: number;
|
|
28
|
+
memoryUsage: number;
|
|
29
|
+
lastRebuild: number;
|
|
30
|
+
rebuildTime: number;
|
|
31
|
+
}
|
|
32
|
+
export declare class GraphAdjacencyIndex {
|
|
33
|
+
private storage;
|
|
34
|
+
private native;
|
|
35
|
+
private unifiedCache;
|
|
36
|
+
private config;
|
|
37
|
+
private initialized;
|
|
38
|
+
private isRebuilding;
|
|
39
|
+
private flushTimer?;
|
|
40
|
+
private rebuildStartTime;
|
|
41
|
+
private totalRelationshipsIndexed;
|
|
42
|
+
private isCompacting;
|
|
43
|
+
private hasBinaryBlobs;
|
|
44
|
+
private hasMmapPaths;
|
|
45
|
+
get isInitialized(): boolean;
|
|
46
|
+
constructor(storage: StorageAdapter, config?: GraphIndexConfig);
|
|
47
|
+
private ensureInitialized;
|
|
48
|
+
private populateVerbIdSetFromStorage;
|
|
49
|
+
getNeighbors(id: string, optionsOrDirection?: {
|
|
50
|
+
direction?: 'in' | 'out' | 'both';
|
|
51
|
+
limit?: number;
|
|
52
|
+
offset?: number;
|
|
53
|
+
} | 'in' | 'out' | 'both'): Promise<string[]>;
|
|
54
|
+
getVerbIdsBySource(sourceId: string, options?: {
|
|
55
|
+
limit?: number;
|
|
56
|
+
offset?: number;
|
|
57
|
+
}): Promise<string[]>;
|
|
58
|
+
getVerbIdsByTarget(targetId: string, options?: {
|
|
59
|
+
limit?: number;
|
|
60
|
+
offset?: number;
|
|
61
|
+
}): Promise<string[]>;
|
|
62
|
+
getVerbCached(verbId: string): Promise<GraphVerb | null>;
|
|
63
|
+
getVerbsBatchCached(verbIds: string[]): Promise<Map<string, GraphVerb>>;
|
|
64
|
+
addVerb(verb: GraphVerb): Promise<void>;
|
|
65
|
+
removeVerb(verbId: string): Promise<void>;
|
|
66
|
+
size(): number;
|
|
67
|
+
getRelationshipCountByType(type: string): number;
|
|
68
|
+
getTotalRelationshipCount(): number;
|
|
69
|
+
getAllRelationshipCounts(): Map<string, number>;
|
|
70
|
+
getRelationshipStats(): {
|
|
71
|
+
totalRelationships: number;
|
|
72
|
+
relationshipsByType: Record<string, number>;
|
|
73
|
+
uniqueSourceNodes: number;
|
|
74
|
+
uniqueTargetNodes: number;
|
|
75
|
+
totalNodes: number;
|
|
76
|
+
};
|
|
77
|
+
getStats(): GraphIndexStats;
|
|
78
|
+
isHealthy(): boolean;
|
|
79
|
+
rebuild(): Promise<void>;
|
|
80
|
+
flush(): Promise<void>;
|
|
81
|
+
close(): Promise<void>;
|
|
82
|
+
/** Blob key for an SSTable: "graph-lsm/{treeName}/{sstableId}" */
|
|
83
|
+
private blobKey;
|
|
84
|
+
private loadTreeFromStorage;
|
|
85
|
+
private loadTreeSSTables;
|
|
86
|
+
private flushTree;
|
|
87
|
+
private compactTree;
|
|
88
|
+
private saveTreeManifest;
|
|
89
|
+
private startAutoFlush;
|
|
90
|
+
private calculateMemoryUsage;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=NativeGraphAdjacencyIndex.d.ts.map
|