buildCorpus wires a FactIndex + VectorIndex over a temp dir, adds the corpus, backfills vectors, and returns a content→id map so tests can label samples.
(t *testing.T)
| 81 | // buildCorpus wires a FactIndex + VectorIndex over a temp dir, adds the corpus, |
| 82 | // backfills vectors, and returns a content→id map so tests can label samples. |
| 83 | func buildCorpus(t *testing.T) (*FactIndex, *VectorIndex, map[string]string) { |
| 84 | t.Helper() |
| 85 | dir := t.TempDir() |
| 86 | cfg := DefaultConfig() |
| 87 | fi := NewFactIndex(dir, cfg, zap.NewNop()) |
| 88 | |
| 89 | corpus := []struct{ content, category string }{ |
| 90 | {"OAuth login issues bearer tokens", "auth"}, |
| 91 | {"Postgres stores user rows in tables", "database"}, |
| 92 | {"Kubernetes rollout uses canary strategy", "deploy"}, |
| 93 | {"Zap emits structured logs to stdout", "logging"}, |
| 94 | {"Redis eviction relies on ttl", "cache"}, |
| 95 | } |
| 96 | for _, c := range corpus { |
| 97 | fi.AddFact(c.content, c.category, nil) |
| 98 | } |
| 99 | |
| 100 | contentToID := make(map[string]string) |
| 101 | items := make(map[string]string) |
| 102 | for _, f := range fi.GetAll() { |
| 103 | contentToID[f.Content] = f.ID |
| 104 | items[f.ID] = f.Content |
| 105 | } |
| 106 | |
| 107 | vi := NewVectorIndex(dir, conceptProvider{}, zap.NewNop()) |
| 108 | if !vi.Enabled() { |
| 109 | t.Fatal("vector index should be enabled with a real provider") |
| 110 | } |
| 111 | if err := vi.BackfillFacts(context.Background(), items); err != nil { |
| 112 | t.Fatalf("backfill: %v", err) |
| 113 | } |
| 114 | return fi, vi, contentToID |
| 115 | } |
| 116 | |
| 117 | // TestBlendedBeatsKeyword is the headline A/B: on queries phrased with synonyms |
| 118 | // that never appear in the stored fact text, keyword retrieval is blind while |
no test coverage detected