UNPKG

@claude-flow/embeddings

Version:

V3 Embedding Service - OpenAI, Transformers.js, Agentic-Flow (ONNX), Mock providers with hyperbolic embeddings, normalization, and chunking

66 lines • 2.91 kB
/** * Base classes for the embedding-service module — extracted from * embedding-service.ts so sibling provider files (e.g. * ruvector-onnx-embedding-service.ts, future plugin providers) can * extend the base without causing a circular-import TDZ. * * The split happened during ADR-121 Phase 1. Before the split, every * concrete provider lived in embedding-service.ts; introducing a new * provider in a separate file that also imported `BaseEmbeddingService` * from embedding-service.ts created a cycle that crashed at module * load with "Class extends undefined". * * This file has no concrete provider classes — only the abstract base * + the LRU cache it uses. That keeps the dependency graph from any * provider back to base, and never the reverse. */ import { EventEmitter } from 'events'; import type { EmbeddingProvider, EmbeddingConfig, EmbeddingResult, BatchEmbeddingResult, IEmbeddingService, EmbeddingEvent, EmbeddingEventListener, NormalizationType } from './types.js'; import { PersistentEmbeddingCache } from './persistent-cache.js'; export declare class LRUCache<K, V> { private readonly maxSize; private cache; private hits; private misses; constructor(maxSize: number); get(key: K): V | undefined; set(key: K, value: V): void; clear(): void; get size(): number; get hitRate(): number; getStats(): { size: number; maxSize: number; hits: number; misses: number; hitRate: number; }; } export declare abstract class BaseEmbeddingService extends EventEmitter implements IEmbeddingService { protected readonly config: EmbeddingConfig; abstract readonly provider: EmbeddingProvider; protected cache: LRUCache<string, Float32Array>; protected persistentCache: PersistentEmbeddingCache | null; protected embeddingListeners: Set<EmbeddingEventListener>; protected normalizationType: NormalizationType; constructor(config: EmbeddingConfig); abstract embed(text: string): Promise<EmbeddingResult>; abstract embedBatch(texts: string[]): Promise<BatchEmbeddingResult>; /** Apply normalization to embedding if configured. */ protected applyNormalization(embedding: Float32Array): Float32Array; /** Check persistent cache for embedding. */ protected checkPersistentCache(text: string): Promise<Float32Array | null>; /** Store embedding in persistent cache. */ protected storePersistentCache(text: string, embedding: Float32Array): Promise<void>; protected emitEvent(event: EmbeddingEvent): void; addEventListener(listener: EmbeddingEventListener): void; removeEventListener(listener: EmbeddingEventListener): void; clearCache(): void; getCacheStats(): { size: number; maxSize: number; hitRate: number; }; shutdown(): Promise<void>; } //# sourceMappingURL=embedding-service-base.d.ts.map