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>
27 lines
1006 B
Go
27 lines
1006 B
Go
package embeddingvectors
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ItemEligibilityWhereClause returns the SQL predicate that selects the
|
|
// media items eligible for semantic embedding: matched items, plus audiobooks
|
|
// and ebooks (which are embeddable regardless of metadata match status).
|
|
//
|
|
// This is the single source of truth for embed-eligibility. Both the
|
|
// recommendations queries and the catalog coverage counts delegate here so the
|
|
// vector "coverage" denominator (embed-eligible items) and the populations
|
|
// recommendations operate over stay in lockstep. The empty/blank alias falls
|
|
// back to the bare media_items table name.
|
|
//
|
|
// The emitted string must stay byte-identical to the historical
|
|
// recommendations predicate; see eligibility_test.go.
|
|
func ItemEligibilityWhereClause(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)
|
|
}
|