brainy/docs/guides
David Snelling 2cdf70ee0f feat: subtype top-level field + trackField + migrateField
Promotes `subtype?: string` to a top-level standard field on every entity,
alongside `type` / `confidence` / `weight`. Flat string, no hierarchy — the
consumer-chosen vocabulary for sub-classifying entities within a NounType
(Person → employee/customer, Document → invoice/contract, etc.).

Layer 1 — subtype field + rollup
- HNSWNounWithMetadata.subtype + STANDARD_ENTITY_FIELDS entry
- Entity / Result / AddParams / UpdateParams / FindParams threading
- add()/update() persist subtype on storageMetadata + entityForIndexing
- get()/find() route through the standard-field fast path
- subtypeCountsByType (Map<NounTypeIdx, Map<subtype, count>>) on
  BaseStorage, mirrored after nounCountsByType with the same self-heal
  rebuild and persisted to _system/subtype-statistics.json
- brain.counts.bySubtype(type, subtype?) — O(1) point + breakdown
- brain.counts.topSubtypes(type, n) — top-N by count
- brain.subtypesOf(type) — distinct subtypes seen
- find({ type, subtype }) and find({ subtype: ['a','b'] }) on the fast path

Layer 2 — trackField for other facets
- brain.trackField(name, { perType?, values? }) registers a field for
  cardinality + per-NounType breakdown stats. Backed by the aggregation
  engine (auto-defines __fieldCounts__<name>), backfill-on-define applies.
- brain.counts.byField(name, { type? }) returns value frequencies
- Optional vocabulary whitelist rejects off-vocabulary writes at add/update

Layer 3 — generic migrateField
- brain.migrateField({ from, to, readBoth?, batchSize?, onProgress? })
  streams every entity, copies the value from one path to another, and
  (unless readBoth) clears the source. Supports top-level standard fields,
  metadata.X, and data.X paths. Idempotent — safe to re-run.

Docs
- New guide: docs/guides/subtypes-and-facets.md (Layer 1 + 2 + 3)
- README, DATA_MODEL, QUERY_OPERATORS, api/README, finite-type-system,
  quick-start all treat subtype as a core primitive with anonymous example
  vocabularies (employee/customer/invoice/milestone).

Tests
- 26 new integration tests covering write/read/update/delete round-trips,
  counts rollup decrement + re-route on mutation, trackField + byField
  with and without perType, vocabulary whitelist enforcement, and
  migrateField for metadata.X → subtype and data.X → subtype paths
  including readBoth deprecation-window semantics.

Unit suite: 1468/1468 passing. Type-check + build clean.
2026-06-04 17:25:28 -07:00
..
aggregation.md feat: array-unnest groupBy for aggregates + batch-embed entity extraction 2026-05-26 14:20:40 -07:00
distributed-system.md docs: update documentation for accurate v3.9.0 API examples and technical claims 2025-09-22 16:19:27 -07:00
enterprise-for-everyone.md feat: v5.1.0 - VFS auto-initialization and complete API documentation 2025-11-02 10:58:52 -08:00
framework-integration.md feat: enhance framework integration and simplify codebase 2025-09-15 14:54:13 -07:00
import-anything.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
import-flow.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
import-progress-examples.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
import-progress-implementation.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
import-quick-reference.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
inspection.md feat: multi-process safety + read-only inspector mode 2026-05-15 11:25:05 -07:00
installation.md docs: convert code examples to TypeScript 2026-02-19 17:46:18 -08:00
migrating-to-v4.md feat: add import API validation and v4.x migration guide 2025-10-21 15:25:12 -07:00
MIGRATING_TO_V5.11.md feat: enforce data/metadata separation, numeric range queries, improved docs 2026-02-09 12:07:54 -08:00
migration-3.36.0.md feat: implement always-adaptive caching with getCacheStats monitoring 2025-10-10 14:09:30 -07:00
model-loading.md feat: migrate embeddings to Candle WASM + remove semantic type inference 2026-01-06 12:52:34 -08:00
natural-language.md feat: v5.1.0 - VFS auto-initialization and complete API documentation 2025-11-02 10:58:52 -08:00
neural-api.md fix(vfs): prevent race condition in bulkWrite by ordering operations 2025-12-11 13:26:07 -08:00
nextjs-integration.md feat: enhance framework integration and simplify codebase 2025-09-15 14:54:13 -07:00
quick-start.md feat: subtype top-level field + trackField + migrateField 2026-06-04 17:25:28 -07:00
schema-migrations.md feat: add migration system with error handling, validation, and enterprise hardening 2026-02-09 16:13:14 -08:00
standard-import-progress.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
storage-adapters.md docs: add public frontmatter to docs for soulcraft.com/docs pipeline 2026-02-19 17:04:05 -08:00
streaming-imports.md fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
subtypes-and-facets.md feat: subtype top-level field + trackField + migrateField 2026-06-04 17:25:28 -07:00
vue-integration.md feat: enhance framework integration and simplify codebase 2025-09-15 14:54:13 -07:00