Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: bm25_query_to_svector has an additional norm #16

Open
kemingy opened this issue Jul 12, 2024 · 0 comments
Open

bug: bm25_query_to_svector has an additional norm #16

kemingy opened this issue Jul 12, 2024 · 0 comments

Comments

@kemingy
Copy link
Member

kemingy commented Jul 12, 2024

pg_bestmatch.rs/src/lib.rs

Lines 216 to 221 in 3126173

// https://github.com/pinecone-io/pinecone-text/issues/69
let sum = x.values().copied().sum::<f32>();
let mut result = "{".to_string();
for (index, value) in x.into_iter() {
result.push_str(&format!("{}:{}, ", index + 1, value / sum));
}

This is for:

$$score(D, Q) = \sum^{D\land Q}_t (TF_{norm} * IDF /\sum^Q_t IDF)$$

But if the score (BM25) is pre-computed on the document level, it will become:

$$score(D, Q) = \sum^{D\land Q}_t (TF_{norm} * IDF /\sum^D_t IDF)$$

This means that for each query, the score is not only affected by token $\in D \land Q$, but also token $\in D \notin Q$.

solutions

  1. create another function that computes the BM25 score directly instead of using the element-wise multiplication of document/query sparse vector
  2. or delete the query IDF norm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant