feat(8.0): API simplification — remove neural()/Db.search, one storage path key, integration→0

8.0 RC cleanup toward "one place per thing, zero-config, no deprecation":

- Remove the `brain.neural()` clustering namespace (ImprovedNeuralAPI + the dead
  legacy NeuralAPI + the neural CLI + neural-only types). Similarity is `find({vector})`
  / `similar({to})`; attribute grouping is the aggregation `GROUP BY` engine. The separate
  entity-extraction / smart-import feature (NeuralImport, NeuralEntityExtractor, SmartExtractor,
  NaturalLanguageProcessor, `brain.extract()`/`brain.nlp()`) is kept.
- Remove `Db.search()`; `find()` is the one query verb (accepts a bare string or FindParams).
  Fix the bundled MCP client, which called a non-existent `brain.search(query, limit)` →
  now `find({ query, limit })`.
- Storage config: collapse to one canonical top-level `path` key. The pre-8.0 aliases
  (`rootDirectory`, `options.*`, `fileSystemStorage.*`) are removed and now THROW with the
  exact rename instead of silently defaulting to `./brainy-data` on upgrade. A single resolver
  feeds createStorage, the 7.x→8.0 migration probe, and the plugin-factory handoff, so a native
  storage provider resolves the identical root (no split-brain).
- Fix `similar({ threshold })`: the min-similarity filter was silently dropped; it is now
  applied as a post-filter on `result.score` (the documented way to bound semantic results).
- Fix `vfs.rename()` on a directory: child path updates spread the entity vector into `update()`
  and failed dimension validation; they are metadata-only updates now.
- Fix `vfs.move()`: copy+delete orphaned the content-addressed content blob (the destination
  shared the source hash, then unlink removed it). `move()` now delegates to `rename()` — an
  in-place path change that preserves the blob and the entity id, for files and directories.
- Fix streaming import: the bulk fast path never flushed mid-import nor signalled queryability.
  Entity writes are now chunked by a progressive flush interval (100 → 1000 → 5000); each chunk
  flushes and emits `progress.queryable`, so imported data is queryable during the import.
- Sweep all docs, comments, and JSDoc for the removed/changed APIs.

Integration suite: 49 files / 588 passed / 0 failed. Unit: 80 files / 1456 passed, no type errors.
This commit is contained in:
David Snelling 2026-06-20 13:31:11 -07:00
parent 0c4a51c24e
commit 606445cd61
74 changed files with 712 additions and 7470 deletions

View file

@ -6,7 +6,6 @@
* - brain.import() (CSV/Excel/PDF with VFS)
* - brain.clear()
* - vfs file operations (unlink, rmdir, rename, copy, move)
* - neural.clusters()
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
@ -28,7 +27,7 @@ describe('Remaining APIs Comprehensive Test', () => {
brain = new Brainy({ requireSubtype: false,
storage: {
type: 'filesystem',
options: { path: testDir }
path: testDir
}
})
await brain.init()
@ -313,82 +312,6 @@ Gadget,20`
})
})
describe('neural.clusters()', () => {
it('should cluster entities semantically', async () => {
console.log('\n📋 Test: neural.clusters()')
// Create diverse entities for clustering
await brain.addMany({
items: [
{ data: 'JavaScript programming tutorial', type: NounType.Document },
{ data: 'Python coding guide', type: NounType.Document },
{ data: 'TypeScript development', type: NounType.Document },
{ data: 'Cooking pasta recipe', type: NounType.Document },
{ data: 'Baking bread instructions', type: NounType.Document },
{ data: 'Making pizza at home', type: NounType.Document }
]
})
const neural = brain.neural()
const clusters = await neural.clusters({
maxClusters: 3,
minClusterSize: 1
})
console.log(` Found ${clusters.length} clusters`)
for (const cluster of clusters) {
console.log(` Cluster: ${cluster.label || cluster.id} (${cluster.members.length} members)`)
}
expect(clusters.length).toBeGreaterThan(0)
expect(clusters.every(c => c.members.length > 0)).toBe(true)
expect(clusters.every(c => typeof c.id === 'string')).toBe(true)
console.log(` ✅ neural.clusters() created semantic clusters`)
})
it('should cluster over the full corpus (VFS entities included by default)', async () => {
console.log('\n📋 Test: neural.clusters() includes VFS entities by default')
// Create VFS files. In 8.0 these are normal graph entities marked
// metadata.isVFS — only the VFS *root* carries visibility:'system'.
const vfs = brain.vfs
await vfs.writeFile('/cluster-test1.txt', 'VFS file content')
await vfs.writeFile('/cluster-test2.txt', 'Another VFS file')
const neural = brain.neural()
// clusters() has no VFS-exclusion knob (ClusteringOptions has none) and
// its corpus comes from find(), whose excludeVFS defaults to false
// (VFS included). So VFS files are part of the clusterable corpus.
const clusters = await neural.clusters({
maxClusters: 5
})
expect(clusters.length).toBeGreaterThan(0)
// Confirm clustering does not silently drop VFS entities: at least one of
// the VFS files we just wrote appears as a cluster member. (Metadata-only
// get is enough — we only read metadata.isVFS, not the vector.)
let vfsCount = 0
for (const cluster of clusters) {
for (const memberId of cluster.members) {
const entity = await brain.get(memberId)
if (entity?.metadata?.isVFS === true) {
vfsCount++
}
}
}
console.log(` Clusters: ${clusters.length}, VFS members: ${vfsCount}`)
// 8.0 contract: VFS entities are included in clustering by default.
expect(vfsCount).toBeGreaterThan(0)
console.log(` ✅ neural.clusters() clusters the full corpus including VFS`)
})
})
describe('Production Quality Verification', () => {
it('should handle large batch updates efficiently', async () => {
console.log('\n📋 Test: Large batch updateMany()')