/** * HNSW Embedding Store Helper Functions * @module @skillsmith/core/embeddings/hnsw-store.helpers */ import type { HierarchicalNSWConstructor, HNSWEmbeddingStoreOptions } from './hnsw-store.types.js'; import { HNSW_PRESETS } from './hnsw-store.types.js'; import { HNSWEmbeddingStore } from './hnsw-store.js'; /** * Create an HNSWEmbeddingStore with a preset configuration. * * @param preset - Preset name ('small', 'medium', 'large', 'xlarge') * @param options - Additional options (merged with preset); dbPath is opened async * @returns Promise resolving to a configured HNSWEmbeddingStore instance * * @example * ```typescript * const store = await createHNSWStore('large', { * dbPath: './embeddings.db', * indexPath: './embeddings.hnsw', * }); * ``` */ export declare function createHNSWStore(preset: keyof typeof HNSW_PRESETS, options?: Omit): Promise; /** * Check if hnswlib-node is available. * Useful for conditional logic or graceful degradation. * * @returns true if hnswlib-node can be loaded */ export declare function isHNSWAvailable(): Promise; /** * Dynamically load hnswlib-node module. * * @returns The HierarchicalNSW constructor, or null if unavailable * @internal */ export declare function loadHNSWLib(): Promise<{ HierarchicalNSW: HierarchicalNSWConstructor; } | null>; /** * Compute cosine similarity between two embeddings. * Standalone version for use outside of HNSWEmbeddingStore. * * @param a - First embedding * @param b - Second embedding * @returns Similarity score between -1 and 1 */ export declare function computeCosineSimilarity(a: Float32Array, b: Float32Array): number; /** * Convert HNSW distance to similarity score. * HNSW returns distances, we need similarities (higher = more similar). * * @param distance - Distance value from HNSW * @param metric - Distance metric used * @returns Similarity score */ export declare function distanceToSimilarity(distance: number, metric?: 'cosine' | 'l2' | 'ip'): number; /** * Estimate memory usage for an HNSW index. * * @param vectorCount - Number of vectors * @param dimensions - Vector dimensionality * @param m - HNSW M parameter * @returns Estimated memory usage in bytes */ export declare function estimateMemoryUsage(vectorCount: number, dimensions: number, m: number): number; /** * Validate embedding dimensions. * * @param embedding - Embedding to validate * @param expectedDimensions - Expected dimension count * @param context - Context for error message (default: 'Query') * @throws Error if dimensions don't match */ export declare function validateDimensions(embedding: Float32Array, expectedDimensions: number, context?: string): void; /** * Determine whether to use HNSW based on explicit option or environment. * * @param explicit - Explicit useHNSW option (if provided) * @returns Whether to enable HNSW */ export declare function shouldUseHNSW(explicit?: boolean): boolean; //# sourceMappingURL=hnsw-store.helpers.d.ts.map