View Source BM25 (bm25 v1.0.0)

BM25 is an algorithm used to rank documents based on their relevance to a given search query.

BM25 calculates a score for each document based on a given search query, indicating how relevant each document is to that query. The higher the BM25 score, the more relevant the document is considered.

Summary

Functions

Score documents against the given keywords.

Functions

Link to this function

bm25(documents, keywords, opts \\ [])

View Source
@spec bm25([String.t()], [String.t()], keyword()) :: [float()]

Score documents against the given keywords.

Options

  • k1: Float. Controls the scaling of the term frequency component. A higher k1 value allows the term frequency to increase the document score more significantly. k1 typically ranges between 1.2 and 2.0. Default: 1.2.

  • b: Float. Adjusts how much the length of a document affects the final relevance score. b ranges from 0 to 1. Default: 0.75.

Example

iex> documents = [
iex>   "BM25 is a ranking function",
iex>   "used by search engines",
iex>   "to rank matching documents"
iex> ]
iex> query = ["ranking", "search", "function"]
iex> BM25.bm25(documents, query)
[1.8455076734299591, 1.0126973514850315, 0.0]