fix: getNouns().totalCount reports true total, not page size; quiet benign mmap-vector log

getNounsWithPagination returned collectedNouns.length as totalCount, but the
type-first shard scan early-terminates at offset+limit — so
getNouns({ pagination: { limit: 1 } }).totalCount was 1 for any non-empty brain.
The index-rebuild gate calls exactly that, so cold starts logged
"Small dataset (1 items) - rebuilding all indexes" and rebuilt from scratch
regardless of corpus size (a production deployment saw this for an ~8,800-entity
brain). Now reports the authoritative O(1) noun counter (maintained on add/delete,
rehydrated from counts.json on init) as the unfiltered total and derives hasMore
from it. Filtered scans unchanged. Layout-independent (branch/COW included).

Also downgrade the "mmap-vector backend not wired" console.log to prodLog.debug:
it is benign in the native-vector-index model (the native provider owns its own
vector storage and has no setVectorBackend hook), but it fired on every init and
was repeatedly mistaken for the cold-start cause.

Regression: tests/unit/storage/getNouns-totalCount.test.ts. Full unit suite green (1505).
This commit is contained in:
David Snelling 2026-06-17 14:01:33 -07:00
parent adec0ba3c3
commit edff637bfa
4 changed files with 156 additions and 8 deletions

View file

@ -9473,12 +9473,17 @@ export class Brainy<T = any> implements BrainyInterface<T> {
setVectorBackend?: (backend: MmapVectorBackend) => void
}
if (typeof indexWithBackend.setVectorBackend !== 'function') {
if (!this.config.silent) {
console.log(
'[brainy] mmap-vector backend not wired (vector index manages its own ' +
'vector storage; no setVectorBackend hook) — per-entity reads in use'
)
}
// Expected in the native-vector-index model: a native provider (e.g.
// @soulcraft/cortex) replaces the JS HNSW index and owns its own vector
// storage + persisted snapshot, so there is no setVectorBackend hook to
// wire here. This is benign, not a fault, and does NOT by itself imply
// per-entity reads — keep it at debug level so it never reads as a problem
// in normal operation. (The old console.log fired on every init and was
// repeatedly mistaken for the cold-start cause; see BRAINY-MMAP-VECTOR-HOOK.)
prodLog.debug(
'[brainy] mmap-vector backend not wired (native vector index manages ' +
'its own vector storage; no setVectorBackend hook)'
)
return
}