Skip to content

Commit ae50736

Browse files
fix(rerank): validate credentials for explicitly configured providers (#4443)
* fix(rerank): validate credentials for explicitly configured providers RerankConfig checked required fields for openai and litellm only. An explicit `provider: cohere` without api_key, or `provider: vikingdb` without ak/sk, was accepted at load time. is_available() then returned False and HierarchicalRetriever fell back to plain vector search, logging a single info-level line saying rerank was not configured. The new checks run against the effective provider, matching the existing openai and litellm branches. Auto-detection is unaffected, since detecting cohere already requires api_key and detecting vikingdb already requires ak and sk. An empty RerankConfig() still resolves to no provider and stays valid. Drops test_default_provider_is_vikingdb, which asserted a default that auto-detection replaced and had been failing on main. Rewrites test_unknown_provider_raises_value_error to actually cover an unknown provider and adds coverage for the two providers that were missing validation. * docs(configuration): state required credentials per rerank provider The rerank section described credential inference but not the fields each provider requires when provider is set explicitly. --------- Co-authored-by: Terminator666666 <Terminator666666@users.noreply.github.com>
1 parent e73c5bf commit ae50736

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

docs/en/configuration/01-server.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Changing the model or `dimension` can make existing vector collections incompati
147147

148148
Rerank has no separate `enabled` field. It becomes available when the required provider credentials are configured.
149149

150+
Setting `provider` explicitly requires the credentials that provider needs: `ak` and `sk` for `vikingdb`, `api_key` for `cohere`, `api_key` and `api_base` for `openai`, `model` for `litellm`. An incomplete block is rejected when the configuration loads.
151+
150152
## Retrieval Settings
151153

152154
```json

docs/zh/configuration/01-server.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ API 型 `embedding`、`vlm`、`query_planner` 和 `rerank` 配置会复用部分
147147

148148
Rerank 没有单独的 `enabled` 字段;配置了对应 provider 所需的凭证后才会启用。
149149

150+
显式指定 `provider` 时必须提供该 provider 所需的凭证:`vikingdb` 需要 `ak``sk``cohere` 需要 `api_key``openai` 需要 `api_key``api_base``litellm` 需要 `model`。凭证不全的配置在加载时即被拒绝。
151+
150152
## 检索配置
151153

152154
```json

openviking_cli/utils/config/rerank_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ def validate_provider_fields(self) -> "RerankConfig":
8888
if provider == "litellm":
8989
if not self.model:
9090
raise ValueError("LiteLLM rerank provider requires 'model'")
91+
if provider == "cohere":
92+
if not self.api_key:
93+
raise ValueError("Cohere rerank provider requires 'api_key'")
94+
if provider == "vikingdb":
95+
if not self.ak or not self.sk:
96+
raise ValueError("VikingDB rerank provider requires 'ak' and 'sk'")
9197
return self
9298

9399
def is_available(self) -> bool:

tests/misc/test_rerank_openai.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,13 @@ def test_openai_requires_api_key_and_api_base(self):
268268
with pytest.raises(ValidationError):
269269
RerankConfig(provider="openai", api_base="https://example.com/rerank")
270270

271-
def test_default_provider_is_vikingdb(self):
272-
config = RerankConfig()
273-
assert config.provider == "vikingdb"
274-
275271
def test_unknown_provider_raises_value_error(self):
276-
with pytest.raises(ValueError, match="provider"):
272+
with pytest.raises(ValidationError, match="provider"):
273+
RerankConfig(provider="unknown", api_key="key")
274+
275+
def test_explicit_provider_requires_its_own_credentials(self):
276+
with pytest.raises(ValidationError, match="api_key"):
277277
RerankConfig(provider="cohere", ak="ak", sk="sk")
278+
279+
with pytest.raises(ValidationError, match="ak"):
280+
RerankConfig(provider="vikingdb", api_key="key")

0 commit comments

Comments
 (0)