@claude-flow/embeddings
Version:
V3 Embedding Service - OpenAI, Transformers.js, Agentic-Flow (ONNX), Mock providers with hyperbolic embeddings, normalization, and chunking
59 lines • 2.78 kB
TypeScript
/**
* RuvectorOnnxEmbeddingService — ADR-121 Phase 1.
*
* Drop-in replacement for the legacy `TransformersEmbeddingService` that
* uses `ruvector-onnx-embeddings-wasm` instead of the retired
* `@xenova/transformers@2.x`. Matches the existing IEmbeddingService
* contract so consumers don't migrate: opt in via
* `provider: 'ruvector-onnx'` on `createEmbeddingService`.
*
* Why this exists:
* - `@xenova/transformers` was renamed upstream to
* `@huggingface/transformers@4.x` and the v2 line is unmaintained.
* Carrying it in the runtime tree of every embedding install is a
* growing liability.
* - `ruvector-onnx-embeddings-wasm` is pure WASM with SIMD + parallel
* workers, smaller install footprint (no native bindings, no
* Python-style model-conversion tooling shipped), and runs
* identically in Node, browsers, Workers, and Deno.
* - Same model catalog (all-MiniLM-L6-v2, BGE, E5, GTE) so output
* parity with the Xenova path is achievable to >0.999 cosine
* correlation on a fixed test corpus — that's the Phase 1
* acceptance gate.
*
* Optional peer dep: when `ruvector-onnx-embeddings-wasm` isn't
* installed, construction throws a clear error naming the dep and the
* single install command. Callers that don't opt into `ruvector-onnx`
* are unaffected.
*/
import type { EmbeddingProvider, RuvectorOnnxEmbeddingConfig, EmbeddingResult, BatchEmbeddingResult } from './types.js';
import { BaseEmbeddingService } from './embedding-service-base.js';
export declare class RuvectorOnnxEmbeddingService extends BaseEmbeddingService {
readonly provider: EmbeddingProvider;
private embedder;
private readonly modelName;
private readonly normalizeOutput;
private dimensionCache;
constructor(config: RuvectorOnnxEmbeddingConfig);
private initialize;
embed(text: string): Promise<EmbeddingResult>;
embedBatch(texts: string[]): Promise<BatchEmbeddingResult>;
/**
* L2-normalize a Float32Array view into a freshly-allocated
* Float32Array. The WASM embedder can normalize internally via
* WasmEmbedderConfig, but we do it here so the cached vector is
* always normalized regardless of model defaults — keeps similarity
* scoring predictable across providers.
*/
private l2NormalizeView;
/**
* Release the WASM embedder. Idempotent; safe to call multiple times.
*/
close(): Promise<void>;
}
/**
* Factory helper — mirrors the createEmbeddingService convention so
* callers can opt in without instantiating directly.
*/
export declare function createRuvectorOnnxEmbeddingService(config?: Omit<RuvectorOnnxEmbeddingConfig, 'provider'>): RuvectorOnnxEmbeddingService;
//# sourceMappingURL=ruvector-onnx-embedding-service.d.ts.map