From 6ac396afb2813e05faa06b6fd3db95367befef55 Mon Sep 17 00:00:00 2001 From: toy0116 Date: Mon, 4 May 2026 11:33:37 +0800 Subject: [PATCH] fix(hybrid-search): guard MatchCount=0 truncating all results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/application/service/knowledgebase_search.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/application/service/knowledgebase_search.go b/internal/application/service/knowledgebase_search.go index 605b442f..8791e654 100644 --- a/internal/application/service/knowledgebase_search.go +++ b/internal/application/service/knowledgebase_search.go @@ -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) }