@soulcraft/brainy 6.2.2 → 6.2.4

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.
Files changed (31) hide show
  1. package/dist/augmentations/KnowledgeAugmentation.d.ts +40 -0
  2. package/dist/augmentations/KnowledgeAugmentation.js +251 -0
  3. package/dist/importManager.d.ts +78 -0
  4. package/dist/importManager.js +267 -0
  5. package/dist/query/typeInference.d.ts +158 -0
  6. package/dist/query/typeInference.js +760 -0
  7. package/dist/storage/adapters/historicalStorageAdapter.d.ts +0 -2
  8. package/dist/storage/adapters/historicalStorageAdapter.js +4 -4
  9. package/dist/storage/adapters/typeAwareStorageAdapter.d.ts +252 -0
  10. package/dist/storage/adapters/typeAwareStorageAdapter.js +814 -0
  11. package/dist/storage/baseStorage.d.ts +12 -0
  12. package/dist/storage/baseStorage.js +16 -0
  13. package/dist/types/brainyDataInterface.d.ts +52 -0
  14. package/dist/types/brainyDataInterface.js +10 -0
  15. package/dist/utils/metadataIndex.d.ts +6 -2
  16. package/dist/utils/metadataIndex.js +31 -14
  17. package/dist/vfs/ConceptSystem.d.ts +203 -0
  18. package/dist/vfs/ConceptSystem.js +545 -0
  19. package/dist/vfs/EntityManager.d.ts +75 -0
  20. package/dist/vfs/EntityManager.js +216 -0
  21. package/dist/vfs/EventRecorder.d.ts +84 -0
  22. package/dist/vfs/EventRecorder.js +269 -0
  23. package/dist/vfs/GitBridge.d.ts +167 -0
  24. package/dist/vfs/GitBridge.js +537 -0
  25. package/dist/vfs/KnowledgeLayer.d.ts +35 -0
  26. package/dist/vfs/KnowledgeLayer.js +443 -0
  27. package/dist/vfs/PersistentEntitySystem.d.ts +165 -0
  28. package/dist/vfs/PersistentEntitySystem.js +503 -0
  29. package/dist/vfs/SemanticVersioning.d.ts +105 -0
  30. package/dist/vfs/SemanticVersioning.js +309 -0
  31. package/package.json +1 -1
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Type Inference System - Phase 3: Type-First Query Optimization
3
+ *
4
+ * Automatically infers NounTypes from natural language queries using keyword-based
5
+ * heuristics for fast O(1) type detection.
6
+ *
7
+ * Performance Guarantee: < 1ms per query
8
+ * Accuracy Target: > 80%
9
+ *
10
+ * Examples:
11
+ * - "Find engineers in San Francisco" → [Person, Location]
12
+ * - "Show documents about AI" → [Document, Concept]
13
+ * - "List companies in tech sector" → [Organization, Topic]
14
+ */
15
+ import { NounType } from '../types/graphTypes.js';
16
+ /**
17
+ * Result of type inference with confidence score
18
+ */
19
+ export interface TypeInference {
20
+ type: NounType;
21
+ confidence: number;
22
+ matchedKeywords: string[];
23
+ }
24
+ /**
25
+ * Configuration for type inference behavior
26
+ */
27
+ export interface TypeInferenceConfig {
28
+ /**
29
+ * Minimum confidence threshold to include a type (default: 0.4)
30
+ */
31
+ minConfidence?: number;
32
+ /**
33
+ * Maximum number of types to return (default: 5)
34
+ */
35
+ maxTypes?: number;
36
+ /**
37
+ * Enable debug logging (default: false)
38
+ */
39
+ debug?: boolean;
40
+ /**
41
+ * Enable vector similarity fallback for unknown words (default: false)
42
+ * When enabled, queries with low keyword confidence trigger vector-based type inference
43
+ */
44
+ enableVectorFallback?: boolean;
45
+ /**
46
+ * Minimum confidence threshold to trigger vector fallback (default: 0.7)
47
+ * If keyword matching produces confidence below this, vector fallback is used
48
+ */
49
+ fallbackConfidenceThreshold?: number;
50
+ /**
51
+ * Minimum similarity score for vector-based type matches (default: 0.5)
52
+ */
53
+ vectorThreshold?: number;
54
+ }
55
+ /**
56
+ * Type Inference System
57
+ *
58
+ * Uses keyword matching for fast type detection from natural language.
59
+ * Designed for billion-scale performance with minimal latency.
60
+ */
61
+ export declare class TypeInferenceSystem {
62
+ private keywordMap;
63
+ private phraseMap;
64
+ private config;
65
+ private typeEmbeddings;
66
+ private embedder;
67
+ constructor(config?: TypeInferenceConfig);
68
+ /**
69
+ * Infer noun types from a natural language query (synchronous keyword matching only)
70
+ * For hybrid mode with vector fallback, use inferTypesAsync()
71
+ *
72
+ * @param query - Natural language query string
73
+ * @returns Array of type inferences sorted by confidence (highest first)
74
+ */
75
+ inferTypes(query: string): TypeInference[];
76
+ /**
77
+ * Infer noun types with hybrid approach: keyword matching + optional vector fallback
78
+ * This is the async version that supports vector similarity fallback
79
+ *
80
+ * @param query - Natural language query string
81
+ * @returns Promise resolving to array of type inferences
82
+ */
83
+ inferTypesAsync(query: string): Promise<TypeInference[]>;
84
+ /**
85
+ * Internal: Keyword-based type inference (synchronous, fast)
86
+ */
87
+ private inferTypesViaKeywords;
88
+ /**
89
+ * Internal: Hybrid inference with vector fallback (asynchronous)
90
+ */
91
+ private inferTypesWithFallback;
92
+ /**
93
+ * Match multi-word phrases in query
94
+ */
95
+ private matchPhrases;
96
+ /**
97
+ * Match individual keywords in query
98
+ */
99
+ private matchKeywords;
100
+ /**
101
+ * Find closest keyword using edit distance (for typo correction)
102
+ * Allows edit distance 1-2 depending on word length
103
+ */
104
+ private findFuzzyKeywordMatch;
105
+ /**
106
+ * Calculate Levenshtein (edit) distance between two strings
107
+ */
108
+ private levenshteinDistance;
109
+ /**
110
+ * Update type score with new match
111
+ */
112
+ private updateTypeScore;
113
+ /**
114
+ * Load pre-compiled type embeddings from embeddedTypeEmbeddings.ts
115
+ */
116
+ private loadTypeEmbeddings;
117
+ /**
118
+ * Lazy-load TransformerEmbedding model (only when vector fallback is triggered)
119
+ */
120
+ private loadEmbedder;
121
+ /**
122
+ * Calculate cosine similarity between two vectors
123
+ */
124
+ private cosineSimilarity;
125
+ /**
126
+ * Infer types using vector similarity against pre-compiled type embeddings
127
+ */
128
+ private inferTypesViaVectorSimilarity;
129
+ /**
130
+ * Merge keyword-based and vector-based results
131
+ * Prioritizes keyword results (explicit matches) over vector results (semantic matches)
132
+ */
133
+ private mergeResults;
134
+ /**
135
+ * Build keyword dictionary for single-word matching
136
+ */
137
+ private buildKeywordMap;
138
+ /**
139
+ * Build phrase dictionary for multi-word matching
140
+ */
141
+ private buildPhraseMap;
142
+ /**
143
+ * Get statistics about the inference system
144
+ */
145
+ getStats(): {
146
+ keywordCount: number;
147
+ phraseCount: number;
148
+ config: Required<TypeInferenceConfig>;
149
+ };
150
+ }
151
+ /**
152
+ * Get or create the global TypeInferenceSystem instance
153
+ */
154
+ export declare function getTypeInferenceSystem(config?: TypeInferenceConfig): TypeInferenceSystem;
155
+ /**
156
+ * Convenience function to infer types from a query
157
+ */
158
+ export declare function inferTypes(query: string, config?: TypeInferenceConfig): TypeInference[];