* feat(curator): add embedding client and sampler wave-1 prerequisites Bead archie-core-1786637500752-415-434e5bb9 (GitHub #436) was closed with no linked PR/commits, and the surprisal-sampling bead archie-core-1786637500776-416-600a66e5 (GitHub #437) found none of its stated prerequisites -- an embedding client, a Sampler interface, or the four wave-1 cheap sampling strategies -- actually exist. This builds them: - internal/domain/embedding + internal/infrastructure/embedding: a narrow typed embedding client, config-driven via a providers table + a role in [models], mirroring the existing chat model role convention. Degrades to capability-unavailable (never fails startup or a call) for a missing role, unknown provider, unsupported class, or unresolved credential. Wired as an optional capability in bootstrap.go's setupEmbeddings. - internal/domain/sampling: the Sampler interface plus recency, random, all, and staleness-proxy strategies, per docs/prds/curator-sampler-wave1.md. Deterministic given fixed inputs, matching GitHub #437's stated acceptance criterion for the embedding-backed strategy it will add behind this same interface (not part of this change). Table-driven tests throughout; httptest for the embedding client, no live service. No curator wiring yet -- nothing consumes either capability in this change. * no-mistakes(document): docs(architecture): mark curator sampling prereqs as landed
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package sampling
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRecencySampler(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
base := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
candidates := []Candidate{
|
|
{ID: "oldest", At: base},
|
|
{ID: "middle", At: base.Add(time.Hour)},
|
|
{ID: "newest", At: base.Add(2 * time.Hour)},
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
cap int
|
|
wantIDs []string
|
|
}{
|
|
{name: "no cap orders newest first", cap: 0, wantIDs: []string{"newest", "middle", "oldest"}},
|
|
{name: "cap keeps only the most recent", cap: 2, wantIDs: []string{"newest", "middle"}},
|
|
{name: "cap larger than count returns everything", cap: 100, wantIDs: []string{"newest", "middle", "oldest"}},
|
|
}
|
|
|
|
s := NewRecency()
|
|
if s.Name() != "recency" {
|
|
t.Fatalf("Name() = %q, want %q", s.Name(), "recency")
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
got, err := s.Sample(context.Background(), candidates, Request{Cap: tt.cap})
|
|
if err != nil {
|
|
t.Fatalf("Sample() error = %v", err)
|
|
}
|
|
assertIDs(t, got, tt.wantIDs)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRecencySamplerTiesKeepInputOrder(t *testing.T) {
|
|
t.Parallel()
|
|
at := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
candidates := []Candidate{
|
|
{ID: "first", At: at},
|
|
{ID: "second", At: at},
|
|
{ID: "third", At: at},
|
|
}
|
|
got, err := NewRecency().Sample(context.Background(), candidates, Request{})
|
|
if err != nil {
|
|
t.Fatalf("Sample() error = %v", err)
|
|
}
|
|
assertIDs(t, got, []string{"first", "second", "third"})
|
|
}
|
|
|
|
func TestRecencySamplerDoesNotMutateInput(t *testing.T) {
|
|
t.Parallel()
|
|
assertInputNotMutated(t, NewRecency())
|
|
}
|