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,6 +33,14 @@ type Dependencies struct {
|
||||
Transactor outbound.Transactor
|
||||
Keyring Keyring
|
||||
Clock func() time.Time
|
||||
// Semantic schedules the vectors of a new requirements snapshot; nil
|
||||
// schedules nothing.
|
||||
Semantic SemanticTrigger
|
||||
}
|
||||
|
||||
// SemanticTrigger schedules the vectors of a need's requirements snapshot.
|
||||
type SemanticTrigger interface {
|
||||
NeedRequirementsChanged(ctx context.Context, unit outbound.UnitOfWork, organizationID, needID uuid.UUID, requirementsVersion int64, at time.Time) error
|
||||
}
|
||||
|
||||
// Service applies organization-scoped need commands and reads.
|
||||
@@ -40,6 +48,7 @@ type Service struct {
|
||||
transactor outbound.Transactor
|
||||
keyring Keyring
|
||||
clock func() time.Time
|
||||
semantic SemanticTrigger
|
||||
}
|
||||
|
||||
// NewService fails at startup when a required dependency is missing.
|
||||
@@ -47,7 +56,7 @@ func NewService(deps Dependencies) (*Service, error) {
|
||||
if deps.Transactor == nil || deps.Keyring == nil || deps.Clock == nil {
|
||||
return nil, errors.New("need.NewService - every dependency must be set")
|
||||
}
|
||||
return &Service{transactor: deps.Transactor, keyring: deps.Keyring, clock: deps.Clock}, nil
|
||||
return &Service{transactor: deps.Transactor, keyring: deps.Keyring, clock: deps.Clock, semantic: deps.Semantic}, nil
|
||||
}
|
||||
|
||||
// CreateCommand binds the authenticated actor and path organization to one
|
||||
@@ -110,6 +119,9 @@ func (service *Service) createInTransaction(
|
||||
if err := unit.Needs().Create(ctx, createdNeed); err != nil {
|
||||
return domain.NeedResponseSnapshot{}, fmt.Errorf("%s - store need: %w", createLocation, err)
|
||||
}
|
||||
if err := service.scheduleSemantic(ctx, unit, command.OrganizationID, needID, createdNeed.RequirementsVersion(), request.now); err != nil {
|
||||
return domain.NeedResponseSnapshot{}, fmt.Errorf("%s - %w", createLocation, err)
|
||||
}
|
||||
if err := unit.NeedCreationResults().SaveCreationResult(ctx, request.scope, snapshot); err != nil {
|
||||
return domain.NeedResponseSnapshot{}, fmt.Errorf("%s - store immutable creation response: %w", createLocation, err)
|
||||
}
|
||||
@@ -305,9 +317,28 @@ func (service *Service) updateInTransaction(
|
||||
}
|
||||
return service.recoverConcurrentUpdate(ctx, store, command, now)
|
||||
}
|
||||
if updated.RequirementsVersion() != current.RequirementsVersion() {
|
||||
if err := service.scheduleSemantic(ctx, unit, command.OrganizationID, command.NeedID, updated.RequirementsVersion(), now); err != nil {
|
||||
return domain.Need{}, fmt.Errorf("%s - %w", location, err)
|
||||
}
|
||||
}
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
// scheduleSemantic schedules the vectors of a new requirements snapshot in
|
||||
// the transaction that created it.
|
||||
func (service *Service) scheduleSemantic(
|
||||
ctx context.Context, unit outbound.UnitOfWork, organizationID, needID uuid.UUID, requirementsVersion int64, at time.Time,
|
||||
) error {
|
||||
if service.semantic == nil {
|
||||
return nil
|
||||
}
|
||||
if err := service.semantic.NeedRequirementsChanged(ctx, unit, organizationID, needID, requirementsVersion, at); err != nil {
|
||||
return fmt.Errorf("schedule need vectors: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (service *Service) recoverConcurrentUpdate(
|
||||
ctx context.Context,
|
||||
store outbound.NeedRepository,
|
||||
|
||||
Reference in new issue
Block a user