brainy/tests/manual/metadata-index-debug.test.ts
David Snelling 014b8104da feat: brain.find() excludes VFS by default (Option 3C)
Added includeVFS parameter to FindParams:
- brain.find() excludes VFS entities by default (clean knowledge graph)
- Opt-in with brain.find({ includeVFS: true })
- Automatically excludes VFS in all query paths (empty, metadata, vector)
- Respects explicit where: { isVFS: ... } queries

Implementation:
- Empty query path: Apply VFS filtering even with no criteria
- Metadata query path: Filter out isVFS: true by default
- Vector search path: Apply VFS filter after search
- Skip auto-exclusion if where clause explicitly queries isVFS

Architecture (Option 3C):
- VFS entities are first-class graph entities
- Marked with isVFS: true flag
- Separated via filtering, not storage
- Enables VFS-knowledge relationships

Moved internal docs to .strategy/:
- README_STORAGE_EXPLORATION.md
- EXPLORATION_SUMMARY.md
- STORAGE_FILES_REFERENCE.md
- STORAGE_ADAPTER_QUICK_REFERENCE.md
- SECURITY.md
2025-10-24 11:42:47 -07:00

86 lines
2.4 KiB
TypeScript

/**
* Debug: Check metadata index for isVFS field
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { Brainy } from '../../src/brainy.js'
import { NounType } from '../../src/types/graphTypes.js'
import * as fs from 'fs'
import * as path from 'path'
describe('Metadata Index Debug', () => {
const testDir = path.join(process.cwd(), 'test-metadata-index-debug')
let brain: Brainy
beforeAll(async () => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true })
}
fs.mkdirSync(testDir, { recursive: true })
brain = new Brainy({
storage: {
type: 'filesystem',
options: { path: testDir }
}
})
await brain.init()
})
afterAll(() => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true })
}
})
it('should index custom metadata fields', async () => {
// Add entity with custom metadata field
const entity1 = await brain.add({
data: 'Test entity with custom field',
type: NounType.Document,
metadata: {
customFlag: true,
customString: 'hello',
customNumber: 42
}
})
console.log('\n📋 Added entity:', entity1.id)
console.log(' Metadata:', entity1.metadata)
// Try to find by custom fields
console.log('\n📋 Query 1: where: { customFlag: true }')
const result1 = await brain.find({
where: { customFlag: true },
limit: 10
})
console.log(` Results: ${result1.length}`)
if (result1.length > 0) {
console.log(` Found: ${result1[0].id}`)
console.log(` Metadata.customFlag: ${result1[0].metadata?.customFlag}`)
}
console.log('\n📋 Query 2: where: { customString: "hello" }')
const result2 = await brain.find({
where: { customString: 'hello' },
limit: 10
})
console.log(` Results: ${result2.length}`)
console.log('\n📋 Query 3: where: { customNumber: 42 }')
const result3 = await brain.find({
where: { customNumber: 42 },
limit: 10
})
console.log(` Results: ${result3.length}`)
// Check what fields are indexed
console.log('\n📋 Indexed fields:')
const fields = await brain.getFilterFields()
console.log(` ${fields.join(', ')}`)
expect(result1.length).toBeGreaterThan(0)
expect(result2.length).toBeGreaterThan(0)
expect(result3.length).toBeGreaterThan(0)
})
})