/** * @fileoverview Abstract base class for AI reranker implementations. * * Provides the foundation for semantic reranking providers (Cohere, LLM-based, etc.) * following the same patterns as BaseLLM and BaseEmbeddings. * * Implementations should: * 1. Register with @RegisterClass(BaseReranker, 'ProviderName') * 2. Implement the protected doRerank() method * 3. Handle provider-specific API calls and response mapping * * @module @memberjunction/ai * @since 3.0.0 */ import { BaseModel } from './baseModel.js'; import { RerankParams, RerankResponse, RerankResult } from './reranker.types.js'; /** * Abstract base class for all reranker implementations. * Extends BaseModel to follow MJ conventions for AI model classes. * * Provides common functionality including: * - Input validation * - Response standardization * - Utility methods for sorting and filtering results * * Example usage: * ```typescript * @RegisterClass(BaseReranker, 'CohereReranker') * export class CohereReranker extends BaseReranker { * protected async doRerank(params: RerankParams): Promise { * // Call Cohere API and return results * } * } * ``` */ export declare abstract class BaseReranker extends BaseModel { protected _modelName: string; /** * Create a new reranker instance. * @param apiKey - API key for the reranking service (e.g., Cohere API key) * @param modelName - Optional model name to use (provider-specific) */ constructor(apiKey: string, modelName?: string); /** * Get the model name used for this reranker */ get ModelName(): string; /** * Rerank documents based on their relevance to a query. * This is the main entry point for reranking operations. * * The method: * 1. Validates input parameters * 2. Calls the provider-specific doRerank() implementation * 3. Applies topK limit if specified * 4. Returns standardized RerankResponse * * @param params - Reranking parameters including query and documents * @returns Promise resolving to RerankResponse with reranked results */ Rerank(params: RerankParams): Promise; /** * Provider-specific reranking implementation. * Subclasses must implement this method to perform the actual reranking. * * Implementation requirements: * - Call the provider's reranking API * - Map results to RerankResult format * - Sort results by relevance score (highest first) * - Preserve document metadata for zero-copy retrieval * * @param params - Reranking parameters * @returns Promise resolving to array of RerankResult sorted by relevance */ protected abstract doRerank(params: RerankParams): Promise; /** * Create a standardized error response. * Used internally when validation fails or an exception occurs. */ protected createErrorResponse(message: string, startTime: number): RerankResponse; /** * Sort results by relevance score in descending order. * Utility method for implementations. */ protected sortByRelevance(results: RerankResult[]): RerankResult[]; /** * Filter results by minimum relevance threshold. * Utility method for implementations that need to filter low-scoring results. */ protected filterByThreshold(results: RerankResult[], minScore: number): RerankResult[]; } //# sourceMappingURL=baseReranker.d.ts.map