Repository navigation
[python] Prepare query vectors once per exact search - #11379
Open
wangzhigang1999 wants to merge 1 commit into
Open
wangzhigang1999 wants to merge 1 commit into
wangzhigang1999 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Move the scalar and NumPy scoring routines into
vector_scoring.pyand let the reader own query preparation. The scoring blocks can then take a prepared query directly. This gives the single-query and batch readers a common place to get the query array and cosine norm.Each local read prepares a query once per metric and can reuse it during both candidate reranking and the raw scan. Each Ray scoring task prepares its own queries. The next read starts with an empty cache. This PR also removes four obsolete helpers and moves their tests to the active read paths.
Tests
The conversion test in
vector_scoring_test.pyputs tied hits on opposite sides of a 1,024-row block boundary. It checks the returned row IDs and scores and counts query-array conversions. On the base revision the single-query case converts twice and the two-query case converts eight times. With this change the counts are one and two. A separate batch-scorer test checks that an unsupported metric on a later query raises the usual metric error.I ran the vector search and reader regression tests on macOS arm64 with Python 3.11, including local and Ray execution. The main run passed 685 tests. Both native lookup tests skipped by the default configuration passed with native planning and reading enabled. Another 18 multimodal search tests passed.
I also compared the patch with
3a8e01f35don the same machine. All 30 cases returned the same Top-10 row IDs and bit-identical scores for L2, cosine and inner product. Each timing below is the median of five runs after warm-up. The table shows eight cosine queries.The smallest batches showed the largest benefit. In that case I counted 4,096 query-array conversions on the base revision and eight with the patch.
Closes #11378.