The rank_bm25 function has been deprecated as of 0.8.5 and has been replaced with score_bm25, which follows new query syntax and has a different return type.

Overview

BM25 scores measure how relevant a score is for a given query. Higher scores indicate higher relevance.

Basic Usage

The score_bm25 function takes a query and returns a table with two columns: the key_field of each result and its BM25 score. score_bm25 accepts the same parameters as search.

SELECT * FROM <index_name>.score_bm25('<query>');
index_name
required

The name of the index.

query
required

The query string.

limit_rows
The maximum number of rows to return.
offset_rows

The number of rows to skip before starting to return rows.

stable_sort
default: false

A boolean specifying whether ParadeDB should stabilize the order of equally-scored results, at the cost of performance.

Joining BM25 Scores

Because score_bm25 generates a new score_bm25 column, the function does not return all the columns of the original table. To map the columns of the original table to the output of score_bm25, perform a JOIN on the key_field column.

-- Here, the key_field is "id"
WITH scores AS (
    SELECT * FROM search_idx.score_bm25(
      'description:keyboard',
      highlight_field => 'description'
    )
)
SELECT scores.id, description, score_bm25
FROM scores
LEFT JOIN mock_items ON scores.id = mock_items.id;