p3: map Brave LLM Context; RRF merge; per-source no_rerank
Live llm/context hits live in grounding.generic plus a URL-keyed sources map, not a sources array. Fan-in uses reciprocal-rank fusion instead of cosine. no_rerank keeps that source's own order as a prefix.
This commit is contained in:
@@ -23,6 +23,7 @@ type Engine struct {
|
||||
Degraded []string // static: missing keys
|
||||
TavilyCap int
|
||||
Now func() time.Time
|
||||
NoRerank map[string]bool
|
||||
|
||||
mu sync.Mutex
|
||||
Queries map[string]map[string]uint64
|
||||
@@ -137,6 +138,7 @@ func (e *Engine) Run(ctx context.Context, query string, k int, doRerank bool, ca
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
var lists []namedHits
|
||||
var hits []Hit
|
||||
var warns []string
|
||||
var okNames, failNames, att []string
|
||||
@@ -158,7 +160,7 @@ func (e *Engine) Run(ctx context.Context, query string, k int, doRerank bool, ca
|
||||
continue
|
||||
}
|
||||
okNames = append(okNames, o.name)
|
||||
hits = append(hits, o.out.Hits...)
|
||||
lists = append(lists, namedHits{name: o.name, hits: o.out.Hits})
|
||||
if o.out.Credits > 0 {
|
||||
e.addCredits(caller, o.name, o.out.Credits)
|
||||
if o.name == NameTavily && e.Cache != nil {
|
||||
@@ -166,24 +168,9 @@ func (e *Engine) Run(ctx context.Context, query string, k int, doRerank bool, ca
|
||||
}
|
||||
}
|
||||
}
|
||||
hits = Dedupe(hits)
|
||||
sortBySourceOrder(hits)
|
||||
hits = mergeSearch(e, lists, doRerank)
|
||||
|
||||
var rerankMS int64
|
||||
if doRerank && e.RerankOn {
|
||||
rs := e.now()
|
||||
ranked, fb := rankHits(ctx, query, hits, e.Embedder)
|
||||
rerankMS = e.now().Sub(rs).Milliseconds()
|
||||
if fb != "" {
|
||||
warns = append(warns, "rerank fell back: "+fb)
|
||||
degraded = true
|
||||
e.mu.Lock()
|
||||
e.RerankFallback++
|
||||
e.mu.Unlock()
|
||||
} else {
|
||||
hits = ranked
|
||||
}
|
||||
}
|
||||
hits = clampHits(hits, k)
|
||||
|
||||
if !degraded && e.Cache != nil && len(att) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user