/** * Extended Semantic Search Features (V-004) * * Builds on SemanticPatternMatcher to provide: * - Skill similarity search * - Error pattern matching * - Content deduplication * - Analytics and reporting */ import { EmbeddingProvider } from '../utils/embedding-provider.js'; import { VectorStore, type EntityType } from '../utils/vector-store.js'; import type { EmbeddedStore } from '../utils/embedded-store.js'; import type { Skill } from '../utils/embedding-pipeline.js'; import type { FailureRecord, AntiPattern } from '../types/api-patterns.js'; /** * Options for skill similarity search */ export interface SkillSearchOptions { /** 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; /** Tenant ID for multi-tenant isolation */ tenantId?: string; } /** * Result of skill similarity search */ export interface SimilarSkill { /** The matched skill */ skill: Skill; /** Similarity score (0.0-1.0) */ similarity: number; /** Vector store record ID */ embeddingId: string; } /** * Options for error pattern search */ export interface ErrorSearchOptions { /** Maximum number of results (default: 10) */ limit?: number; /** Minimum similarity threshold 0.0-1.0 (default: 0.5) */ minSimilarity?: number; /** Filter by domain */ domain?: string; /** Filter by error category */ category?: string; /** Tenant ID for multi-tenant isolation */ tenantId?: string; } /** * Result of error pattern search */ export interface SimilarError { /** The matched error record */ error: FailureRecord; /** Similarity score (0.0-1.0) */ similarity: number; /** Vector store record ID */ embeddingId: string; /** Matching anti-pattern if one exists */ antiPattern?: AntiPattern; } /** * Options for content deduplication */ export interface DeduplicationOptions { /** Similarity threshold to consider content duplicate (default: 0.95) */ similarityThreshold?: number; /** Maximum candidates to check (default: 100) */ maxCandidates?: number; /** Scope to domain */ domain?: string; /** Tenant ID for multi-tenant isolation */ tenantId?: string; } /** * Result of content deduplication check */ export interface DuplicateResult { /** Whether a duplicate was found */ isDuplicate: boolean; /** The original content ID if duplicate */ originalId?: string; /** Similarity to original (0.0-1.0) */ similarity?: number; /** Number of candidates checked */ candidatesChecked: number; } /** * Analytics data for semantic search */ export interface SemanticSearchAnalytics { /** Total embeddings by entity type */ embeddingsByType: Record; /** Total embeddings */ totalEmbeddings: number; /** Embedding dimensions */ dimensions: number; /** Model used for embeddings */ model: string; /** Average search latency (ms) from recent searches */ avgSearchLatencyMs: number; /** Search count by entity type */ searchCountByType: Record; /** Top domains by embedding count */ topDomains: Array<{ domain: string; count: number; }>; /** Similarity distribution buckets */ similarityDistribution: { '0.9-1.0': number; '0.8-0.9': number; '0.7-0.8': number; '0.6-0.7': number; '0.5-0.6': number; 'below-0.5': number; }; } /** * SemanticSearchExtended - Extended semantic search capabilities * * Provides skill similarity, error matching, deduplication, and analytics * on top of the core pattern matching functionality. */ export declare class SemanticSearchExtended { private embeddingProvider; private vectorStore; private embeddedStore; /** Internal metrics for analytics */ private metrics; constructor(embeddingProvider?: EmbeddingProvider | null, vectorStore?: VectorStore | null, embeddedStore?: EmbeddedStore | null); /** * Check if semantic search is available */ isAvailable(): boolean; /** * Initialize with dependencies */ initialize(embeddingProvider: EmbeddingProvider, vectorStore: VectorStore, embeddedStore: EmbeddedStore): Promise; /** * Find skills semantically similar to a query * * @param query Search query (skill name, description, or action) * @param options Search options * @returns Array of similar skills with scores */ findSimilarSkills(query: string, options?: SkillSearchOptions): Promise<{ skills: SimilarSkill[]; searchTimeMs: number; usedVectorSearch: boolean; }>; /** * Find skills by action type * * @param action The action to search for (e.g., "click", "type", "navigate") * @param options Search options * @returns Similar skills that perform this action */ findSkillsByAction(action: string, options?: SkillSearchOptions): Promise; /** * Find skills applicable to a specific domain * * @param domain Domain to search (e.g., "github.com") * @param description Optional description of what to accomplish * @returns Skills relevant to this domain */ findSkillsForDomain(domain: string, description?: string): Promise; /** * Find similar error patterns * * Useful for: * - Finding known solutions to new errors * - Identifying recurring issues * - Suggesting retry strategies * * @param errorMessage Error message to match * @param context Additional context (URL, domain, status code) * @param options Search options * @returns Similar errors and their solutions */ findSimilarErrors(errorMessage: string, context?: { url?: string; domain?: string; statusCode?: number; }, options?: ErrorSearchOptions): Promise<{ errors: SimilarError[]; searchTimeMs: number; usedVectorSearch: boolean; }>; /** * Find known anti-patterns that match an error */ private findMatchingAntiPattern; /** * Get suggested retry strategy for an error * * @param errorMessage Error message * @param statusCode HTTP status code if applicable * @returns Suggested retry strategy or null */ getSuggestedRetryStrategy(errorMessage: string, statusCode?: number): Promise<{ strategy: 'retry' | 'backoff' | 'skip' | 'none'; reason: string; delayMs?: number; } | null>; private mapRetryStrategy; private getMostCommon; private getDefaultStrategy; /** * Check if content is a duplicate of existing content * * @param content Content to check * @param options Deduplication options * @returns Duplicate check result */ checkDuplicate(content: string, options?: DeduplicationOptions): Promise; /** * Find all near-duplicates of content * * @param content Content to find duplicates for * @param options Deduplication options * @returns Array of near-duplicate content IDs with similarity scores */ findNearDuplicates(content: string, options?: DeduplicationOptions): Promise>; /** * Get content fingerprint for quick comparison * * @param content Content to fingerprint * @returns Fingerprint string (hash of embedding) */ getContentFingerprint(content: string): Promise; /** * Get comprehensive analytics about semantic search */ getAnalytics(): Promise; /** * Get embedding coverage report * * Shows what percentage of patterns/skills/etc have embeddings */ getCoverageReport(): Promise<{ patterns: { total: number; indexed: number; percentage: number; }; skills: { total: number; indexed: number; percentage: number; }; }>; /** * Reset analytics metrics */ resetMetrics(): void; /** * Track search metrics */ private trackSearch; /** * Get top domains by embedding count */ private getTopDomains; /** * Convert URL to searchable text */ private urlToSearchableText; /** * Truncate content for embedding */ private truncateContent; } /** * Create a SemanticSearchExtended instance */ export declare function createSemanticSearchExtended(embeddingProvider?: EmbeddingProvider | null, vectorStore?: VectorStore | null, embeddedStore?: EmbeddedStore | null): SemanticSearchExtended; //# sourceMappingURL=semantic-search-extended.d.ts.map