Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(rerank): send top_n in OpenAI-compatible rerank requests (#4040)

ktz03687167f1ac9e
diff --git a/openviking/models/rerank/openai_rerank.py b/openviking/models/rerank/openai_rerank.py
index 838e7a16e..baedae4cd 100644
--- a/openviking/models/rerank/openai_rerank.py
+++ b/openviking/models/rerank/openai_rerank.py
@@ -96,6 +96,9 @@ class OpenAIRerankClient(RerankBase):
"model": self.model_name,
"query": query,
"documents": documents,
+ # Required by some OpenAI-compatible providers (e.g. Scaleway);
+ # matches CohereRerankClient and is harmless elsewhere.
+ "top_n": len(documents),
}
def _extract_results(self, response_json: dict) -> Optional[List[dict]]:
diff --git a/tests/models/test_openai_rerank.py b/tests/models/test_openai_rerank.py
index 13b9982c4..6c2f56dd6 100644
--- a/tests/models/test_openai_rerank.py
+++ b/tests/models/test_openai_rerank.py
@@ -68,6 +68,7 @@ class TestBuildRequestBody:
assert body["query"] == "hello"
assert body["documents"] == ["doc1", "doc2"]
assert body["model"] == "qwen3-rerank"
+ assert body["top_n"] == 2
# nested keys should NOT be present
assert "input" not in body
assert "parameters" not in body
@@ -81,6 +82,7 @@ class TestBuildRequestBody:
body = client._build_request_body("hello", ["doc1", "doc2"])
assert body["query"] == "hello"
assert body["documents"] == ["doc1", "doc2"]
+ assert body["top_n"] == 2
assert "input" not in body
@@ -211,6 +213,7 @@ class TestRerankBatch:
sent_body = kwargs["json"]
assert sent_body["query"] == "hello"
assert sent_body["documents"] == ["doc1", "doc2"]
+ assert sent_body["top_n"] == 2
assert "input" not in sent_body
def test_standard_full_flow(self):