fix(go-model): default Jina rerank top_n to document count (#17242)

## Summary

- Default Jina rerank `top_n` to the document count
- Add coverage for default and explicitly configured `top_n` values

## Testing

- `bash build.sh --test -c -o /tmp/ragflow-models.test
./internal/entity/models`
- `git diff --check`
This commit is contained in:
Hz_
2026-07-24 10:53:09 +08:00
committed by GitHub
parent 339bba8793
commit e66d617f4f
2 changed files with 27 additions and 2 deletions

View File

@@ -234,8 +234,8 @@ func (j *JinaModel) Rerank(ctx context.Context, modelName *string, query string,
}
url := fmt.Sprintf("%s/%s", resolvedBaseURL, j.baseModel.URLSuffix.Rerank)
var topN = rerankConfig.TopN
if rerankConfig.TopN != 0 {
topN := len(documents)
if rerankConfig != nil && rerankConfig.TopN > 0 && rerankConfig.TopN < topN {
topN = rerankConfig.TopN
}

View File

@@ -254,3 +254,28 @@ func TestJinaChatFallsBackToDefaultOnEmptyRegion(t *testing.T) {
t.Errorf("empty Region: expected fallback to default, got %v", err)
}
}
func TestJinaRerankDefaultsTopNToDocumentCount(t *testing.T) {
srv := newJinaServer(t, "/rerank", func(t *testing.T, body map[string]interface{}, w http.ResponseWriter) {
if body["top_n"] != float64(2) {
t.Errorf("top_n=%v, want 2", body["top_n"])
}
_, _ = w.Write([]byte(`{"results":[]}`))
})
defer srv.Close()
apiKey := "test-key"
modelName := "jina-reranker-v3"
_, err := newJinaForTest(srv.URL).Rerank(
t.Context(),
&modelName,
"weather",
[]string{"sunny", "rainy"},
&APIConfig{ApiKey: &apiKey},
&RerankConfig{},
nil,
)
if err != nil {
t.Fatalf("Rerank: %v", err)
}
}