Member Junction
    Preparing search index...

    LLM-based implementation of the BaseReranker class. Uses AI Prompts to perform semantic reranking via large language models.

    This reranker is useful when:

    • You want to use your existing LLM infrastructure
    • You need more control over the reranking logic via custom prompts
    • Cohere or other dedicated rerankers are not available

    Configuration:

    • Requires a rerank prompt ID to be provided
    • The prompt should accept 'query', 'documents', and 'topK' template variables
    • The prompt should return JSON array: [{ index: number, score: number }, ...]

    Usage:

    const reranker = ClassFactory.CreateInstance<BaseReranker>(
    BaseReranker,
    'LLMReranker',
    '', // No API key needed, uses AI Prompts system
    '', // No model name, uses prompt configuration
    promptID,
    contextUser
    );

    const response = await reranker.Rerank({
    query: 'What is the capital of France?',
    documents: [
    { id: '1', text: 'Paris is the capital of France.' },
    { id: '2', text: 'London is in England.' }
    ],
    topK: 5
    });

    Hierarchy

    • BasePromptBackedReranker
      • LLMReranker
    Index

    Constructors

    • Create a new LLMReranker instance.

      Parameters

      • apiKey: string

        Not used for LLM reranker, pass empty string

      • modelName: string

        Not used for LLM reranker, pass empty string

      • promptID: string

        ID of the AI Prompt to use for reranking

      • contextUser: UserInfo

        User context for executing the prompt

      Returns LLMReranker

    Properties

    _modelName: string
    ParentPromptRunID?: string

    The MJ: AI Prompt Runs row this rerank is recorded under. When set, every prompt run the reranker makes is created as its child (ParentID), so its cost rolls up to the rerank's run. AIRerankerRunner sets it to its own run before it calls the driver.

    Accessors

    • get apiKey(): string

      Only sub-classes can access the API key

      Returns string

    • get ModelName(): string

      Get the model name used for this reranker

      Returns string

    • get PromptID(): string

      Get the prompt ID used for reranking

      Returns string

    Methods

    • The usage of several prompt runs together: their tokens added up, and the sum of the costs that are known, in the currency of the first run that has one. The cost is unset when no run's cost is known.

      Parameters

      Returns ModelUsage

    • The response for a call its signal ended, before or during the driver's work. A caller cancellation is classified Cancelled, so it is never failed over; an abort caused by a timeout reads as a retriable network error.

      Parameters

      • signal: AbortSignal
      • error: unknown
      • startTime: number

      Returns RerankResponse

    • Create a standardized error response. Used internally when validation fails or an exception occurs.

      Parameters

      • message: string
      • startTime: number

      Returns RerankResponse

    • Rerank documents using an LLM via the AI Prompts system.

      The method:

      1. Loads the configured rerank prompt
      2. Formats documents for the prompt template
      3. Executes the prompt with query and documents
      4. Parses the JSON response to extract rankings

      Parameters

      Returns Promise<RerankResult[]>

    • Filter results by minimum relevance threshold. Utility method for implementations that need to filter low-scoring results.

      Parameters

      Returns RerankResult[]

    • Records the usage of a rerank's prompt runs, for Rerank to put on the response. Record it whenever a prompt ran, because a failed call still cost a model call.

      Parameters

      Returns void

    • Reranks through BaseReranker.Rerank, then puts the usage of the rerank's prompt runs on the response as Usage. A failed response carries it too, because a failed call still cost a model call. No Usage when no prompt ran.

      Parameters

      Returns Promise<RerankResponse>

    • Sort results by relevance score in descending order. Utility method for implementations.

      Parameters

      Returns RerankResult[]

    • The tokens and cost of one prompt run. The runner's reported cost wins when it has one. Otherwise it is the run's saved cost, which the server computes when the run is saved: TotalCost, else Cost. The cost is unset when neither is known, so call this after the runner's pending saves.

      Parameters

      Returns ModelUsage