mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-24 17:36:47 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user