import { C as ConversationStore } from '../ConversationStore-DgHjCpwv.mjs'; import { M as Message } from '../streaming.d-CUzaq8hR.mjs'; import '../common.d-iR60eBef.mjs'; /** * Type definitions for semantic search */ /** * Supported OpenAI embedding models */ type EmbeddingModel = 'text-embedding-3-small' | 'text-embedding-3-large' | 'text-embedding-ada-002'; /** * Configuration for embeddings */ interface EmbeddingConfig { /** OpenAI API key */ apiKey: string; /** Embedding model to use */ model?: EmbeddingModel; /** Batch size for embedding generation */ batchSize?: number; /** Dimensions for the embedding (only for text-embedding-3-* models) */ dimensions?: number; /** Maximum retries for API calls */ maxRetries?: number; /** Timeout in milliseconds */ timeout?: number; } /** * A message with its vector embedding */ interface MessageWithEmbedding extends Message { /** Vector embedding of the message content */ embedding: number[]; } /** * Filter criteria for search */ interface SearchFilter { /** Filter by conversation ID */ conversationId?: string; /** Filter by message role */ role?: 'user' | 'assistant' | 'system'; /** Filter by date range (start timestamp) */ startDate?: number; /** Filter by date range (end timestamp) */ endDate?: number; /** Filter by custom metadata */ metadata?: Record; } /** * Options for search operations */ interface SearchOptions { /** Number of results to return */ topK?: number; /** Minimum similarity threshold (0-1) */ threshold?: number; /** Filter criteria */ filter?: SearchFilter; /** Whether to include the query message in results */ includeQuery?: boolean; } /** * Similarity score with additional metadata */ interface SimilarityScore { /** Cosine similarity score (0-1) */ score: number; /** Distance metric (1 - cosine similarity) */ distance: number; /** Rank in results (1-based) */ rank: number; } /** * Search result containing a message and its similarity score */ interface SearchResult { /** The matched message */ message: Message; /** Similarity score and metadata */ similarity: SimilarityScore; /** Conversation ID the message belongs to */ conversationId?: string; } /** * Options for finding similar messages */ interface SimilarMessageOptions { /** Number of similar messages to return */ topK?: number; /** Minimum similarity threshold (0-1) */ threshold?: number; /** Whether to include the source message in results */ includeSelf?: boolean; /** Filter criteria */ filter?: SearchFilter; } /** * Options for searching across conversations */ interface ConversationSearchOptions extends SearchOptions { /** Specific conversation IDs to search within */ conversationIds?: string[]; /** Maximum number of conversations to search */ maxConversations?: number; } /** * Batch embedding request */ interface BatchEmbeddingRequest { /** Array of texts to embed */ texts: string[]; /** Model to use for embeddings */ model?: EmbeddingModel; /** Dimensions for the embedding */ dimensions?: number; } /** * Batch embedding response */ interface BatchEmbeddingResponse { /** Array of embeddings corresponding to input texts */ embeddings: number[][]; /** Model used for embeddings */ model: string; /** Total tokens used */ usage: { promptTokens: number; totalTokens: number; }; } /** * Cache entry for embeddings */ interface EmbeddingCacheEntry { /** The original text */ text: string; /** The generated embedding */ embedding: number[]; /** Model used */ model: string; /** Timestamp when cached */ cachedAt: number; /** TTL in milliseconds */ ttl?: number; } /** * Statistics for semantic search operations */ interface SearchStats { /** Total number of messages indexed */ totalMessages: number; /** Total number of conversations indexed */ totalConversations: number; /** Total number of embeddings generated */ totalEmbeddings: number; /** Cache hit rate (0-1) */ cacheHitRate?: number; /** Average embedding generation time (ms) */ avgEmbeddingTime?: number; } /** * Semantic search implementation for conversation history * * Provides vector-based semantic search using OpenAI embeddings API. * Supports similarity search, ranking, and filtering across conversations. */ /** * Semantic search engine for conversation messages */ declare class SemanticSearch { private openai; private config; private store; private embeddingCache; private stats; constructor(store: ConversationStore, config: EmbeddingConfig); /** * Generate embedding for a single text */ private generateEmbedding; /** * Generate embeddings for multiple texts in batches */ generateBatchEmbeddings(request: BatchEmbeddingRequest): Promise; /** * Search messages by semantic similarity */ searchMessages(query: string, options?: SearchOptions): Promise; /** * Find similar messages to a given message */ findSimilarMessages(messageId: string, options?: SimilarMessageOptions): Promise; /** * Search across multiple conversations */ searchConversations(query: string, options?: ConversationSearchOptions): Promise; /** * Convert message content to a string for embedding */ private getMessageContentAsString; /** * Calculate cosine similarity between two vectors */ private cosineSimilarity; /** * Get filtered messages from the store */ private getFilteredMessages; /** * Find a message by ID across all conversations */ private findMessageById; /** * Generate cache key for an embedding */ private getCacheKey; /** * Simple hash function for cache keys */ private simpleHash; /** * Check if a cache entry is expired */ private isCacheExpired; /** * Update average embedding time */ private updateAvgEmbeddingTime; /** * Update cache hit rate */ private updateCacheHitRate; /** * Get search statistics */ getStats(): SearchStats; /** * Clear the embedding cache */ clearCache(): void; /** * Get the current cache size */ getCacheSize(): number; } export { type BatchEmbeddingRequest, type BatchEmbeddingResponse, type ConversationSearchOptions, type EmbeddingCacheEntry, type EmbeddingConfig, type EmbeddingModel, type MessageWithEmbedding, type SearchFilter, type SearchOptions, type SearchResult, type SearchStats, SemanticSearch, type SimilarMessageOptions, type SimilarityScore };