fix(hybrid-search): guard MatchCount=0 truncating all results

When HybridSearch is called from the HTTP endpoint without a
match_count field, params.MatchCount defaults to Go's zero value.
The guard

  if len(deduplicatedChunks) > params.MatchCount { … [:0] }

then silently truncated every result list to empty, so processSearchResults
was called with 0 chunks and returned nil — 64 RRF-fused results → 0.

Fix: treat MatchCount ≤ 0 as "no explicit limit" and fall back to the
same floor (50) used by the over-retrieval phase.  Callers that set
MatchCount explicitly (chat pipeline, knowledge.go, agent tools) are
unaffected.

Verified: vector=50 + keyword=50 → RRF=64 → processSearchResults(50) → 108
final results (50 primary + 61 enrichment neighbours/parents) for
"M1000 MP frequency bands LTE cellular" query.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main
toy0116 2026-05-04 11:33:37 +08:00
parent 1c31d649a7
commit 6ac396afb2
1 changed files with 7 additions and 3 deletions

View File

@ -236,10 +236,14 @@ func (s *knowledgeBaseService) HybridSearch(ctx context.Context,
return nil, err
}
if len(deduplicatedChunks) > params.MatchCount {
deduplicatedChunks = deduplicatedChunks[:params.MatchCount]
// Limit to MatchCount; 0 means "no explicit limit" — use over-retrieval floor (50).
effectiveMatchCount := params.MatchCount
if effectiveMatchCount <= 0 {
effectiveMatchCount = 50
}
if len(deduplicatedChunks) > effectiveMatchCount {
deduplicatedChunks = deduplicatedChunks[:effectiveMatchCount]
}
return s.processSearchResults(ctx, deduplicatedChunks, params.SkipContextEnrichment)
}