sqlite-utils icon indicating copy to clipboard operation
sqlite-utils copied to clipboard

BM25 ranking with search

Open saeedesmaili opened this issue 1 year ago • 1 comments

What's the recommended way of performing BM25 ranking search with sqlite-utils? I found a mention of rank_bm25() in the docs, but I couldn't figure out how to use the function.

Or maybe I'm misunderstanding the docs, and rank_bm25 is actually what sqlite uses behind the scenes when I use full text search (assuming fts_version="FTS4")?

saeedesmaili avatar Aug 03 '24 08:08 saeedesmaili

Ok, I dug a bit into sqlite fts5 docs, and apparently it's already using bm25 even in fts5:

... in a full-text query, column rank contains by default the same value as would be returned by executing the bm25() auxiliary function with no trailing arguments. The difference between reading from the rank column and using the bm25() function directly within the query is only significant when sorting by the returned value. In this case, using "rank" is faster than using bm25().

saeedesmaili avatar Aug 03 '24 08:08 saeedesmaili