MCPcopy Create free account
hub / github.com/diillson/chatcli / buildCorpus

Function buildCorpus

cli/workspace/memory/ranking_test.go:83–115  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
83func 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

Calls 7

AddFactMethod · 0.95
GetAllMethod · 0.95
EnabledMethod · 0.95
BackfillFactsMethod · 0.95
NewFactIndexFunction · 0.85
NewVectorIndexFunction · 0.85
DefaultConfigFunction · 0.70

Tested by

no test coverage detected