UNPKG

@claude-flow/embeddings

Version:

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

92 lines • 3.77 kB
/** * RVF Embedding Service - Lightweight Hash-Based Embeddings * * Provides deterministic, sub-millisecond embedding generation using * FNV-1a hash-based vectors. No neural model or external API required. * * Features: * - Deterministic: same input always produces the same embedding * - FNV-1a hash seeding with multi-round mixing * - L2-normalized output vectors * - Sub-millisecond generation (<0.1ms typical) * - RvfEmbeddingCache for binary file persistence * - Zero external dependencies * * Use cases: * - Fast similarity search where relative distances matter more than semantics * - Development and testing without API keys * - Offline environments without neural model access * - Bootstrapping before heavier providers are available * * @module @claude-flow/embeddings */ import { EventEmitter } from 'events'; import type { EmbeddingProvider, EmbeddingResult, BatchEmbeddingResult, IEmbeddingService, EmbeddingEventListener, RvfEmbeddingConfig } from './types.js'; /** * Lightweight hash-based embedding service. * * Generates deterministic embeddings from text using FNV-1a hashing * with multi-round mixing and L2 normalization. The output is a unit * vector in R^n where n = configured dimensions (default 384). * * Extends EventEmitter and implements IEmbeddingService for drop-in * compatibility with other providers. * * ⚠️ **Naming clarification (ADR-121 Phase 4):** the "Rvf" in the * class name is historical and predates the existence of * [`@ruvector/rvf`](https://www.npmjs.com/package/@ruvector/rvf) (the * upstream "RuVector Format" — a real vector database SDK with * persistent file storage + ANN query). This class is *not* a wrapper * around `@ruvector/rvf`; it's a pure-TS deterministic hash that * happens to share a name prefix. If you want real RVF cognitive * containers (file-based vector DB, batch ingest, ANN query), import * `RvfDatabase` from `@ruvector/rvf` directly. If you want fast, * deterministic, model-free text→vector for tests / scratch / * sub-millisecond paths, this class is the right tool. Naming may * be revisited in a future major. */ export declare class RvfEmbeddingService extends EventEmitter implements IEmbeddingService { readonly provider: EmbeddingProvider; private readonly dimensions; private readonly cache; private readonly normalizationType; private readonly embeddingListeners; private persistentCache; constructor(config: RvfEmbeddingConfig); /** * Generate an embedding for a single text string. */ embed(text: string): Promise<EmbeddingResult>; /** * Generate embeddings for multiple text strings. */ embedBatch(texts: string[]): Promise<BatchEmbeddingResult>; clearCache(): void; getCacheStats(): { size: number; maxSize: number; hitRate: number; }; shutdown(): Promise<void>; addEventListener(listener: EmbeddingEventListener): void; removeEventListener(listener: EmbeddingEventListener): void; private emitEvent; /** * Generate a deterministic embedding from text using FNV-1a hashing. * * Algorithm: * 1. Compute a base FNV-1a hash of the full text. * 2. For each dimension, derive a unique seed by mixing the base hash * with the dimension index using the golden ratio constant. * 3. Apply a sine-based pseudo-random transform to spread values. * 4. L2-normalize the result to produce a unit vector. * * This is deterministic: the same text always yields the same vector. */ private generateHashEmbedding; /** * Apply user-configured normalization if set. */ private applyNormalization; } //# sourceMappingURL=rvf-embedding-service.d.ts.map