brainy/tests/unit
David Snelling 46fc7f2c4a feat: hook native sort:topK provider into search result ranking
Adds a swappable sort:topK seam for the find() result-ranking hot path. Brainy
ranks candidate results by relevance score then slices to offset+limit; for large
candidate sets that is an O(N log N) full sort even though only the page is kept.

New utils/resultRanking.ts exposes rankIndicesByScore (top-K index selection) with a
JS default (sortTopKIndicesJs) that is byte-identical in ordering to the previous
results.sort((a, b) => b.score - a.score) + slice: descending by score, stable ties
by original index (ES2019+ stable sort semantics). setSortTopKImplementation lets a
native provider (e.g. cortex's Rust partial-sort) replace it; the provider returns
indices into a scores array and only has to match the JS index ordering.

brainy.ts resolves the sort:topK provider in init() (same pattern as distance:sq8)
and wires both relevance-score sort sites in find() through rankIndicesByScore +
reorderByIndices. rankIndicesByScore validates a native provider's output (length,
range, no duplicates) and falls back to JS on any inconsistency, so a query never
returns wrong or duplicated results. No provider registered = unchanged JS behavior.

Tests: unit coverage of the dispatcher (JS ordering vs Array.sort across 200 random
trials incl. ties, provider routing, and fallback on bad/throwing providers) plus
find() integration proving ranking routes through a registered provider, that the
provider and JS fallback produce identical ids/scores on the same data, and that
pagination requests k = offset + limit with descending ordering.
2026-05-27 13:13:47 -07:00
..
aggregation feat: exact percentile and distinctCount aggregation ops 2026-05-26 16:18:47 -07:00
brainy fix: flush all native providers on shutdown to prevent data loss 2026-02-01 16:23:49 -08:00
graph feat: add v5.8.0 features - transactions, pagination, and comprehensive docs 2025-11-14 10:26:23 -08:00
hnsw feat: hook native SQ8 distance provider into HNSW reranking 2026-05-27 12:43:29 -07:00
import fix: flush all native providers on shutdown to prevent data loss 2026-02-01 16:23:49 -08:00
indexes/columnStore feat: unified column store for filtering + sorting at billion scale 2026-04-10 11:22:19 -07:00
neural fix: extraction, multi-hop traversal, and aggregate result shape (BR-ADV-FEATURES-BUN) 2026-05-26 11:32:46 -07:00
performance refactor: remove augmentation system and semantic type matching 2026-02-01 10:48:56 -08:00
storage feat(storage): add raw binary-blob primitive to every storage adapter 2026-05-27 11:50:04 -07:00
types fix: update tests for Stage 3 CANONICAL taxonomy (42 nouns, 127 verbs) 2025-11-11 10:09:01 -08:00
utils feat: hook native sort:topK provider into search result ranking 2026-05-27 13:13:47 -07:00
versioning fix(versioning): clean architecture with index pollution prevention 2025-12-09 09:36:10 -08:00
vfs feat: add ImageHandler with EXIF extraction and comprehensive MIME detection (v5.2.0) 2025-11-03 14:06:17 -08:00
brainy-core.unit.test.ts feat: enforce data/metadata separation, numeric range queries, improved docs 2026-02-09 12:07:54 -08:00
brainy-get-optimization.test.ts fix: flush all native providers on shutdown to prevent data loss 2026-02-01 16:23:49 -08:00
create-entities-default.test.ts fix: flush all native providers on shutdown to prevent data loss 2026-02-01 16:23:49 -08:00
fieldTypeInference.test.ts feat: production-ready value-based temporal field detection 2025-10-16 13:58:57 -07:00
plugin.test.ts refactor: remove augmentation system and semantic type matching 2026-02-01 10:48:56 -08:00
type-filtering.unit.test.ts fix: update tests for v5.1.0 API changes (VFS auto-init + property access) 2025-11-02 11:38:12 -08:00
vfs-restart-fix.test.ts fix: set verb.source/target to entity UUID instead of NounType 2026-02-02 09:20:38 -08:00
workshop-vfs-diagnostic.test.ts fix: update tests for v5.1.0 API changes (VFS auto-init + property access) 2025-11-02 11:38:12 -08:00