Files
silo-server/internal/embeddingvectors/eligibility_test.go
QuickandClaude Opus 4.8 927d7764a4 feat(search): model-filtered embed-eligible coverage counts
Establish how semantic vector "coverage" is counted: current-model
embeddings over embed-eligible items, per media type, from Postgres.

- Move the embed-eligibility predicate to a single source of truth in
  embeddingvectors.ItemEligibilityWhereClause; recommendations now
  delegates to it (output byte-identical).
- Add catalogSemanticCoverageByType (per-type eligible/vectorized) and
  define the coverageQuerier interface in catalog. Both numerator and
  denominator apply the eligibility predicate, so vectorized never
  exceeds eligible (C1 guarantee) even with a stale embedding on a
  now-unmatched item.
- countCatalogSearchVectorDocuments now takes a coverageQuerier and a
  model, applies the eligibility + model filter, and is the per-type
  numerator summed across types. Update all four callers (pass "").
- Add idx_media_item_embeddings_model (CONCURRENTLY, self-healing
  guard) so the model filter does not scan the embeddings table.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 22:43:23 -04:00

38 lines
1.3 KiB
Go

package embeddingvectors
import (
"fmt"
"strings"
"testing"
)
// legacyRecommendationItemEligibilityWhereClause reproduces the predicate that
// recommendations.recommendationItemEligibilityWhereClause emitted before it was
// refactored to delegate here. The shared helper must remain byte-identical so
// existing recommendation queries continue to filter the same population.
func legacyRecommendationItemEligibilityWhereClause(alias string) string {
alias = strings.TrimSpace(alias)
if alias == "" {
alias = "media_items"
}
return fmt.Sprintf("(%s.status = 'matched' OR %s.type = 'audiobook' OR %s.type = 'ebook')", alias, alias, alias)
}
func TestItemEligibilityWhereClauseMatchesLegacy(t *testing.T) {
for _, alias := range []string{"mi", "media_items", " e ", "", " "} {
want := legacyRecommendationItemEligibilityWhereClause(alias)
got := ItemEligibilityWhereClause(alias)
if got != want {
t.Fatalf("ItemEligibilityWhereClause(%q) = %q, want %q", alias, got, want)
}
}
}
func TestItemEligibilityWhereClauseDefaultsAlias(t *testing.T) {
got := ItemEligibilityWhereClause("")
want := "(media_items.status = 'matched' OR media_items.type = 'audiobook' OR media_items.type = 'ebook')"
if got != want {
t.Fatalf("ItemEligibilityWhereClause(\"\") = %q, want %q", got, want)
}
}