@soulcraft/brainy 2.14.1 → 2.14.3
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.
|
@@ -117,22 +117,6 @@ export declare abstract class BaseStorageAdapter implements StorageAdapter {
|
|
|
117
117
|
hasMore: boolean;
|
|
118
118
|
nextCursor?: string;
|
|
119
119
|
}>;
|
|
120
|
-
/**
|
|
121
|
-
* Count total number of nouns (optional)
|
|
122
|
-
* WARNING: Implementations should be efficient for large datasets.
|
|
123
|
-
* Consider caching counts or using database COUNT operations.
|
|
124
|
-
* @param filter Optional filter criteria
|
|
125
|
-
* @returns Promise that resolves to the count
|
|
126
|
-
*/
|
|
127
|
-
countNouns?(filter?: any): Promise<number>;
|
|
128
|
-
/**
|
|
129
|
-
* Count total number of verbs (optional)
|
|
130
|
-
* WARNING: Implementations should be efficient for large datasets.
|
|
131
|
-
* Consider caching counts or using database COUNT operations.
|
|
132
|
-
* @param filter Optional filter criteria
|
|
133
|
-
* @returns Promise that resolves to the count
|
|
134
|
-
*/
|
|
135
|
-
countVerbs?(filter?: any): Promise<number>;
|
|
136
120
|
protected statisticsCache: StatisticsData | null;
|
|
137
121
|
protected statisticsBatchUpdateTimerId: NodeJS.Timeout | null;
|
|
138
122
|
protected statisticsModified: boolean;
|
|
@@ -823,19 +823,44 @@ export class FileSystemStorage extends BaseStorage {
|
|
|
823
823
|
const file = verbFiles[i];
|
|
824
824
|
const id = file.replace('.json', '');
|
|
825
825
|
try {
|
|
826
|
-
// Read the verb data
|
|
826
|
+
// Read the verb data (HNSWVerb stored as edge)
|
|
827
827
|
const filePath = path.join(this.verbsDir, file);
|
|
828
828
|
const data = await fs.promises.readFile(filePath, 'utf-8');
|
|
829
829
|
const edge = JSON.parse(data);
|
|
830
|
-
//
|
|
830
|
+
// Get metadata which contains the actual verb information
|
|
831
831
|
const metadata = await this.getVerbMetadata(id);
|
|
832
|
-
//
|
|
832
|
+
// If no metadata exists, skip this verb (it's incomplete)
|
|
833
|
+
if (!metadata) {
|
|
834
|
+
console.warn(`Verb ${id} has no metadata, skipping`);
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
// Convert connections Map to proper format if needed
|
|
838
|
+
let connections = edge.connections;
|
|
839
|
+
if (connections && typeof connections === 'object' && !(connections instanceof Map)) {
|
|
840
|
+
const connectionsMap = new Map();
|
|
841
|
+
for (const [level, nodeIds] of Object.entries(connections)) {
|
|
842
|
+
connectionsMap.set(Number(level), new Set(nodeIds));
|
|
843
|
+
}
|
|
844
|
+
connections = connectionsMap;
|
|
845
|
+
}
|
|
846
|
+
// Properly reconstruct GraphVerb from HNSWVerb + metadata
|
|
833
847
|
const verb = {
|
|
834
848
|
id: edge.id,
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
849
|
+
vector: edge.vector, // Include the vector field!
|
|
850
|
+
connections: connections,
|
|
851
|
+
sourceId: metadata.sourceId || metadata.source,
|
|
852
|
+
targetId: metadata.targetId || metadata.target,
|
|
853
|
+
source: metadata.source || metadata.sourceId,
|
|
854
|
+
target: metadata.target || metadata.targetId,
|
|
855
|
+
verb: metadata.verb || metadata.type,
|
|
856
|
+
type: metadata.type || metadata.verb,
|
|
857
|
+
weight: metadata.weight,
|
|
858
|
+
metadata: metadata.metadata || metadata,
|
|
859
|
+
data: metadata.data,
|
|
860
|
+
createdAt: metadata.createdAt,
|
|
861
|
+
updatedAt: metadata.updatedAt,
|
|
862
|
+
createdBy: metadata.createdBy,
|
|
863
|
+
embedding: metadata.embedding || edge.vector
|
|
839
864
|
};
|
|
840
865
|
// Apply filters if provided
|
|
841
866
|
if (options.filter) {
|
|
@@ -843,19 +868,22 @@ export class FileSystemStorage extends BaseStorage {
|
|
|
843
868
|
// Check verbType filter
|
|
844
869
|
if (filter.verbType) {
|
|
845
870
|
const types = Array.isArray(filter.verbType) ? filter.verbType : [filter.verbType];
|
|
846
|
-
|
|
871
|
+
const verbType = verb.type || verb.verb;
|
|
872
|
+
if (verbType && !types.includes(verbType))
|
|
847
873
|
continue;
|
|
848
874
|
}
|
|
849
875
|
// Check sourceId filter
|
|
850
876
|
if (filter.sourceId) {
|
|
851
877
|
const sources = Array.isArray(filter.sourceId) ? filter.sourceId : [filter.sourceId];
|
|
852
|
-
|
|
878
|
+
const sourceId = verb.sourceId || verb.source;
|
|
879
|
+
if (!sourceId || !sources.includes(sourceId))
|
|
853
880
|
continue;
|
|
854
881
|
}
|
|
855
882
|
// Check targetId filter
|
|
856
883
|
if (filter.targetId) {
|
|
857
884
|
const targets = Array.isArray(filter.targetId) ? filter.targetId : [filter.targetId];
|
|
858
|
-
|
|
885
|
+
const targetId = verb.targetId || verb.target;
|
|
886
|
+
if (!targetId || !targets.includes(targetId))
|
|
859
887
|
continue;
|
|
860
888
|
}
|
|
861
889
|
// Check service filter
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.3",
|
|
4
4
|
"description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|