feat: migrate multi-vector query and reranker logic to C++#405
Open
chinaux wants to merge 16 commits into
Open
feat: migrate multi-vector query and reranker logic to C++#405chinaux wants to merge 16 commits into
chinaux wants to merge 16 commits into
Conversation
zhourrr
reviewed
May 14, 2026
zhourrr
reviewed
May 15, 2026
zhourrr
reviewed
May 15, 2026
zhourrr
reviewed
May 15, 2026
zhourrr
reviewed
May 15, 2026
zhourrr
reviewed
May 15, 2026
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 |
zhourrr
reviewed
May 19, 2026
zhourrr
reviewed
May 19, 2026
- 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)
…ction._get_object
- 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)
9f92f1b to
3d46458
Compare
zhourrr
reviewed
May 25, 2026
egolearner
reviewed
May 26, 2026
| //! relevance scores. The RRF score for a document at rank r is: | ||
| //! score = 1 / (k + r + 1) | ||
| //! where k is the rank constant. | ||
| class RrfReRanker : public Reranker { |
Collaborator
There was a problem hiding this comment.
命名不一致,RrfReRanker/Reranker,rerank作为一个单词,cpp使用RrfReranker/Reranker更合理。Python为了兼容,可以保持之前的命名。
@Cuiyus 觉得呢?
| WeightedReRanker(MetricType metric = MetricType::L2, | ||
| const std::map<std::string, double> &weights = {}); | ||
|
|
||
| MetricType metric() const { |
Collaborator
There was a problem hiding this comment.
metric不应该放这里。加权时,可能每个向量的距离类型都不一样,metric放这里要求所有向量的距离类型必须一致。
| //! Callback-based re-ranker for cross-language bridging. | ||
| //! | ||
| //! Wraps a user-provided callback (e.g., a Python callable) as a Reranker. | ||
| //! When the callback is a Python function, GIL must be managed by the caller. |
Collaborator
There was a problem hiding this comment.
用Python传callback这个方式跑通了吗?
|
|
||
| // ==================== RrfReRanker ==================== | ||
|
|
||
| DocPtrList RrfReRanker::rerank( |
Collaborator
There was a problem hiding this comment.
reranker应该只提供rescore的接口,打分的逻辑对于rrf/weighted完全一样,放外面更合适。可以参考一下内部gateway的实现。
egolearner
reviewed
May 26, 2026
| //! Multi-vector query structure for querying multiple vector fields | ||
| //! with optional re-ranking of combined results. | ||
|
|
||
| struct SubVectorQuery { |
Collaborator
There was a problem hiding this comment.
SubVectorQuery没必要加?MultiVectorQuery可以直接用std::vector<VectorQuery>?
- 调用的时候显式设置output_fields_为vector{}就不会召回任何字段了,
- 复用topk_作为num_candidates_语义。
- 在多向量检索时,显然filter也需要支持,因此复用VectorQuery能够直接支持filter。
- import Callable from collections.abc instead of typing (UP035) - remove redundant quotes around MetricType annotations (UP037)
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: