Member Junction
    Preparing search index...

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    CostReporter: ReRankerCostReporter = null

    Optional cost reporter. When set, the reranker invokes it after each successful Rerank call with the actual cents charged. The SearchEngine wires this from the RerankerBudgetGuard to the scope-level spend tracker — see Phase 2D.6.

    Accessors

    • get DriverClass(): string

      The DriverClass key used by @RegisterClass(BaseReRanker, 'DriverClassName') so the SearchEngine can resolve this subclass via ClassFactory from the scope's ScopeConfig.reRanker.driverClass value.

      Returns string

    • get Name(): string

      Human-friendly display name. Defaults to DriverClass so subclasses don't have to override unless they want a different label in UI dropdowns / cost reports.

      Returns string

    • get Version(): string

      Reranker semantic version (independent of the package version). Bump this on a subclass when the prompt, scoring formula, or upstream model identifier changes in a way that invalidates cached scores. Defaults to '1'.

      Returns string

    Methods

    • Pre-call cost estimate in cents for reranking the given candidate count. Used by the budget guard to short-circuit BEFORE making the call when the projected cost exceeds SearchScope.RerankerBudgetCents.

      Default: 0 (free / local). Real-provider subclasses override based on their pricing.

      Parameters

      • resultCount: number

        The number of candidates to be reranked.

      Returns number

      Estimated cost in cents (whole + fractional, e.g. 0.25 for ¼¢).

    • Return the underlying @memberjunction/ai BaseReranker instance to use.

      Provider-specific subclasses (Cohere, BGE, Voyage) override this to return a configured AI reranker. Returning null (the default) tells ReRank() to skip the AI layer and fall back to a simple top-N slice — useful for Noop and test implementations.

      Parameters

      • _config: Record<string, unknown>

        Provider-specific config from ScopeConfig.reRanker.config.

      • _contextUser: UserInfo

        The calling user (for auth / tenant propagation).

      Returns BaseReranker

    • Maximum number of candidates a single Rerank call can score. Real providers cap this (Cohere: 1000, Voyage: 1000, OpenAI: varies). The SearchEngine should respect this cap by chunking large candidate lists. Defaults to Number.MAX_SAFE_INTEGER (no cap) — subclasses should override.

      Returns number

    • Helper for subclasses: report a cost AND record it on the optional callback. Always safe to call even when no callback is set.

      Parameters

      • cents: number

      Returns void

    • Score and re-order candidates against the query.

      Default implementation:

      1. Returns empty when topN <= 0 or candidates is empty.
      2. Resolves an AI-layer reranker via getAIReranker(). If none, slices to topN.
      3. Maps SearchResultItem[] to RerankDocument[] (preserving each original item in metadata.__mjSearchItem).
      4. Calls the AI reranker's Rerank() — inherits validation, timing, error handling.
      5. On success, maps the RerankResult[] back to SearchResultItem[], replacing Score with relevanceScore and augmenting ScoreBreakdown with a ReRank key.
      6. On failure, logs and falls back to the unchanged top-N slice.

      Subclasses that bypass the AI layer (e.g. NoopReRanker) may override this method.

      Parameters

      • query: string

        The original query text.

      • candidates: SearchResultItem[]

        The fused candidate list (post-RRF, pre-dedup).

      • topN: number

        Maximum number of candidates to return after re-ranking.

      • contextUser: UserInfo

        The calling user (for auth / tenant propagation).

      • Optionalconfig: Record<string, unknown>

        Optional provider-specific config from ScopeConfig.reRanker.config.

      Returns Promise<SearchResultItem[]>

    • Enumerate every reranker currently registered with ClassFactory under BaseReRanker. Designed for the SearchScope form's reranker dropdown (P2D.7) — the form populates the dropdown from this single call rather than hardcoding a list, so any ClassFactory-registered reranker (including third-party ones published as separate packages) shows up automatically.

      Each entry includes the driver-class registration key, the friendly Name, Version, and a HasCost flag (true when EstimateCostCents(1) > 0). Sorted by Name for stable UI ordering.

      Returns RegisteredReRankerInfo[]