/** * Semantic Pattern Matcher for LLM Browser (V-003) * * Bridges LearningEngine with vector search to find semantically similar patterns. * Uses embeddings to find relevant patterns even when URLs/content differ textually. */ import { EmbeddingProvider } from '../utils/embedding-provider.js'; import { VectorStore } from '../utils/vector-store.js'; import type { EmbeddedStore } from '../utils/embedded-store.js'; import { type LearnedPattern } from '../utils/embedding-pipeline.js'; /** * Options for finding similar patterns */ export interface FindSimilarOptions { /** Maximum number of results (default: 5) */ limit?: number; /** Minimum similarity threshold 0.0-1.0 (default: 0.6) */ minSimilarity?: number; /** Scope search to specific domain */ domain?: string; /** Include similarity scores in results */ includeScores?: boolean; /** Tenant ID for multi-tenant isolation */ tenantId?: string; } /** * Result of semantic pattern search */ export interface SimilarPattern { /** The matched pattern */ pattern: LearnedPattern; /** Similarity score (0.0-1.0) */ similarity: number; /** What triggered the match */ matchReason: 'url' | 'content' | 'both'; /** Vector store record ID */ embeddingId: string; } /** * Result of a semantic search with match explanation */ export interface SemanticSearchResult { /** Matched patterns ordered by relevance */ patterns: SimilarPattern[]; /** Query that was embedded */ queryText: string; /** Time taken for embedding + search (ms) */ searchTimeMs: number; /** Whether vector search was available */ usedVectorSearch: boolean; } /** * SemanticPatternMatcher - Find patterns using semantic similarity * * This class provides semantic search over learned patterns by: * 1. Converting queries (URLs or content) into embeddings * 2. Searching the vector store for similar embeddings * 3. Fetching full pattern details from SQLite * 4. Ranking results by combined similarity and confidence scores */ export declare class SemanticPatternMatcher { private embeddingProvider; private vectorStore; private embeddedStore; private initialized; /** * Weight for vector similarity in combined scoring (0-1) * Higher = more emphasis on semantic similarity */ private readonly similarityWeight; /** * Weight for pattern confidence in combined scoring (0-1) */ private readonly confidenceWeight; /** * Weight for recency in combined scoring (0-1) */ private readonly recencyWeight; constructor(embeddingProvider?: EmbeddingProvider | null, vectorStore?: VectorStore | null, embeddedStore?: EmbeddedStore | null); /** * Check if semantic matching is available */ isAvailable(): boolean; /** * Initialize with dependencies */ initialize(embeddingProvider: EmbeddingProvider, vectorStore: VectorStore, embeddedStore: EmbeddedStore): Promise; /** * Find patterns semantically similar to a URL * * @param url The URL to find similar patterns for * @param options Search options * @returns Array of similar patterns with scores */ findSimilarByUrl(url: string, options?: FindSimilarOptions): Promise; /** * Find patterns semantically similar to content text * * @param content The content to find similar patterns for * @param options Search options * @returns Array of similar patterns with scores */ findSimilarByContent(content: string, options?: FindSimilarOptions): Promise; /** * Find patterns combining URL and content similarity * * @param url The URL to match * @param content Optional content to match * @param options Search options * @returns Combined results from both URL and content search */ findSimilar(url: string, content?: string, options?: FindSimilarOptions): Promise; /** * Get the best matching pattern for a URL using semantic search * * This is the main entry point for LearningEngine integration. * Returns null if no sufficiently similar pattern is found. * * @param url The URL to find a pattern for * @param minSimilarity Minimum similarity threshold (default: 0.75) * @returns Best matching pattern or null */ findBestMatch(url: string, minSimilarity?: number): Promise; /** * Convert a URL to embedding text */ private urlToEmbeddingText; /** * Truncate content to a reasonable length for embedding */ private truncateContent; /** * Search the vector store with filters */ private searchVectorStore; /** * Fetch full patterns from SQLite and rank by combined score */ private fetchAndRankPatterns; /** * Calculate combined score from vector similarity, confidence, and recency */ private calculateCombinedScore; /** * Get statistics about semantic matching */ getStats(): Promise<{ available: boolean; patternCount: number; dimensions: number; }>; } /** * Create a SemanticPatternMatcher with optional initialization */ export declare function createSemanticPatternMatcher(embeddingProvider?: EmbeddingProvider | null, vectorStore?: VectorStore | null, embeddedStore?: EmbeddedStore | null): SemanticPatternMatcher; //# sourceMappingURL=semantic-pattern-matcher.d.ts.map