feat: export provider contracts for the plugin surface brainy consumes

Native accelerators (cortex) register providers for metadataIndex, graphIndex,
hnsw, entityIdMapper, cache, columnStore, and aggregation. Until now the exact
method/property surface brainy calls on each was implicit — a provider could
drop a member brainy depends on and only fail at runtime when that path ran.

This defines and exports the provider contracts from the stable
@soulcraft/brainy/plugin entrypoint:
- MetadataIndexProvider, GraphIndexProvider, HnswProvider,
  EntityIdMapperProvider, CacheProvider — each typed as exactly the surface
  brainy calls (optional/feature-detected members like HNSW setPersistMode and
  enableCOW are intentionally excluded).
- Re-exports ColumnStoreProvider and AggregationProvider (and the aggregate
  types) from the same entrypoint so a plugin author can import the whole
  provider surface from one place.

Brainy's own baseline classes now `implements` these contracts
(MetadataIndexManager, GraphAdjacencyIndex, HNSWIndex, EntityIdMapper,
UnifiedCache), so the interfaces can never silently diverge from what brainy
ships — and any provider that declares `implements` gets a compile error the
moment brainy starts requiring a new member.

The embeddings/embedBatch providers stay typed by the existing EmbeddingFunction
(no duplicate interface added). Type-only changes; no runtime behavior change.
This commit is contained in:
David Snelling 2026-05-27 14:45:40 -07:00
parent 46fc7f2c4a
commit 4b6f63ed67
6 changed files with 227 additions and 7 deletions

View file

@ -12,6 +12,7 @@ import { GraphVerb, StorageAdapter } from '../coreTypes.js'
import { UnifiedCache, getGlobalCache } from '../utils/unifiedCache.js'
import { prodLog } from '../utils/logger.js'
import { LSMTree } from './lsm/LSMTree.js'
import type { GraphIndexProvider } from '../plugin.js'
export interface GraphIndexConfig {
maxIndexSize?: number // Default: 100000
@ -36,7 +37,7 @@ export interface GraphIndexStats {
* Memory efficient: 385x less memory (1.3GB vs 500GB for 1B relationships)
* Performance: Sub-5ms neighbor lookups with bloom filter optimization
*/
export class GraphAdjacencyIndex {
export class GraphAdjacencyIndex implements GraphIndexProvider {
// LSM-tree storage for outgoing and incoming edges
private lsmTreeSource: LSMTree // sourceId -> targetIds (outgoing edges)
private lsmTreeTarget: LSMTree // targetId -> sourceIds (incoming edges)