feat(ml): fuse two embedding models and protect the ML service with a token

This commit is contained in:
shira committed 2026-10-11 14:40:52 +03:00
1 parent bc00d6901f
commit b24e5ff906
63 files changed
+2287 -276

No files matched your search

@@ -1,6 +1,6 @@
// Package policypublish implements the local operator command that adds the
// demo matching section, or the semantic matching section, to the product
// policy. Until an administrative policy
// demo matching section, the semantic matching section, or the two-model
// semantic ensemble section to the product policy. Until an administrative policy
// editor exists, this is how a stand gets the coefficients that the match
// search needs: startup seeds only the first demo version.
package policypublish
@@ -21,7 +21,7 @@ import (
"lincodex/backend/internal/usecase/policy"
)
const usage = "usage: policy-publish matching|semantic --actor operator:<handle>"
const usage = "usage: policy-publish matching|semantic|semantic-ensemble --actor operator:<handle>"
// Track names which section a command publishes.
type Track string
@@ -32,6 +32,10 @@ const (
// TrackSemantic adds the semantic matching section (Sem weight 0.5, the
// encoder identity, the calibration, and the explanation thresholds).
TrackSemantic Track = "semantic"
// TrackSemanticEnsemble replaces the semantic section with the two-model
// ensemble (Giga and Qwen3-Embedding) and its calibration; the earlier
// single-model version stays as the previous version.
TrackSemanticEnsemble Track = "semantic-ensemble"
)
// Command is a parsed, validated request.
@@ -44,11 +48,12 @@ type Command struct {
type Extender interface {
EnsureDemoMatchingSection(ctx context.Context, author domain.PolicyAuthor) (policy.MatchingResult, error)
EnsureDemoSemanticMatchingSection(ctx context.Context, author domain.PolicyAuthor) (policy.MatchingResult, error)
EnsureDemoSemanticEnsembleSection(ctx context.Context, author domain.PolicyAuthor) (policy.MatchingResult, error)
}
// Parse validates every argument before Run reads configuration or connects.
func Parse(args []string) (Command, error) {
if len(args) == 0 || (args[0] != string(TrackMatching) && args[0] != string(TrackSemantic)) {
if len(args) == 0 || (args[0] != string(TrackMatching) && args[0] != string(TrackSemantic) && args[0] != string(TrackSemanticEnsemble)) {
return Command{}, errors.New(usage)
}
track := Track(args[0])
@@ -98,10 +103,16 @@ func Execute(ctx context.Context, command Command, extender Extender, output io.
}
publish, section, note := extender.EnsureDemoMatchingSection, "the demo matching section",
"note: demonstration values, not calibrated; they apply to new searches at once and change no stored result\n"
if command.Track == TrackSemantic {
switch command.Track {
case TrackSemantic:
publish, section, note = extender.EnsureDemoSemanticMatchingSection, "the semantic matching section",
"note: research-calibrated values (LincodexMatch DEV split), not product measurements; searches use them at once,\n"+
"and Sem stays neutral for subjects without vectors until the semantic-backfill command has run\n"
case TrackSemanticEnsemble:
publish, section, note = extender.EnsureDemoSemanticEnsembleSection, "the semantic ensemble section (Giga + Qwen3-Embedding)",
"note: research-calibrated values (LincodexMatch DEV split), not product measurements; the ML service must serve both models,\n"+
"and Sem stays neutral for subjects without Qwen3 vectors until the semantic-backfill command has run\n"
case TrackMatching:
}
result, err := publish(ctx, command.Author)
if err != nil {