feat: implement semantic field matching and type-aware NLP
- Add metadata intelligence API to Brainy for field discovery - Implement semantic field matching using embeddings instead of hardcoded lists - Pre-embed all 30+ NounTypes and 40+ VerbTypes for type detection - Replace weak fallback with intelligent field-aware parsing - Add field cardinality tracking for query optimization - Enable dynamic field discovery from actual indexed metadata - Use cosine similarity for matching query terms to fields and types - Add query optimization hints based on field statistics This creates a truly intelligent NLP system that: - Discovers fields dynamically from the actual data - Uses semantic similarity to match "published" to "publishDate" - Leverages fixed NounTypes/VerbTypes as semantic vocabulary - Optimizes queries based on field cardinality and distribution - NO FALLBACKS - everything is based on real data and embeddings
This commit is contained in:
parent
23e0a5c24b
commit
b3c742dcea
2 changed files with 411 additions and 45 deletions
|
|
@ -895,6 +895,60 @@ export class Brainy<T = any> {
|
|||
return this._tripleIntelligence
|
||||
}
|
||||
|
||||
// ============= METADATA INTELLIGENCE API =============
|
||||
|
||||
/**
|
||||
* Get all indexed field names currently in the metadata index
|
||||
* Essential for dynamic query building and NLP field discovery
|
||||
*/
|
||||
async getAvailableFields(): Promise<string[]> {
|
||||
await this.ensureInitialized()
|
||||
return this.metadataIndex.getFilterFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get field statistics including cardinality and query patterns
|
||||
* Used for query optimization and understanding data distribution
|
||||
*/
|
||||
async getFieldStatistics(): Promise<Map<string, any>> {
|
||||
await this.ensureInitialized()
|
||||
return this.metadataIndex.getFieldStatistics()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fields sorted by cardinality for optimal filtering
|
||||
* Lower cardinality fields are better for initial filtering
|
||||
*/
|
||||
async getFieldsWithCardinality(): Promise<Array<{
|
||||
field: string
|
||||
cardinality: number
|
||||
distribution: string
|
||||
}>> {
|
||||
await this.ensureInitialized()
|
||||
return this.metadataIndex.getFieldsWithCardinality()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get optimal query plan for a given set of filters
|
||||
* Returns field processing order and estimated cost
|
||||
*/
|
||||
async getOptimalQueryPlan(filters: Record<string, any>): Promise<{
|
||||
strategy: 'exact' | 'range' | 'hybrid'
|
||||
fieldOrder: string[]
|
||||
estimatedCost: number
|
||||
}> {
|
||||
await this.ensureInitialized()
|
||||
return this.metadataIndex.getOptimalQueryPlan(filters)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filter values for a specific field (for UI dropdowns, etc)
|
||||
*/
|
||||
async getFieldValues(field: string): Promise<string[]> {
|
||||
await this.ensureInitialized()
|
||||
return this.metadataIndex.getFilterValues(field)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a streaming pipeline
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue