Class RerankedResult<TRaw>

Overview

Represents a single document returned from some generic findAndRerank operation on the Data API. This is the individual item type emitted by a FindAndRerankCursor.

Each result contains:

  • the original document returned by the Data API (after projection), and
  • an optional set of scores yielded during reranking (if includeScores was set on the cursor).

Reranking

When hybrid search is performed using the $hybrid operator, the Data API returns candidate documents based on vector and/or lexical similarity, before reranking them using a reranking model.

If includeScores was enabled when the cursor was created, then the scores from each stage of the ranking pipeline will be included in the scores object for every result.


Example
const cursor = collection.findAndRerank({}, {
sort: { $hybrid: 'What is a tree?' },
includeScores: true,
});

for await (const result of cursor) {
console.log(result.document); // The document
console.log(result.scores); // { $rerank: .12, $vector: .78, ... }
}

Type Parameters

  • TRaw

Constructors

Properties

Constructors

Properties

document: TRaw

The document returned from the findAndRerank query.

If a projection was applied, this will reflect only the projected fields.

scores: Record<string, number>

The set of scores used during the hybrid search and reranking process.

For collections, keys may include:

  • $vector: the score from the vector similarity search
  • $lexical: the score from the lexical similarity search
  • $reranker: the score from the reranking step

This will be an empty object unless includeScores: true was set on the cursor.