brainy/examples/tests/test-metadata-filter.js
David Snelling 8ff382ca3b chore: recovery checkpoint - v3.0 API successfully recovered
CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB

Recovery Status:
- Successfully recovered brainy.ts from compiled JavaScript
- All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.)
- Neural subsystem intact (562KB embedded patterns, NLP working)
- Augmentation pipeline operational (20+ augmentations)
- HNSW clustering system complete
- Triple Intelligence compiled (needs constructor fix)
- Test suite validates functionality

Changes preserved:
- 898 files with changes from last 3 days
- 144,475 insertions
- All augmentation improvements
- All test coverage enhancements
- Complete v3.0 feature set

This is a LOCAL checkpoint only - contains recovered work after corruption incident.
Created backup in .backups/brainy-full-20250910-151314.tar.gz

Branch: recovery-checkpoint-20250910-151433
Date: Wed Sep 10 03:18:04 PM PDT 2025
2025-09-10 15:18:04 -07:00

51 lines
No EOL
1.6 KiB
JavaScript

#!/usr/bin/env node
import { BrainyData } from './dist/index.js'
const brain = new BrainyData({
storage: { type: 'memory' },
verbose: false
})
await brain.init()
// Add test data like the unit test
const items = [
{ data: 'Flask framework', metadata: { name: 'Flask', type: 'framework', language: 'Python', year: 2010 }},
{ data: 'Django framework', metadata: { name: 'Django', type: 'framework', language: 'Python', year: 2005 }},
{ data: 'Express framework', metadata: { name: 'Express', type: 'framework', language: 'JavaScript', year: 2010 }},
{ data: 'FastAPI framework', metadata: { name: 'FastAPI', type: 'framework', language: 'Python', year: 2018 }}
]
console.log('Adding 4 items...')
for (const item of items) {
await brain.addNoun(item.data, item.metadata)
}
console.log('\nTest 1: Search with wildcard, no filter')
const all = await brain.search('*', 10)
console.log(` Found ${all.length} items`)
console.log('\nTest 2: Search with wildcard + metadata filter')
const pythonFrameworks = await brain.search('*', 10, {
metadata: {
type: 'framework',
language: 'Python'
}
})
console.log(` Found ${pythonFrameworks.length} items (expected 3)`)
pythonFrameworks.forEach(item => {
console.log(` - ${item.metadata?.name}: type=${item.metadata?.type}, language=${item.metadata?.language}`)
})
console.log('\nTest 3: Direct metadata index check')
const metadataIndex = brain.metadataIndex
if (metadataIndex) {
const ids = await metadataIndex.getIdsForFilter({
type: 'framework',
language: 'Python'
})
console.log(` MetadataIndex found ${ids.length} matching IDs`)
}
process.exit(0)