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

LUCENE-9071: Speed up BM25 scores. (#1043) #13299

Open
IcanDoItL opened this issue Apr 12, 2024 · 3 comments
Open

LUCENE-9071: Speed up BM25 scores. (#1043) #13299

IcanDoItL opened this issue Apr 12, 2024 · 3 comments

Comments

@IcanDoItL
Copy link

IcanDoItL commented Apr 12, 2024

https://github.com/apache/lucene/blob/0345fcabb3ceb71fb39c1aa77502bae220f259ca/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java#L246,How to understand monotonicity?, freq * 1/norm is guaranteed to be monotonic? but My experimental results are the same as freq / (freq + norm).
the code is
@test
public void test() {
int length = 2;
float freq = 1.0f;
float[] cache = {16777216.0f, 16777217.0f};
float[] inverseCache = new float[length];
for (int i = 0; i < length; i++) {
inverseCache[i] = 1f / cache[i];
}
for (int i = 0; i < length; i++) {
System.out.println(freq / (freq + cache[i]));
}
for (int i = 0; i < length; i++) {
System.out.println(freq * inverseCache[i]);
}
}

@jpountz
Copy link
Contributor

jpountz commented Apr 15, 2024

The problem is not with norm but with freq in that case. Try to compute BM25 scores with a few freqs and you'll find cases when you get a lower score evern though freq is greater by one ulp.

@IcanDoItL
Copy link
Author

IcanDoItL commented Apr 16, 2024

@jpountz thanks

Try to compute BM25 scores with a few freqs and you'll find cases when you get a lower score evern though freq is greater by one ulp.

I didn't find during my testing. Can you give me an example

@jpountz
Copy link
Contributor

jpountz commented Apr 17, 2024

If you apply the change that you suggested and run TestBM25Similarity, you should get failures that will give you examples.

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

2 participants