/** * Enhanced service for generating embeddings from text * * Features: * - Improved caching for frequent embeddings * - Enhanced error handling with automatic retries * - Support for text chunking and batching * - Fallback model support */ /** * Configuration for the enhanced embedding service */ export interface EmbeddingServiceConfig { model?: string; apiKey?: string; dimensions?: number; batchSize?: number; fallbackModel?: string; maxRetries?: number; retryDelayMs?: number; enableCache?: boolean; cacheSize?: number; chunkSize?: number; chunkOverlap?: number; } /** * Enhanced service that generates embeddings from text using OpenAI's API * with caching, batching, and retry logic */ export declare class EmbeddingService { private openai; private config; private logger; private cache; /** * Creates a new enhanced embedding service * * @param config - Configuration for the embedding service */ constructor(config?: EmbeddingServiceConfig); /** * Sets up cache management to prevent memory leaks */ private setupCacheManagement; /** * Executes a function with retry logic */ private withRetry; /** * Create a hash key for the cache */ private createCacheKey; /** * Chunks text into smaller pieces for better embedding */ private chunkText; /** * Generates an embedding for a single text with caching and chunking * * @param text - The text to embed * @returns Promise resolving to the embedding vector */ embedText(text: string): Promise; /** * Embeds a long text by chunking and then combining chunks * * @param text - The long text to embed * @returns Promise resolving to the combined embedding vector */ private embedLongText; /** * Combines multiple embeddings into one * * @param embeddings - Array of embeddings to combine * @param weights - Optional weights for each embedding (e.g. chunk lengths) * @returns Combined embedding vector */ private combineEmbeddings; /** * Generates embeddings for multiple texts in batches * * @param texts - Array of texts to embed * @returns Promise resolving to an array of embedding vectors */ embedBatch(texts: string[]): Promise; /** * Calculate cosine similarity between two vectors * * @param a - First vector * @param b - Second vector * @returns Cosine similarity (0-1) */ calculateSimilarity(a: number[], b: number[]): number; }