@soulcraft/brainy 0.60.0 → 0.61.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/README.md +7 -5
- package/bin/brainy.js +66 -80
- package/dist/augmentations/memoryAugmentations.js +32 -22
- package/dist/brainyData.d.ts +18 -8
- package/dist/brainyData.js +140 -74
- package/dist/coreTypes.d.ts +0 -12
- package/dist/cortex/cortex.js +5 -5
- package/dist/storage/adapters/baseStorageAdapter.d.ts +0 -12
- package/dist/storage/adapters/opfsStorage.js +26 -20
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +0 -12
- package/dist/storage/adapters/s3CompatibleStorage.js +70 -40
- package/dist/storage/baseStorage.d.ts +6 -8
- package/dist/storage/baseStorage.js +12 -20
- package/package.json +5 -5
package/dist/brainyData.js
CHANGED
|
@@ -2146,26 +2146,8 @@ export class BrainyData {
|
|
|
2146
2146
|
}
|
|
2147
2147
|
return results;
|
|
2148
2148
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
* @returns Array of vector documents
|
|
2152
|
-
*/
|
|
2153
|
-
async getAllNouns() {
|
|
2154
|
-
await this.ensureInitialized();
|
|
2155
|
-
try {
|
|
2156
|
-
// Use getNouns with no pagination to get all nouns
|
|
2157
|
-
const result = await this.getNouns({
|
|
2158
|
-
pagination: {
|
|
2159
|
-
limit: Number.MAX_SAFE_INTEGER // Request all nouns
|
|
2160
|
-
}
|
|
2161
|
-
});
|
|
2162
|
-
return result.items;
|
|
2163
|
-
}
|
|
2164
|
-
catch (error) {
|
|
2165
|
-
console.error('Failed to get all nouns:', error);
|
|
2166
|
-
throw new Error(`Failed to get all nouns: ${error}`);
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2149
|
+
// getAllNouns() method removed - use getNouns() with pagination instead
|
|
2150
|
+
// This method was dangerous and could cause expensive scans and memory issues
|
|
2169
2151
|
/**
|
|
2170
2152
|
* Get nouns with pagination and filtering
|
|
2171
2153
|
* @param options Pagination and filtering options
|
|
@@ -2725,7 +2707,7 @@ export class BrainyData {
|
|
|
2725
2707
|
const scores = await this.intelligentVerbScoring.computeVerbScores(sourceId, targetId, verbType, options.weight, options.metadata);
|
|
2726
2708
|
finalWeight = scores.weight;
|
|
2727
2709
|
finalConfidence = scores.confidence;
|
|
2728
|
-
scoringReasoning = scores.reasoning;
|
|
2710
|
+
scoringReasoning = scores.reasoning || [];
|
|
2729
2711
|
if (this.loggingConfig?.verbose && scoringReasoning.length > 0) {
|
|
2730
2712
|
console.log(`Intelligent verb scoring for ${sourceId}-${verbType}-${targetId}:`, scoringReasoning);
|
|
2731
2713
|
}
|
|
@@ -2748,8 +2730,8 @@ export class BrainyData {
|
|
|
2748
2730
|
type: verbType, // Set the type property to match the verb type
|
|
2749
2731
|
weight: finalWeight,
|
|
2750
2732
|
confidence: finalConfidence, // Add confidence to metadata
|
|
2751
|
-
intelligentScoring:
|
|
2752
|
-
reasoning: scoringReasoning,
|
|
2733
|
+
intelligentScoring: this.intelligentVerbScoring?.enabled ? {
|
|
2734
|
+
reasoning: scoringReasoning.length > 0 ? scoringReasoning : [`Final weight ${finalWeight}`, `Base confidence ${finalConfidence || 0.5}`],
|
|
2753
2735
|
computedAt: new Date().toISOString()
|
|
2754
2736
|
} : undefined,
|
|
2755
2737
|
createdAt: timestamp,
|
|
@@ -2851,7 +2833,12 @@ export class BrainyData {
|
|
|
2851
2833
|
updatedAt: metadata.updatedAt,
|
|
2852
2834
|
createdBy: metadata.createdBy,
|
|
2853
2835
|
data: metadata.data,
|
|
2854
|
-
metadata:
|
|
2836
|
+
metadata: {
|
|
2837
|
+
...metadata.data,
|
|
2838
|
+
weight: metadata.weight,
|
|
2839
|
+
confidence: metadata.confidence,
|
|
2840
|
+
...(metadata.intelligentScoring && { intelligentScoring: metadata.intelligentScoring })
|
|
2841
|
+
} // Complete metadata including intelligent scoring when available
|
|
2855
2842
|
};
|
|
2856
2843
|
return graphVerb;
|
|
2857
2844
|
}
|
|
@@ -2861,47 +2848,94 @@ export class BrainyData {
|
|
|
2861
2848
|
}
|
|
2862
2849
|
}
|
|
2863
2850
|
/**
|
|
2864
|
-
*
|
|
2865
|
-
* @
|
|
2851
|
+
* Internal performance optimization: intelligently load verbs when beneficial
|
|
2852
|
+
* @internal - Used by search, indexing, and caching optimizations
|
|
2866
2853
|
*/
|
|
2867
|
-
async
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2854
|
+
async _optimizedLoadAllVerbs() {
|
|
2855
|
+
// Only load all if it's safe and beneficial
|
|
2856
|
+
if (await this._shouldPreloadAllData()) {
|
|
2857
|
+
const result = await this.getVerbs({
|
|
2858
|
+
pagination: { limit: Number.MAX_SAFE_INTEGER }
|
|
2859
|
+
});
|
|
2860
|
+
return result.items;
|
|
2861
|
+
}
|
|
2862
|
+
// Fall back to on-demand loading
|
|
2863
|
+
return [];
|
|
2864
|
+
}
|
|
2865
|
+
/**
|
|
2866
|
+
* Internal performance optimization: intelligently load nouns when beneficial
|
|
2867
|
+
* @internal - Used by search, indexing, and caching optimizations
|
|
2868
|
+
*/
|
|
2869
|
+
async _optimizedLoadAllNouns() {
|
|
2870
|
+
// Only load all if it's safe and beneficial
|
|
2871
|
+
if (await this._shouldPreloadAllData()) {
|
|
2872
|
+
const result = await this.getNouns({
|
|
2873
|
+
pagination: { limit: Number.MAX_SAFE_INTEGER }
|
|
2874
|
+
});
|
|
2875
|
+
return result.items;
|
|
2876
|
+
}
|
|
2877
|
+
// Fall back to on-demand loading
|
|
2878
|
+
return [];
|
|
2879
|
+
}
|
|
2880
|
+
/**
|
|
2881
|
+
* Intelligent decision making for when to preload all data
|
|
2882
|
+
* @internal
|
|
2883
|
+
*/
|
|
2884
|
+
async _shouldPreloadAllData() {
|
|
2885
|
+
// Smart heuristics for performance optimization
|
|
2886
|
+
// 1. Read-only mode is ideal for preloading
|
|
2887
|
+
if (this.readOnly) {
|
|
2888
|
+
return await this._isDatasetSizeReasonable();
|
|
2889
|
+
}
|
|
2890
|
+
// 2. Check available memory (Node.js)
|
|
2891
|
+
if (typeof process !== 'undefined' && process.memoryUsage) {
|
|
2892
|
+
const memUsage = process.memoryUsage();
|
|
2893
|
+
const availableMemory = memUsage.heapTotal - memUsage.heapUsed;
|
|
2894
|
+
const memoryMB = availableMemory / (1024 * 1024);
|
|
2895
|
+
// Only preload if we have substantial free memory (>500MB)
|
|
2896
|
+
if (memoryMB < 500) {
|
|
2897
|
+
console.debug('Performance optimization: Skipping preload due to low memory');
|
|
2898
|
+
return false;
|
|
2898
2899
|
}
|
|
2899
|
-
return graphVerbs;
|
|
2900
2900
|
}
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2901
|
+
// 3. Consider frozen/immutable mode
|
|
2902
|
+
if (this.frozen) {
|
|
2903
|
+
return await this._isDatasetSizeReasonable();
|
|
2904
2904
|
}
|
|
2905
|
+
// 4. For frequent search operations, preloading can be beneficial
|
|
2906
|
+
// TODO: Track search frequency and decide based on access patterns
|
|
2907
|
+
return false; // Conservative default for write-heavy workloads
|
|
2908
|
+
}
|
|
2909
|
+
/**
|
|
2910
|
+
* Estimate if dataset size is reasonable for in-memory loading
|
|
2911
|
+
* @internal
|
|
2912
|
+
*/
|
|
2913
|
+
async _isDatasetSizeReasonable() {
|
|
2914
|
+
// Implement basic size estimation
|
|
2915
|
+
// Check if we have recent statistics
|
|
2916
|
+
const stats = await this.getStatistics();
|
|
2917
|
+
if (stats) {
|
|
2918
|
+
const totalEntities = Object.values(stats.nounCount || {}).reduce((a, b) => a + b, 0) +
|
|
2919
|
+
Object.values(stats.verbCount || {}).reduce((a, b) => a + b, 0);
|
|
2920
|
+
// Conservative thresholds
|
|
2921
|
+
if (totalEntities > 100000) {
|
|
2922
|
+
console.debug('Performance optimization: Dataset too large for preloading');
|
|
2923
|
+
return false;
|
|
2924
|
+
}
|
|
2925
|
+
if (totalEntities < 10000) {
|
|
2926
|
+
console.debug('Performance optimization: Small dataset - safe to preload');
|
|
2927
|
+
return true;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
// Medium datasets - check memory pressure
|
|
2931
|
+
if (typeof process !== 'undefined' && process.memoryUsage) {
|
|
2932
|
+
const memUsage = process.memoryUsage();
|
|
2933
|
+
const heapUsedPercent = (memUsage.heapUsed / memUsage.heapTotal) * 100;
|
|
2934
|
+
// Only preload if heap usage is low
|
|
2935
|
+
return heapUsedPercent < 50;
|
|
2936
|
+
}
|
|
2937
|
+
// Default: conservative approach
|
|
2938
|
+
return false;
|
|
2905
2939
|
}
|
|
2906
2940
|
/**
|
|
2907
2941
|
* Get verbs with pagination and filtering
|
|
@@ -3679,19 +3713,40 @@ export class BrainyData {
|
|
|
3679
3713
|
}
|
|
3680
3714
|
// First use the HNSW index to find similar vectors efficiently
|
|
3681
3715
|
const searchResults = await this.index.search(queryVector, k * 2);
|
|
3682
|
-
//
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3716
|
+
// Intelligent verb loading: preload all if beneficial, otherwise on-demand
|
|
3717
|
+
let verbMap = null;
|
|
3718
|
+
let usePreloadedVerbs = false;
|
|
3719
|
+
// Try to intelligently preload verbs for performance
|
|
3720
|
+
const preloadedVerbs = await this._optimizedLoadAllVerbs();
|
|
3721
|
+
if (preloadedVerbs.length > 0) {
|
|
3722
|
+
verbMap = new Map();
|
|
3723
|
+
for (const verb of preloadedVerbs) {
|
|
3724
|
+
verbMap.set(verb.id, verb);
|
|
3725
|
+
}
|
|
3726
|
+
usePreloadedVerbs = true;
|
|
3727
|
+
console.debug(`Performance optimization: Preloaded ${preloadedVerbs.length} verbs for fast lookup`);
|
|
3688
3728
|
}
|
|
3729
|
+
// Fallback: on-demand verb loading function
|
|
3730
|
+
const getVerbById = async (verbId) => {
|
|
3731
|
+
if (usePreloadedVerbs && verbMap) {
|
|
3732
|
+
return verbMap.get(verbId) || null;
|
|
3733
|
+
}
|
|
3734
|
+
try {
|
|
3735
|
+
const verb = await this.getVerb(verbId);
|
|
3736
|
+
return verb;
|
|
3737
|
+
}
|
|
3738
|
+
catch (error) {
|
|
3739
|
+
console.warn(`Failed to load verb ${verbId}:`, error);
|
|
3740
|
+
return null;
|
|
3741
|
+
}
|
|
3742
|
+
};
|
|
3689
3743
|
// Filter search results to only include verbs
|
|
3690
3744
|
const verbResults = [];
|
|
3745
|
+
// Process search results and load verbs on-demand
|
|
3691
3746
|
for (const result of searchResults) {
|
|
3692
3747
|
// Search results are [id, distance] tuples
|
|
3693
3748
|
const [id, distance] = result;
|
|
3694
|
-
const verb =
|
|
3749
|
+
const verb = await getVerbById(id);
|
|
3695
3750
|
if (verb) {
|
|
3696
3751
|
// If verb types are specified, check if this verb matches
|
|
3697
3752
|
if (options.verbTypes && options.verbTypes.length > 0) {
|
|
@@ -3721,8 +3776,11 @@ export class BrainyData {
|
|
|
3721
3776
|
}
|
|
3722
3777
|
}
|
|
3723
3778
|
else {
|
|
3724
|
-
//
|
|
3725
|
-
|
|
3779
|
+
// Get all verbs with pagination
|
|
3780
|
+
const allVerbsResult = await this.getVerbs({
|
|
3781
|
+
pagination: { limit: 10000 }
|
|
3782
|
+
});
|
|
3783
|
+
verbs = allVerbsResult.items;
|
|
3726
3784
|
}
|
|
3727
3785
|
// Calculate similarity for each verb not already in results
|
|
3728
3786
|
const existingIds = new Set(verbResults.map((v) => v.id));
|
|
@@ -4248,10 +4306,18 @@ export class BrainyData {
|
|
|
4248
4306
|
async backup() {
|
|
4249
4307
|
await this.ensureInitialized();
|
|
4250
4308
|
try {
|
|
4251
|
-
//
|
|
4252
|
-
|
|
4253
|
-
//
|
|
4254
|
-
const
|
|
4309
|
+
// Use intelligent loading for backup - this is a legitimate use case for full export
|
|
4310
|
+
console.log('Creating backup - loading all data...');
|
|
4311
|
+
// For backup, we legitimately need all data, so use large pagination
|
|
4312
|
+
const nounsResult = await this.getNouns({
|
|
4313
|
+
pagination: { limit: Number.MAX_SAFE_INTEGER }
|
|
4314
|
+
});
|
|
4315
|
+
const nouns = nounsResult.items;
|
|
4316
|
+
const verbsResult = await this.getVerbs({
|
|
4317
|
+
pagination: { limit: Number.MAX_SAFE_INTEGER }
|
|
4318
|
+
});
|
|
4319
|
+
const verbs = verbsResult.items;
|
|
4320
|
+
console.log(`Backup: Loaded ${nouns.length} nouns and ${verbs.length} verbs`);
|
|
4255
4321
|
// Get all noun types
|
|
4256
4322
|
const nounTypes = Object.values(NounType);
|
|
4257
4323
|
// Get all verb types
|
package/dist/coreTypes.d.ts
CHANGED
|
@@ -512,16 +512,4 @@ export interface StorageAdapter {
|
|
|
512
512
|
* @returns Promise that resolves to an array of changes
|
|
513
513
|
*/
|
|
514
514
|
getChangesSince?(timestamp: number, limit?: number): Promise<any[]>;
|
|
515
|
-
/**
|
|
516
|
-
* Get all nouns from storage
|
|
517
|
-
* @returns Promise that resolves to an array of all nouns
|
|
518
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getNouns() with pagination instead.
|
|
519
|
-
*/
|
|
520
|
-
getAllNouns(): Promise<HNSWNoun[]>;
|
|
521
|
-
/**
|
|
522
|
-
* Get all verbs from storage
|
|
523
|
-
* @returns Promise that resolves to an array of all HNSWVerbs
|
|
524
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getVerbs() with pagination instead.
|
|
525
|
-
*/
|
|
526
|
-
getAllVerbs(): Promise<HNSWVerb[]>;
|
|
527
515
|
}
|
package/dist/cortex/cortex.js
CHANGED
|
@@ -2158,7 +2158,7 @@ export class Cortex {
|
|
|
2158
2158
|
console.log(boxen(`${emojis.brain}☁️ ${colors.brain('BRAIN CLOUD PREMIUM FEATURES')}\n\n` +
|
|
2159
2159
|
`Premium connectors and features have moved to Brain Cloud!\n\n` +
|
|
2160
2160
|
`${colors.accent('◆')} ${colors.dim('Setup Brain Cloud:')} ${colors.highlight('brainy cloud')}\n` +
|
|
2161
|
-
`${colors.accent('◆')} ${colors.dim('Learn more:')} ${colors.highlight('https://
|
|
2161
|
+
`${colors.accent('◆')} ${colors.dim('Learn more:')} ${colors.highlight('https://soulcraft.com/brain-cloud')}\n\n` +
|
|
2162
2162
|
`${colors.retro('Available Tiers:')}\n` +
|
|
2163
2163
|
`${colors.success('🫙')} Brain Jar (Free) - Local coordination\n` +
|
|
2164
2164
|
`${colors.success('☁️')} Brain Cloud ($19/mo) - Sync everywhere\n` +
|
|
@@ -2174,7 +2174,7 @@ export class Cortex {
|
|
|
2174
2174
|
`${colors.accent('◆')} ${colors.dim('No credit card required')}\n` +
|
|
2175
2175
|
`${colors.accent('◆')} ${colors.dim('Cancel anytime')}\n\n` +
|
|
2176
2176
|
`${colors.highlight('Run: brainy cloud')}\n\n` +
|
|
2177
|
-
`Or visit: ${colors.accent('https://
|
|
2177
|
+
`Or visit: ${colors.accent('https://soulcraft.com/brain-cloud')}`, { padding: 1, borderStyle: 'round', borderColor: '#FFD700' }));
|
|
2178
2178
|
}
|
|
2179
2179
|
async licenseValidate(featureId) {
|
|
2180
2180
|
console.log(colors.info('Premium features available in Brain Cloud'));
|
|
@@ -2189,7 +2189,7 @@ export class Cortex {
|
|
|
2189
2189
|
console.log(boxen(`${emojis.lock} ${colors.brain('BRAIN CLOUD FEATURE')} ${emojis.atom}\n\n` +
|
|
2190
2190
|
`This feature is available in Brain Cloud!\n\n` +
|
|
2191
2191
|
`${colors.highlight('Setup: brainy cloud')}\n` +
|
|
2192
|
-
`${colors.dim('Learn more: https://
|
|
2192
|
+
`${colors.dim('Learn more: https://soulcraft.com/brain-cloud')}`, { padding: 1, borderStyle: 'round', borderColor: '#D67441' }));
|
|
2193
2193
|
}
|
|
2194
2194
|
return false;
|
|
2195
2195
|
}
|
|
@@ -2389,7 +2389,7 @@ export class Cortex {
|
|
|
2389
2389
|
]);
|
|
2390
2390
|
if (!accountResponse.hasAccount) {
|
|
2391
2391
|
console.log('\n' + boxen(`${emojis.sparkles} ${colors.brain('CREATE YOUR ACCOUNT')}\n\n` +
|
|
2392
|
-
`${colors.accent('◆')} Visit: ${colors.highlight('https://
|
|
2392
|
+
`${colors.accent('◆')} Visit: ${colors.highlight('https://soulcraft.com/brain-cloud')}\n` +
|
|
2393
2393
|
`${colors.accent('◆')} Click "Start Free Trial"\n` +
|
|
2394
2394
|
`${colors.accent('◆')} Get your API key\n` +
|
|
2395
2395
|
`${colors.accent('◆')} Return here to continue setup`, { padding: 1, borderStyle: 'round', borderColor: '#FFD700' }));
|
|
@@ -2432,7 +2432,7 @@ export class Cortex {
|
|
|
2432
2432
|
catch (error) {
|
|
2433
2433
|
spinner.fail('Setup failed');
|
|
2434
2434
|
console.error(colors.error('Error:'), error.message);
|
|
2435
|
-
console.log('\n' + colors.dim('Need help? Visit https://
|
|
2435
|
+
console.log('\n' + colors.dim('Need help? Visit https://soulcraft.com/brain-cloud/support'));
|
|
2436
2436
|
}
|
|
2437
2437
|
}
|
|
2438
2438
|
/**
|
|
@@ -29,18 +29,6 @@ export declare abstract class BaseStorageAdapter implements StorageAdapter {
|
|
|
29
29
|
quota: number | null;
|
|
30
30
|
details?: Record<string, any>;
|
|
31
31
|
}>;
|
|
32
|
-
/**
|
|
33
|
-
* Get all nouns from storage
|
|
34
|
-
* @returns Promise that resolves to an array of all nouns
|
|
35
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getNouns() with pagination instead.
|
|
36
|
-
*/
|
|
37
|
-
abstract getAllNouns(): Promise<any[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Get all verbs from storage
|
|
40
|
-
* @returns Promise that resolves to an array of all HNSWVerbs
|
|
41
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getVerbs() with pagination instead.
|
|
42
|
-
*/
|
|
43
|
-
abstract getAllVerbs(): Promise<any[]>;
|
|
44
32
|
/**
|
|
45
33
|
* Get nouns with pagination and filtering
|
|
46
34
|
* @param options Pagination and filtering options
|
|
@@ -146,7 +146,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
146
146
|
connections: this.mapToObject(noun.connections, (set) => Array.from(set))
|
|
147
147
|
};
|
|
148
148
|
// Create or get the file for this noun
|
|
149
|
-
const fileHandle = await this.nounsDir.getFileHandle(noun.id
|
|
149
|
+
const fileHandle = await this.nounsDir.getFileHandle(`${noun.id}.json`, {
|
|
150
150
|
create: true
|
|
151
151
|
});
|
|
152
152
|
// Write the noun data to the file
|
|
@@ -166,7 +166,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
166
166
|
await this.ensureInitialized();
|
|
167
167
|
try {
|
|
168
168
|
// Get the file handle for this noun
|
|
169
|
-
const fileHandle = await this.nounsDir.getFileHandle(id);
|
|
169
|
+
const fileHandle = await this.nounsDir.getFileHandle(`${id}.json`);
|
|
170
170
|
// Read the noun data from the file
|
|
171
171
|
const file = await fileHandle.getFile();
|
|
172
172
|
const text = await file.text();
|
|
@@ -253,7 +253,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
253
253
|
async deleteNode(id) {
|
|
254
254
|
await this.ensureInitialized();
|
|
255
255
|
try {
|
|
256
|
-
await this.nounsDir.removeEntry(id);
|
|
256
|
+
await this.nounsDir.removeEntry(`${id}.json`);
|
|
257
257
|
}
|
|
258
258
|
catch (error) {
|
|
259
259
|
// Ignore NotFoundError, which means the file doesn't exist
|
|
@@ -281,7 +281,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
281
281
|
connections: this.mapToObject(edge.connections, (set) => Array.from(set))
|
|
282
282
|
};
|
|
283
283
|
// Create or get the file for this verb
|
|
284
|
-
const fileHandle = await this.verbsDir.getFileHandle(edge.id
|
|
284
|
+
const fileHandle = await this.verbsDir.getFileHandle(`${edge.id}.json`, {
|
|
285
285
|
create: true
|
|
286
286
|
});
|
|
287
287
|
// Write the verb data to the file
|
|
@@ -307,7 +307,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
307
307
|
await this.ensureInitialized();
|
|
308
308
|
try {
|
|
309
309
|
// Get the file handle for this edge
|
|
310
|
-
const fileHandle = await this.verbsDir.getFileHandle(id);
|
|
310
|
+
const fileHandle = await this.verbsDir.getFileHandle(`${id}.json`);
|
|
311
311
|
// Read the edge data from the file
|
|
312
312
|
const file = await fileHandle.getFile();
|
|
313
313
|
const text = await file.text();
|
|
@@ -389,10 +389,12 @@ export class OPFSStorage extends BaseStorage {
|
|
|
389
389
|
* Get verbs by source (internal implementation)
|
|
390
390
|
*/
|
|
391
391
|
async getVerbsBySource_internal(sourceId) {
|
|
392
|
-
//
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
392
|
+
// Use the paginated approach to properly handle HNSWVerb to GraphVerb conversion
|
|
393
|
+
const result = await this.getVerbsWithPagination({
|
|
394
|
+
filter: { sourceId: [sourceId] },
|
|
395
|
+
limit: Number.MAX_SAFE_INTEGER // Get all matching results
|
|
396
|
+
});
|
|
397
|
+
return result.items;
|
|
396
398
|
}
|
|
397
399
|
/**
|
|
398
400
|
* Get edges by source
|
|
@@ -407,10 +409,12 @@ export class OPFSStorage extends BaseStorage {
|
|
|
407
409
|
* Get verbs by target (internal implementation)
|
|
408
410
|
*/
|
|
409
411
|
async getVerbsByTarget_internal(targetId) {
|
|
410
|
-
//
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
// Use the paginated approach to properly handle HNSWVerb to GraphVerb conversion
|
|
413
|
+
const result = await this.getVerbsWithPagination({
|
|
414
|
+
filter: { targetId: [targetId] },
|
|
415
|
+
limit: Number.MAX_SAFE_INTEGER // Get all matching results
|
|
416
|
+
});
|
|
417
|
+
return result.items;
|
|
414
418
|
}
|
|
415
419
|
/**
|
|
416
420
|
* Get edges by target
|
|
@@ -425,10 +429,12 @@ export class OPFSStorage extends BaseStorage {
|
|
|
425
429
|
* Get verbs by type (internal implementation)
|
|
426
430
|
*/
|
|
427
431
|
async getVerbsByType_internal(type) {
|
|
428
|
-
//
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
+
// Use the paginated approach to properly handle HNSWVerb to GraphVerb conversion
|
|
433
|
+
const result = await this.getVerbsWithPagination({
|
|
434
|
+
filter: { verbType: [type] },
|
|
435
|
+
limit: Number.MAX_SAFE_INTEGER // Get all matching results
|
|
436
|
+
});
|
|
437
|
+
return result.items;
|
|
432
438
|
}
|
|
433
439
|
/**
|
|
434
440
|
* Get edges by type
|
|
@@ -451,7 +457,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
451
457
|
async deleteEdge(id) {
|
|
452
458
|
await this.ensureInitialized();
|
|
453
459
|
try {
|
|
454
|
-
await this.verbsDir.removeEntry(id);
|
|
460
|
+
await this.verbsDir.removeEntry(`${id}.json`);
|
|
455
461
|
}
|
|
456
462
|
catch (error) {
|
|
457
463
|
// Ignore NotFoundError, which means the file doesn't exist
|
|
@@ -468,7 +474,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
468
474
|
await this.ensureInitialized();
|
|
469
475
|
try {
|
|
470
476
|
// Create or get the file for this metadata
|
|
471
|
-
const fileHandle = await this.metadataDir.getFileHandle(id
|
|
477
|
+
const fileHandle = await this.metadataDir.getFileHandle(`${id}.json`, {
|
|
472
478
|
create: true
|
|
473
479
|
});
|
|
474
480
|
// Write the metadata to the file
|
|
@@ -488,7 +494,7 @@ export class OPFSStorage extends BaseStorage {
|
|
|
488
494
|
await this.ensureInitialized();
|
|
489
495
|
try {
|
|
490
496
|
// Get the file handle for this metadata
|
|
491
|
-
const fileHandle = await this.metadataDir.getFileHandle(id);
|
|
497
|
+
const fileHandle = await this.metadataDir.getFileHandle(`${id}.json`);
|
|
492
498
|
// Read the metadata from the file
|
|
493
499
|
const file = await fileHandle.getFile();
|
|
494
500
|
const text = await file.text();
|
|
@@ -305,26 +305,14 @@ export declare class S3CompatibleStorage extends BaseStorage {
|
|
|
305
305
|
* Get verbs by source (internal implementation)
|
|
306
306
|
*/
|
|
307
307
|
protected getVerbsBySource_internal(sourceId: string): Promise<GraphVerb[]>;
|
|
308
|
-
/**
|
|
309
|
-
* Get edges by source
|
|
310
|
-
*/
|
|
311
|
-
protected getEdgesBySource(sourceId: string): Promise<GraphVerb[]>;
|
|
312
308
|
/**
|
|
313
309
|
* Get verbs by target (internal implementation)
|
|
314
310
|
*/
|
|
315
311
|
protected getVerbsByTarget_internal(targetId: string): Promise<GraphVerb[]>;
|
|
316
|
-
/**
|
|
317
|
-
* Get edges by target
|
|
318
|
-
*/
|
|
319
|
-
protected getEdgesByTarget(targetId: string): Promise<GraphVerb[]>;
|
|
320
312
|
/**
|
|
321
313
|
* Get verbs by type (internal implementation)
|
|
322
314
|
*/
|
|
323
315
|
protected getVerbsByType_internal(type: string): Promise<GraphVerb[]>;
|
|
324
|
-
/**
|
|
325
|
-
* Get edges by type
|
|
326
|
-
*/
|
|
327
|
-
protected getEdgesByType(type: string): Promise<GraphVerb[]>;
|
|
328
316
|
/**
|
|
329
317
|
* Delete a verb from storage (internal implementation)
|
|
330
318
|
*/
|