feat(8.0): GraphAccelerationProvider contract — the native graph-engine seam

Defines the optional native graph-acceleration provider (cor 3.0) that
brainy feature-detects and routes brain.graph.* / related({node}) /
find({connected}) to, falling back to pure-TS adjacency when absent. This is
the published seam cor wires its native build against (mirrors the existing
VersionedIndexProvider pattern: defined in plugin.ts, exported from index.ts,
implemented externally, feature-detected at runtime).

Contract (locked cross-team in the design thread):
- GraphAccelerationProvider: traverse, edgesForNode, graphCursorOpen/Next/Close,
  pageRank, connectedComponents, shortestPath, neighborhoodSample, topByDegree.
  Every read op is generation-aware (optional trailing generation?: bigint) so
  db.asOf(g).graph.* resolves historically; omitted = now.
- Subgraph: columnar wire format (BigInt64Array node/edge columns, Uint16Array
  edgeTypes, optional Uint8Array nodeDepth, truncated flag) — parallel typed
  arrays, never array-of-objects; brainy maps u64<->UUID lazily for rendered rows.
- OpaqueIdSet: a find() universe forwarded opaquely into traverse/search for the
  zero-crossing query->expand fusion (brainy never inspects it; the provider
  version-tags + validates the envelope).
- VectorIndexProvider.search gains allowedIds?: OpaqueIdSet | ReadonlySet<string>
  (predicate pushdown — recovers filtered recall lost to post-filtering).
- EntityIdMapperProvider gains entityIntsToUuids(BigInt64Array) — the bigint batch
  reverse resolver for Subgraph.nodes; implemented on the JS mapper (TS fallback).

All new public types exported from index.ts. Test: entityIntsToUuids round-trip
+ order-preservation + empty-int sentinel.
This commit is contained in:
David Snelling 2026-06-21 08:12:22 -07:00
parent 682e786cc3
commit a3d6fdb8b3
4 changed files with 391 additions and 1 deletions

View file

@ -291,6 +291,27 @@ export class EntityIdMapper implements EntityIdMapperProvider {
return result
}
/**
* @description Batch reverse-resolve u64 entity ints (a `BigInt64Array`) UUID
* strings the bigint counterpart of {@link EntityIdMapper.intsIterableToUuids},
* for the native graph engine whose `Subgraph.nodes` is a `BigInt64Array`. The JS
* mapper is keyed by `number` (u32-era); each int is narrowed via `Number()` safe
* for the JS fallback's id range. Order-preserving (one entry per input): an int the
* mapper has not assigned yields `''` (does not occur for graph-engine results, which
* reference assigned ints only).
* @param nodeInts - Entity ints as returned in a graph `Subgraph`.
* @returns One UUID per input, in order (`''` for a never-assigned int).
* @example
* const uuids = mapper.entityIntsToUuids(subgraph.nodes)
*/
entityIntsToUuids(nodeInts: BigInt64Array): string[] {
const result: string[] = new Array(nodeInts.length)
for (let i = 0; i < nodeInts.length; i++) {
result[i] = this.intToUuid.get(Number(nodeInts[i])) ?? ''
}
return result
}
/**
* Flush mappings to storage
*/