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:
parent
46fc7f2c4a
commit
4b6f63ed67
6 changed files with 227 additions and 7 deletions
|
|
@ -17,6 +17,7 @@ import {
|
|||
type MemoryInfo,
|
||||
type CacheAllocationStrategy
|
||||
} from './memoryDetection.js'
|
||||
import type { CacheProvider } from '../plugin.js'
|
||||
|
||||
export interface CacheItem {
|
||||
key: string
|
||||
|
|
@ -57,7 +58,14 @@ export interface UnifiedCacheConfig {
|
|||
memoryCheckInterval?: number
|
||||
}
|
||||
|
||||
export class UnifiedCache {
|
||||
/**
|
||||
* Single cost-aware cache for HNSW and MetadataIndex.
|
||||
*
|
||||
* Implements {@link CacheProvider}: the surface Brainy calls on whatever cache
|
||||
* is installed as the global cache (its own instance, or a registered
|
||||
* `'cache'` provider such as Cortex's native eviction engine).
|
||||
*/
|
||||
export class UnifiedCache implements CacheProvider {
|
||||
private cache = new Map<string, CacheItem>()
|
||||
private access = new Map<string, number>() // Access counts
|
||||
private loadingPromises = new Map<string, Promise<any>>()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue