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:
2026-09-23 16:02:21 -07:00
parent eb4e46d036
commit b6e1cdf825
10 changed files with 264 additions and 58 deletions
+34
View File
@@ -6,6 +6,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
@@ -96,6 +97,39 @@ func TestBraveMapsSources(t *testing.T) {
}
}
func TestBraveMapsGroundingGeneric(t *testing.T) {
raw, err := os.ReadFile("../../tests/testdata/brave_llm_context.json")
if err != nil {
t.Fatal(err)
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(raw)
}))
defer ts.Close()
c, err := dial.New(ts.URL, dial.Options{Loopback: true, Timeout: time.Second})
if err != nil {
t.Fatal(err)
}
out := (&BraveLLM{Client: c, Key: "k"}).Search(context.Background(), "q", 5)
if len(out.Hits) != 3 {
t.Fatalf("hits %d %+v", len(out.Hits), out.Hits)
}
if out.Hits[0].URL != "https://docs.tavily.com/documentation/api-reference/endpoint/search" {
t.Fatalf("first %+v", out.Hits[0])
}
if !strings.Contains(out.Hits[0].Snippet, "max_results") {
t.Fatalf("snippet %q", out.Hits[0].Snippet)
}
var urls []string
for _, h := range out.Hits {
urls = append(urls, h.URL)
}
joined := strings.Join(urls, " ")
if !strings.Contains(joined, "orphan.example") {
t.Fatalf("sources map missed: %v", urls)
}
}
func TestTavilyBadJSONIsError(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`not-json`))