feat(matching): rank with semantic embeddings and explain matches by evidence
This commit is contained in:
1 parent
facc1789b1
commit
24b64d698a
215 files changed
+16951
-327
No files matched your search
@@ -33,7 +33,31 @@ type MatchingResult struct {
|
||||
// latest version that is not a demonstration version and a family without a
|
||||
// version, because the section is only an addition to a policy that exists.
|
||||
func (publisher *Publisher) EnsureDemoMatchingSection(ctx context.Context, author domain.PolicyAuthor) (MatchingResult, error) {
|
||||
const location = "Publisher.EnsureDemoMatchingSection"
|
||||
return publisher.ensureMatching(ctx, author, "Publisher.EnsureDemoMatchingSection",
|
||||
func(current *domain.MatchingPolicy) bool { return current != nil },
|
||||
domain.DemoMatchingPolicy)
|
||||
}
|
||||
|
||||
// EnsureDemoSemanticMatchingSection makes the latest demonstration version
|
||||
// carry the semantic matching section (domain.DemoSemanticMatchingPolicy): the
|
||||
// encoder identity, the calibration of Sem, the explanation thresholds, and
|
||||
// the Fit weights with Sem 0.5. A version that already has a semantic section
|
||||
// is left alone. Otherwise it publishes the next version, a copy of the latest
|
||||
// one whose matching section is replaced, so the earlier PRD point stays as
|
||||
// the previous version.
|
||||
func (publisher *Publisher) EnsureDemoSemanticMatchingSection(ctx context.Context, author domain.PolicyAuthor) (MatchingResult, error) {
|
||||
return publisher.ensureMatching(ctx, author, "Publisher.EnsureDemoSemanticMatchingSection",
|
||||
func(current *domain.MatchingPolicy) bool { return current != nil && current.Semantics != nil },
|
||||
domain.DemoSemanticMatchingPolicy)
|
||||
}
|
||||
|
||||
func (publisher *Publisher) ensureMatching(
|
||||
ctx context.Context,
|
||||
author domain.PolicyAuthor,
|
||||
location string,
|
||||
present func(*domain.MatchingPolicy) bool,
|
||||
section func() domain.MatchingPolicy,
|
||||
) (MatchingResult, error) {
|
||||
latest, err := publisher.policies.GetLatest(ctx, domain.ProductPolicyKey)
|
||||
if errors.Is(err, outbound.ErrPolicyVersionNotFound) {
|
||||
return MatchingResult{}, fmt.Errorf("%s - the product policy has no version to extend: %w", location, err)
|
||||
@@ -42,13 +66,13 @@ func (publisher *Publisher) EnsureDemoMatchingSection(ctx context.Context, autho
|
||||
return MatchingResult{}, fmt.Errorf("%s - read latest version: %w", location, err)
|
||||
}
|
||||
current := latest.Policy()
|
||||
if current.Matching != nil {
|
||||
if present(current.Matching) {
|
||||
return MatchingResult{Version: latest}, nil
|
||||
}
|
||||
if latest.Kind() != domain.PolicyKindDemo {
|
||||
return MatchingResult{}, fmt.Errorf("%s - latest version %d is %s: %w", location, latest.Version(), latest.Kind(), ErrNotDemoPolicy)
|
||||
}
|
||||
matching := domain.DemoMatchingPolicy()
|
||||
matching := section()
|
||||
current.Matching = &matching
|
||||
// The new version is built on the version that was read, so it takes the
|
||||
// next number exactly once. A taken number means the base is no longer the
|
||||
|
||||
Reference in new issue
Block a user