liveBook · Manning

Retrieval ranking

As explained in Designing AI Systems

A rank is the ordinal position of an item in an ordered list of search results.

Retrieval ranking orders search results by relevance; a rank is an item’s ordinal position in that list. Keyword and vector searches produce scores on different scales, so combining their scores directly can be unreliable. section 5.5.3

Reciprocal Rank Fusion (RRF) combines ranked lists using position rather than score: each result receives 1/(k + rank) per list, with k=60 a standard default. Results ranked highly by both searches rise in the combined list. For keyword retrieval, PostgreSQL full-text search offers a practical starting point; its ts_rank is simpler than BM25 because it does not account for corpus-wide term rarity. section 5.5.2 section 5.5.3

Listing 5.22 Adding full-text search to the chunks table
ALTER TABLE chunks
    ADD COLUMN search_vector tsvector
    GENERATED ALWAYS AS (
        to_tsvector('english', chunk_text)
    ) STORED;    #A
 
CREATE INDEX idx_chunks_search
    ON chunks USING gin (search_vector);    #B

A generated tsvector and GIN index provide a PostgreSQL keyword-search path for ranking results. section 5.5.2

How Designing AI Systems covers it

How deep it goes
Defines rank fusion with its formula and default constant, and contrasts PostgreSQL ts_rank with BM25.
Examples
Uses PostgreSQL tsvector and GIN indexing, and illustrates fusion with a result ranked highly in both lists.
What you can do after
Apply it via Reciprocal Rank Fusion to merge keyword and vector results without normalizing their scores.
How it connects
Connects BM25, full-text search, vector search, cosine similarity, and Reciprocal Rank Fusion.

Also explained in

Compare how 9 books explain retrieval ranking →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Systems. The section links point to the parts of the book it draws on.