feat: migrate multi-vector query and reranker logic to C++#405
Open
chinaux wants to merge 12 commits into
Open
feat: migrate multi-vector query and reranker logic to C++#405chinaux wants to merge 12 commits into
chinaux wants to merge 12 commits into
Conversation
- Add Reranker base class with RrfReRanker and WeightedReRanker implementations - Add Collection::MultiQuery interface for multi-vector queries with reranking - Add MultiVectorQuery struct in doc.h with forward declaration for Reranker - Add C API bindings for reranker and MultiQuery (zvec_reranker_*, zvec_multi_vector_query_*, zvec_collection_multi_query) - Add Python binding for reranker classes with py::function bridge for callback - Validate duplicate field names in multi-vector queries (C++ and Python consistent) - Remove TODO comment about concurrent execution (SQLEngine is not thread-safe) - Update collection.h MultiQuery doc comment from concurrently to sequentially - Add C++ collection tests (6 MultiQuery test cases) - Add C API tests (reranker functions + multi_vector_query end-to-end) - Implement Python test cases (11 previously skipped tests now active) - Simplify Python query_executor validation for unified duplicate field check
…idate_and_sanitize)
zhourrr
reviewed
May 14, 2026
zhourrr
reviewed
May 15, 2026
| if (query.queries.empty()) { | ||
| return tl::make_unexpected( | ||
| Status::InvalidArgument("No queries provided for MultiQuery")); | ||
| } |
Collaborator
There was a problem hiding this comment.
建议是 multi query 必需接受两个及以上的向量,不支持单向量,且 reranker 也必须强制传入
zhourrr
reviewed
May 15, 2026
| }; | ||
|
|
||
| //! Multi-vector query structure for querying multiple vector fields | ||
| //! with optional re-ranking of combined results. |
Collaborator
There was a problem hiding this comment.
这里的注释为啥 reranking 是 optional 而不是强制的
zhourrr
reviewed
May 15, 2026
zhourrr
reviewed
May 15, 2026
zhourrr
reviewed
May 15, 2026
| //! Each vector field's relevance score is normalized based on its metric type, | ||
| //! then scaled by a user-provided weight. Final scores are summed across | ||
| //! fields. Supported metrics: L2, IP, COSINE. | ||
| class WeightedReRanker : public Reranker { |
Collaborator
There was a problem hiding this comment.
如果用户传入的多组向量中,向量a是用的 L2 metric,向量b用的 cosine,是否应该在校验时直接报错?这种场景下 RRF reranker 下是成立的,在 weighted reranker 时有待商榷
zhourrr
reviewed
May 15, 2026
zhourrr
reviewed
May 15, 2026
| auto *mvq = reinterpret_cast<zvec::MultiVectorQuery *>(query); | ||
| auto *reranker_ptr = | ||
| reinterpret_cast<zvec::Reranker::Ptr *>(reranker); | ||
| mvq->reranker = *reranker_ptr; |
Collaborator
There was a problem hiding this comment.
这里是不是内存泄漏了?mvq 的 reranker copy 了这个 shared pointer。但是用户传入的shared pointer 还存在 heap 上,所以用户得手动 free(reranker) 才能释放这个 shared pointer。但 .h 文件里注释说这个函数 take ownership,用户可能会认为不需要释放
zhourrr
reviewed
May 15, 2026
| * @return zvec_error_code_t Error code | ||
| * | ||
| * @note The returned array is allocated by the library and should be freed | ||
| * using zvec_free() when no longer needed. The individual string pointers |
- Register _SubVectorQuery in pybind11 with from_vector_query() factory - Convert _VectorQuery to _SubVectorQuery in MultiVectorQueryExecutor - Relax RRF/Weighted score assertion tolerance from 1e-10 to 1e-6 - Fix WeightedReRanker test metric to IP (matching HnswIndexParam default)
zhourrr
reviewed
May 19, 2026
| struct SubVectorQuery { | ||
| int num_candidates_; | ||
| std::string field_name_; | ||
| std::string query_vector_; // fp16, void * |
Collaborator
There was a problem hiding this comment.
这里的注释 fp16, void * 是啥意思,感觉像是历史遗留。没意义的话去掉吧
zhourrr
reviewed
May 19, 2026
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.

refact: