UNPKG

@tanstack/ai

Version:

Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.

64 lines (63 loc) 2.46 kB
import { RerankAdapterResult, RerankOptions } from '../../types.js'; /** * Configuration for rerank adapter instances */ export interface RerankAdapterConfig { apiKey?: string; baseUrl?: string; timeout?: number; headers?: Record<string, string>; } /** * Rerank adapter interface with pre-resolved generics. * * An adapter is created by a provider function: `provider('model')` → `adapter` * All type resolution happens at the provider call site, not in this interface. * * Generic parameters: * - TModel: The specific model name (e.g. 'rerank-v3.5') * - TProviderOptions: Provider-specific options (already resolved) */ export interface RerankAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> { /** Discriminator for adapter kind */ readonly kind: 'rerank'; /** Adapter name identifier */ readonly name: string; /** The model this adapter is configured for */ readonly model: TModel; /** * @internal Type-only properties for inference. Not assigned at runtime. */ '~types': { providerOptions: TProviderOptions; }; /** * Rerank the given (pre-serialized) documents against the query, returning * scored indices into `options.documents`. The activity layer maps these * back to the caller's original documents. */ rerank: (options: RerankOptions<TProviderOptions>) => Promise<RerankAdapterResult>; } /** * A RerankAdapter with any/unknown type parameters. * Useful as a constraint in generic functions and interfaces. */ export type AnyRerankAdapter = RerankAdapter<any, any>; /** * Abstract base class for rerank adapters. * Extend this class to implement a rerank adapter for a specific provider. * * Generic parameters match RerankAdapter - all pre-resolved by the provider function. */ export declare abstract class BaseRerankAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> implements RerankAdapter<TModel, TProviderOptions> { readonly kind: "rerank"; abstract readonly name: string; readonly model: TModel; '~types': { providerOptions: TProviderOptions; }; protected config: RerankAdapterConfig; constructor(config: RerankAdapterConfig | undefined, model: TModel); abstract rerank(options: RerankOptions<TProviderOptions>): Promise<RerankAdapterResult>; protected generateId(): string; }