alibaba--zvec
0923f7c691
* refactor: make Reranker stateless with std::variant value semantics (#461) Replace class hierarchy (Reranker/ScoreBasedReranker/RrfReranker/ WeightedReranker/CallbackReranker) with std::variant<RrfParams, WeightedParams, CallbackParams> value type and a stateless free function reranker::rerank(). Key changes: - reranker.h: define RerankParams variant + reranker::rerank() API - query.h: MultiQuery::reranker (shared_ptr) -> MultiQuery::rerank (value) - schema.h: add CollectionSchema::get_field_ptr() returning FieldSchema::Ptr - collection.cc: push field lookup to caller, pass vector<FieldSchema::Ptr> - c_api: remove opaque zvec_reranker_t, add zvec_multi_query_set_rerank_* - python binding: expose _RrfParams/_WeightedParams/_CallbackParams + setters - python layer: WeightedReRanker(list[float]), remove Python rerank logic - all tests updated to new interface Benefits: - Thread-safe by design: no mutable state, safe to share across threads - Collection-decoupled: no bind_schema(), field info passed as parameter - Simpler lifecycle: value semantics, no shared_ptr management Closes #461 * chore: remove nightly_build.yml unrelated to reranker refactor * chore: remove uv.lock unrelated to reranker refactor * fix: raise ValueError when multi-query has no reranker After the reranker stateless refactor the C++ MultiQuery rerank strategy uses a std::variant with a default value, so the implicit 'reranker required' validation no longer triggered. Restore the check in QueryExecutor._execute_multi_query so that a hybrid (multi-query) request without a reranker raises ValueError. * fix(reranker): use index_type FTS check for non-vector normalization Replace dynamic_cast nullptr check with explicit IndexType::FTS check and map FTS/BM25 positive scores to (0.0, 1.0) via 2*atan(score)/pi. * refactor(reranker): move Params types into reranker namespace and qualify usages Move RrfParams, WeightedParams, CallbackParams and RerankParams into the zvec::reranker namespace, and add explicit reranker:: qualification at all usage sites outside the reranker module (query.h, python/c bindings, tests). * refactor(query): drop unused PendingQuery wrapper, use std::vector<SearchQuery> directly * refactor(reranker): make _to_cpp_params non-abstract with default NotImplementedError Remove @abstractmethod from RerankFunction._to_cpp_params and provide a default implementation raising NotImplementedError. Drop the redundant _to_cpp_params overrides from Qwen and Sentence rerankers since they use the Python rerank path and don't need the C++ conversion.
59 行
2.2 KiB
Python
59 行
2.2 KiB
Python
# Copyright 2025-present the zvec project
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
from __future__ import annotations
|
|
|
|
from .bm25_embedding_function import BM25EmbeddingFunction
|
|
from .embedding_function import DenseEmbeddingFunction, SparseEmbeddingFunction
|
|
from .http_embedding_function import HTTPDenseEmbedding
|
|
from .jina_embedding_function import JinaDenseEmbedding
|
|
from .jina_function import JinaFunctionBase
|
|
from .multi_vector_reranker import CallbackReRanker, RrfReRanker, WeightedReRanker
|
|
from .openai_embedding_function import OpenAIDenseEmbedding
|
|
from .openai_function import OpenAIFunctionBase
|
|
from .qwen_embedding_function import QwenDenseEmbedding, QwenSparseEmbedding
|
|
from .qwen_function import QwenFunctionBase
|
|
from .qwen_rerank_function import QwenReRanker
|
|
from .rerank_function import RerankFunction
|
|
from .rerank_function import RerankFunction as ReRanker
|
|
from .sentence_transformer_embedding_function import (
|
|
DefaultLocalDenseEmbedding,
|
|
DefaultLocalSparseEmbedding,
|
|
)
|
|
from .sentence_transformer_function import SentenceTransformerFunctionBase
|
|
from .sentence_transformer_rerank_function import DefaultLocalReRanker
|
|
|
|
__all__ = [
|
|
"BM25EmbeddingFunction",
|
|
"CallbackReRanker",
|
|
"DefaultLocalDenseEmbedding",
|
|
"DefaultLocalReRanker",
|
|
"DefaultLocalSparseEmbedding",
|
|
"DenseEmbeddingFunction",
|
|
"HTTPDenseEmbedding",
|
|
"JinaDenseEmbedding",
|
|
"JinaFunctionBase",
|
|
"OpenAIDenseEmbedding",
|
|
"OpenAIFunctionBase",
|
|
"QwenDenseEmbedding",
|
|
"QwenFunctionBase",
|
|
"QwenReRanker",
|
|
"QwenSparseEmbedding",
|
|
"ReRanker",
|
|
"RerankFunction",
|
|
"RrfReRanker",
|
|
"SentenceTransformerFunctionBase",
|
|
"SparseEmbeddingFunction",
|
|
"WeightedReRanker",
|
|
]
|