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
@@ -57,6 +57,9 @@ type privacyCohortCandidate struct {
|
||||
acknowledgements []domain.ProfileParallelPeriodAcknowledgement
|
||||
workFormats []domain.QuestionnaireWorkFormat
|
||||
categories []domain.CandidateViewConfirmedCategoryInput
|
||||
// verifiedRepositories holds the keys of the repositories whose latest
|
||||
// check found them public.
|
||||
verifiedRepositories map[string]bool
|
||||
}
|
||||
|
||||
func (repository privacyCohortRepository) ListVisibleCandidateViewSources(
|
||||
@@ -94,6 +97,7 @@ func (repository privacyCohortRepository) ListVisibleCandidateViewSources(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - restore candidate source: %w", location, err)
|
||||
}
|
||||
current.verifiedRepositories = verifiedRepositorySet(row.VerifiedRepositories)
|
||||
}
|
||||
if row.Kind.Valid {
|
||||
claim, err := privacyCohortStoredClaim(row)
|
||||
@@ -210,11 +214,22 @@ func buildPrivacyCohortSource(candidate privacyCohortCandidate) (domain.Candidat
|
||||
return domain.CandidateViewSource{}, fmt.Errorf("validate safe profile claims: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
return domain.NewCandidateViewSource(
|
||||
candidate.id, candidate.fields, domain.CandidateViewProfileFromContent(content), candidate.categories,
|
||||
candidate.workFormats, nil,
|
||||
candidate.id, candidate.fields,
|
||||
domain.CandidateViewProfileFromContentWithRepositories(content, candidate.verifiedRepositories),
|
||||
candidate.categories, candidate.workFormats, nil,
|
||||
)
|
||||
}
|
||||
|
||||
// verifiedRepositorySet turns the keys of the verified repositories of one
|
||||
// candidate into a set.
|
||||
func verifiedRepositorySet(keys []string) map[string]bool {
|
||||
set := make(map[string]bool, len(keys))
|
||||
for _, key := range keys {
|
||||
set[key] = true
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
func privacyCohortJSONBytes(value any) ([]byte, error) {
|
||||
switch typed := value.(type) {
|
||||
case []byte:
|
||||
|
||||
@@ -134,6 +134,7 @@ func buildPreviewCandidateViewSource(
|
||||
if err != nil {
|
||||
return domain.CandidateViewSource{}, fmt.Errorf("%s - restore candidate input: %w", location, err)
|
||||
}
|
||||
candidate.verifiedRepositories = verifiedRepositorySet(first.VerifiedRepositories)
|
||||
for _, row := range rows {
|
||||
if row.Kind.Valid {
|
||||
claim, err := previewStoredClaim(row)
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"lincodex/backend/internal/adapter/secondary/postgres/sqlc"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
// SemanticVectors returns the vector repository of the transaction.
|
||||
func (unit *UnitOfWork) SemanticVectors() outbound.SemanticVectorRepository {
|
||||
return semanticVectorRepository{queries: unit.queries}
|
||||
}
|
||||
|
||||
// ProjectRepositories returns the repository check store of the transaction.
|
||||
func (unit *UnitOfWork) ProjectRepositories() outbound.ProjectRepositoryStore {
|
||||
return projectRepositoryStore{queries: unit.queries}
|
||||
}
|
||||
|
||||
type semanticVectorRepository struct {
|
||||
queries *sqlc.Queries
|
||||
}
|
||||
|
||||
func subjectColumns(kind domain.SemanticSubjectKind, subjectID uuid.UUID) (pgtype.UUID, pgtype.UUID, error) {
|
||||
switch kind {
|
||||
case domain.SemanticSubjectCandidate:
|
||||
return pgUUID(subjectID), pgtype.UUID{}, nil
|
||||
case domain.SemanticSubjectNeed:
|
||||
return pgtype.UUID{}, pgUUID(subjectID), nil
|
||||
default:
|
||||
return pgtype.UUID{}, pgtype.UUID{}, fmt.Errorf("postgres.subjectColumns - subject kind is unknown: %w", domain.ErrInvalidSemanticVector)
|
||||
}
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) Replace(
|
||||
ctx context.Context,
|
||||
kind domain.SemanticSubjectKind,
|
||||
subjectID uuid.UUID,
|
||||
model domain.SemanticModel,
|
||||
items []outbound.StoredSemanticItem,
|
||||
at time.Time,
|
||||
) error {
|
||||
const location = "semanticVectorRepository.Replace"
|
||||
candidateID, needID, err := subjectColumns(kind, subjectID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := repository.queries.DeleteSemanticVectorsOfModel(ctx, sqlc.DeleteSemanticVectorsOfModelParams{
|
||||
SubjectKind: string(kind), SubjectID: pgUUID(subjectID),
|
||||
ModelID: model.ID, ModelRevision: model.Revision, PromptVersion: model.PromptVersion,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("%s - delete previous vectors: %w", location, markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
for _, item := range items {
|
||||
if err := repository.queries.InsertSemanticVector(ctx, sqlc.InsertSemanticVectorParams{
|
||||
SubjectKind: string(kind), SubjectID: pgUUID(subjectID), CandidateID: candidateID, NeedID: needID,
|
||||
ModelID: model.ID, ModelRevision: model.Revision, PromptVersion: model.PromptVersion,
|
||||
ItemKey: item.Key, ContentSha256: item.ContentDigest[:], LabelSha256: item.LabelDigest,
|
||||
Dimension: int32(len(item.Vector)), Vector: item.Vector.Encode(), ComputedAt: pgTime(at), //nolint:gosec // a domain vector has at most 4096 dimensions
|
||||
}); err != nil {
|
||||
return fmt.Errorf("%s - insert vector: %w", location, markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// semanticLockNamespace keeps the advisory lock keys of vector jobs apart
|
||||
// from any other advisory lock of the database.
|
||||
const semanticLockNamespace = 0x53454d41 // "SEMA"
|
||||
|
||||
func (repository semanticVectorRepository) Lock(ctx context.Context, kind domain.SemanticSubjectKind, subjectID uuid.UUID) error {
|
||||
digest := sha256.Sum256([]byte(string(kind) + ":" + subjectID.String()))
|
||||
key := int64(binary.BigEndian.Uint64(digest[:8])>>16) ^ semanticLockNamespace
|
||||
if err := repository.queries.LockSemanticSubject(ctx, key); err != nil {
|
||||
return fmt.Errorf("semanticVectorRepository.Lock - take lock: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) DeleteSubject(ctx context.Context, kind domain.SemanticSubjectKind, subjectID uuid.UUID) error {
|
||||
if err := repository.queries.DeleteSemanticVectorsOfSubject(ctx, sqlc.DeleteSemanticVectorsOfSubjectParams{
|
||||
SubjectKind: string(kind), SubjectID: pgUUID(subjectID),
|
||||
}); err != nil {
|
||||
return fmt.Errorf("semanticVectorRepository.DeleteSubject - delete vectors: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) Digests(
|
||||
ctx context.Context, kind domain.SemanticSubjectKind, subjectID uuid.UUID, model domain.SemanticModel,
|
||||
) (map[string][32]byte, error) {
|
||||
rows, err := repository.queries.ListSemanticVectorDigests(ctx, sqlc.ListSemanticVectorDigestsParams{
|
||||
SubjectKind: string(kind), SubjectID: pgUUID(subjectID),
|
||||
ModelID: model.ID, ModelRevision: model.Revision, PromptVersion: model.PromptVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("semanticVectorRepository.Digests - select digests: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
digests := make(map[string][32]byte, len(rows))
|
||||
for _, row := range rows {
|
||||
var digest [32]byte
|
||||
if len(row.ContentSha256) != len(digest) {
|
||||
return nil, fmt.Errorf("semanticVectorRepository.Digests - digest length is invalid: %w", domain.ErrInvalidSemanticVector)
|
||||
}
|
||||
copy(digest[:], row.ContentSha256)
|
||||
digests[row.ItemKey] = digest
|
||||
}
|
||||
return digests, nil
|
||||
}
|
||||
|
||||
func pgUUIDs(ids []uuid.UUID) []pgtype.UUID {
|
||||
values := make([]pgtype.UUID, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
values = append(values, pgUUID(id))
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) CandidateWholeVectors(
|
||||
ctx context.Context, model domain.SemanticModel, candidateIDs []uuid.UUID,
|
||||
) (map[uuid.UUID]domain.SemanticVector, error) {
|
||||
const location = "semanticVectorRepository.CandidateWholeVectors"
|
||||
vectors := make(map[uuid.UUID]domain.SemanticVector)
|
||||
if len(candidateIDs) == 0 {
|
||||
return vectors, nil
|
||||
}
|
||||
rows, err := repository.queries.ListCandidateWholeVectors(ctx, sqlc.ListCandidateWholeVectorsParams{
|
||||
ModelID: model.ID, ModelRevision: model.Revision, PromptVersion: model.PromptVersion,
|
||||
CandidateIds: pgUUIDs(candidateIDs),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - select vectors: %w", location, markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
for _, row := range rows {
|
||||
vector, err := domain.DecodeSemanticVector(row.Vector, int(row.Dimension))
|
||||
if err != nil || !row.CandidateID.Valid {
|
||||
return nil, fmt.Errorf("%s - stored vector is invalid: %w", location, domain.ErrInvalidSemanticVector)
|
||||
}
|
||||
vectors[uuid.UUID(row.CandidateID.Bytes)] = vector
|
||||
}
|
||||
return vectors, nil
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) CandidateItemVectors(
|
||||
ctx context.Context, model domain.SemanticModel, candidateIDs []uuid.UUID,
|
||||
) (map[uuid.UUID][]outbound.SemanticItemVector, error) {
|
||||
const location = "semanticVectorRepository.CandidateItemVectors"
|
||||
vectors := make(map[uuid.UUID][]outbound.SemanticItemVector)
|
||||
if len(candidateIDs) == 0 {
|
||||
return vectors, nil
|
||||
}
|
||||
rows, err := repository.queries.ListCandidateItemVectors(ctx, sqlc.ListCandidateItemVectorsParams{
|
||||
ModelID: model.ID, ModelRevision: model.Revision, PromptVersion: model.PromptVersion,
|
||||
CandidateIds: pgUUIDs(candidateIDs),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - select vectors: %w", location, markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
for _, row := range rows {
|
||||
vector, err := domain.DecodeSemanticVector(row.Vector, int(row.Dimension))
|
||||
if err != nil || !row.CandidateID.Valid {
|
||||
return nil, fmt.Errorf("%s - stored vector is invalid: %w", location, domain.ErrInvalidSemanticVector)
|
||||
}
|
||||
id := uuid.UUID(row.CandidateID.Bytes)
|
||||
vectors[id] = append(vectors[id], outbound.SemanticItemVector{Key: row.ItemKey, LabelDigest: row.LabelSha256, Vector: vector})
|
||||
}
|
||||
return vectors, nil
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) NeedVectors(
|
||||
ctx context.Context, needID uuid.UUID, model domain.SemanticModel, digests [][32]byte,
|
||||
) (map[string]domain.SemanticVector, error) {
|
||||
const location = "semanticVectorRepository.NeedVectors"
|
||||
vectors := make(map[string]domain.SemanticVector)
|
||||
if len(digests) == 0 {
|
||||
return vectors, nil
|
||||
}
|
||||
values := make([][]byte, 0, len(digests))
|
||||
for _, digest := range digests {
|
||||
values = append(values, digest[:])
|
||||
}
|
||||
rows, err := repository.queries.ListNeedVectors(ctx, sqlc.ListNeedVectorsParams{
|
||||
NeedID: pgUUID(needID), ModelID: model.ID, ModelRevision: model.Revision, PromptVersion: model.PromptVersion,
|
||||
ContentDigests: values,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - select vectors: %w", location, markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
for _, row := range rows {
|
||||
vector, err := domain.DecodeSemanticVector(row.Vector, int(row.Dimension))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - stored vector is invalid: %w", location, domain.ErrInvalidSemanticVector)
|
||||
}
|
||||
vectors[row.ItemKey] = vector
|
||||
}
|
||||
return vectors, nil
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) CandidatesAfter(ctx context.Context, after uuid.UUID, limit int) ([]uuid.UUID, error) {
|
||||
rows, err := repository.queries.ListProfileCandidatesAfter(ctx, sqlc.ListProfileCandidatesAfterParams{
|
||||
AfterID: pgUUID(after), PageSize: int32(limit), //nolint:gosec // the caller bounds the page size
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("semanticVectorRepository.CandidatesAfter - select candidates: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
ids := make([]uuid.UUID, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
ids = append(ids, uuid.UUID(row.Bytes))
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (repository semanticVectorRepository) NeedsAfter(ctx context.Context, after uuid.UUID, limit int) ([]outbound.NeedReference, error) {
|
||||
rows, err := repository.queries.ListNeedsAfter(ctx, sqlc.ListNeedsAfterParams{
|
||||
AfterID: pgUUID(after), PageSize: int32(limit), //nolint:gosec // the caller bounds the page size
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("semanticVectorRepository.NeedsAfter - select needs: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
needs := make([]outbound.NeedReference, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
needs = append(needs, outbound.NeedReference{
|
||||
NeedID: uuid.UUID(row.ID.Bytes), OrganizationID: uuid.UUID(row.OrganizationID.Bytes),
|
||||
RequirementsVersion: row.RequirementsVersion,
|
||||
})
|
||||
}
|
||||
return needs, nil
|
||||
}
|
||||
|
||||
type projectRepositoryStore struct {
|
||||
queries *sqlc.Queries
|
||||
}
|
||||
|
||||
func repositoryCheckFromRow(row sqlc.CandidateProjectRepository) outbound.RepositoryCheck {
|
||||
check := outbound.RepositoryCheck{
|
||||
Key: row.RepositoryKey, State: outbound.RepositoryCheckState(row.State),
|
||||
GitHubID: row.GithubID.Int64, RepositoryETag: row.RepositoryEtag.String, ReadmeETag: row.ReadmeEtag.String,
|
||||
Failure: outbound.RepositoryFailureClass(row.FailureClass.String), RequestedAt: row.RequestedAt.Time.UTC(),
|
||||
Evidence: domain.RepositoryEvidence{
|
||||
Description: row.Description.String, Topics: row.Topics, Languages: row.Languages,
|
||||
ReadmeExcerpt: row.ReadmeExcerpt.String,
|
||||
},
|
||||
}
|
||||
if row.CheckedAt.Valid {
|
||||
check.CheckedAt = row.CheckedAt.Time.UTC()
|
||||
}
|
||||
return check
|
||||
}
|
||||
|
||||
func (store projectRepositoryStore) List(ctx context.Context, candidateID uuid.UUID) ([]outbound.RepositoryCheck, error) {
|
||||
rows, err := store.queries.ListCandidateProjectRepositories(ctx, pgUUID(candidateID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("projectRepositoryStore.List - select checks: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
checks := make([]outbound.RepositoryCheck, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
checks = append(checks, repositoryCheckFromRow(row))
|
||||
}
|
||||
return checks, nil
|
||||
}
|
||||
|
||||
func (store projectRepositoryStore) GetForUpdate(ctx context.Context, candidateID uuid.UUID, key string) (outbound.RepositoryCheck, bool, error) {
|
||||
row, err := store.queries.GetCandidateProjectRepositoryForUpdate(ctx, sqlc.GetCandidateProjectRepositoryForUpdateParams{
|
||||
CandidateID: pgUUID(candidateID), RepositoryKey: key,
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return outbound.RepositoryCheck{}, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return outbound.RepositoryCheck{}, false, fmt.Errorf("projectRepositoryStore.GetForUpdate - select check: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
return repositoryCheckFromRow(row), true, nil
|
||||
}
|
||||
|
||||
func (store projectRepositoryStore) Request(ctx context.Context, candidateID uuid.UUID, key string, at time.Time) error {
|
||||
if err := store.queries.RequestCandidateProjectRepositoryCheck(ctx, sqlc.RequestCandidateProjectRepositoryCheckParams{
|
||||
CandidateID: pgUUID(candidateID), RepositoryKey: key, RequestedAt: pgTime(at),
|
||||
}); err != nil {
|
||||
return fmt.Errorf("projectRepositoryStore.Request - record request: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func optionalPgText(value string) pgtype.Text {
|
||||
if value == "" {
|
||||
return pgtype.Text{}
|
||||
}
|
||||
return pgText(value)
|
||||
}
|
||||
|
||||
func (store projectRepositoryStore) Save(ctx context.Context, candidateID uuid.UUID, check outbound.RepositoryCheck) error {
|
||||
params := sqlc.SaveCandidateProjectRepositoryCheckParams{
|
||||
State: string(check.State), Topics: []string{}, Languages: []string{},
|
||||
RepositoryEtag: optionalPgText(check.RepositoryETag), ReadmeEtag: optionalPgText(check.ReadmeETag),
|
||||
FailureClass: optionalPgText(string(check.Failure)), CheckedAt: pgTime(check.CheckedAt),
|
||||
CandidateID: pgUUID(candidateID), RepositoryKey: check.Key,
|
||||
}
|
||||
if check.State == outbound.RepositoryCheckVerified {
|
||||
params.GithubID = pgtype.Int8{Int64: check.GitHubID, Valid: check.GitHubID > 0}
|
||||
params.Description = optionalPgText(check.Evidence.Description)
|
||||
params.ReadmeExcerpt = optionalPgText(check.Evidence.ReadmeExcerpt)
|
||||
if check.Evidence.Topics != nil {
|
||||
params.Topics = check.Evidence.Topics
|
||||
}
|
||||
if check.Evidence.Languages != nil {
|
||||
params.Languages = check.Evidence.Languages
|
||||
}
|
||||
}
|
||||
if err := store.queries.SaveCandidateProjectRepositoryCheck(ctx, params); err != nil {
|
||||
return fmt.Errorf("projectRepositoryStore.Save - store check: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store projectRepositoryStore) DeleteUnlinked(ctx context.Context, candidateID uuid.UUID, linkedKeys []string) error {
|
||||
if linkedKeys == nil {
|
||||
linkedKeys = []string{}
|
||||
}
|
||||
if err := store.queries.DeleteUnlinkedCandidateProjectRepositories(ctx, sqlc.DeleteUnlinkedCandidateProjectRepositoriesParams{
|
||||
CandidateID: pgUUID(candidateID), LinkedKeys: linkedKeys,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("projectRepositoryStore.DeleteUnlinked - delete checks: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store projectRepositoryStore) LatestRequest(ctx context.Context, candidateID uuid.UUID) (time.Time, error) {
|
||||
latest, err := store.queries.GetLatestRepositoryCheckRequest(ctx, pgUUID(candidateID))
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("projectRepositoryStore.LatestRequest - select request: %w", markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
if !latest.Valid {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
return latest.Time.UTC(), nil
|
||||
}
|
||||
@@ -361,6 +361,24 @@ type CandidateProfileOverlapConfirmation struct {
|
||||
SecondEndedOn pgtype.Text
|
||||
}
|
||||
|
||||
type CandidateProjectRepository struct {
|
||||
CandidateID pgtype.UUID
|
||||
RepositoryKey string
|
||||
State string
|
||||
GithubID pgtype.Int8
|
||||
Description pgtype.Text
|
||||
Topics []string
|
||||
Languages []string
|
||||
ReadmeExcerpt pgtype.Text
|
||||
RepositoryEtag pgtype.Text
|
||||
ReadmeEtag pgtype.Text
|
||||
FailureClass pgtype.Text
|
||||
CheckedAt pgtype.Timestamptz
|
||||
RequestedAt pgtype.Timestamptz
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type CandidatePublication struct {
|
||||
UserID pgtype.UUID
|
||||
State string
|
||||
@@ -838,6 +856,22 @@ type ScheduledJob struct {
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type SemanticVector struct {
|
||||
SubjectKind string
|
||||
SubjectID pgtype.UUID
|
||||
CandidateID pgtype.UUID
|
||||
NeedID pgtype.UUID
|
||||
ModelID string
|
||||
ModelRevision string
|
||||
PromptVersion string
|
||||
ItemKey string
|
||||
ContentSha256 []byte
|
||||
LabelSha256 []byte
|
||||
Dimension int32
|
||||
Vector []byte
|
||||
ComputedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
ID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
|
||||
@@ -68,11 +68,21 @@ SELECT
|
||||
WHERE category.candidate_id = effective.user_id
|
||||
),
|
||||
'[]'::text
|
||||
) AS confirmed_categories
|
||||
) AS confirmed_categories,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT array_agg(repository.repository_key ORDER BY repository.repository_key)
|
||||
FROM candidate_project_repositories AS repository
|
||||
WHERE
|
||||
repository.candidate_id = effective.user_id
|
||||
AND repository.state = 'verified'
|
||||
),
|
||||
'{}'::text []
|
||||
)::text [] AS verified_repositories
|
||||
FROM candidate_effective_publications AS effective
|
||||
LEFT JOIN candidate_profile_claims AS claim
|
||||
ON claim.user_id = effective.user_id
|
||||
AND claim.kind IN ('stack', 'role', 'experience')
|
||||
AND claim.kind IN ('stack', 'role', 'experience', 'project')
|
||||
LEFT JOIN candidate_questionnaires AS questionnaire
|
||||
ON questionnaire.user_id = effective.user_id
|
||||
WHERE NOT EXISTS (
|
||||
@@ -98,15 +108,18 @@ type ListVisibleCandidateViewSourcesRow struct {
|
||||
WorkFormats []string
|
||||
ParallelPeriodAcknowledgements interface{}
|
||||
ConfirmedCategories interface{}
|
||||
VerifiedRepositories []string
|
||||
}
|
||||
|
||||
// Organization-facing anonymous candidate projection inputs. The calling
|
||||
// usecase has already authorized the active organization membership. This
|
||||
// single statement snapshot filters both revoked/unpublished C2 states and
|
||||
// candidates hidden from this organization before any profile value is read.
|
||||
// The projection reads only stack, declared role, and experience dates. It
|
||||
// deliberately excludes names, contacts, salary, location, soft skills,
|
||||
// employer names, summaries, and imported excerpts. The only assessment data
|
||||
// The projection reads only stack, declared role, experience dates, and
|
||||
// projects with the keys of their verified repositories. It deliberately
|
||||
// excludes names, contacts, salary, location, soft skills, employer names,
|
||||
// summaries, and imported excerpts; the repository address of a project stays
|
||||
// in the private input and never reaches the card. The only assessment data
|
||||
// is the current category (specialization and grade) of the separate current
|
||||
// category table; it carries no attempt, score, review, policy, or history.
|
||||
func (q *Queries) ListVisibleCandidateViewSources(ctx context.Context, organizationID pgtype.UUID) ([]ListVisibleCandidateViewSourcesRow, error) {
|
||||
@@ -132,6 +145,7 @@ func (q *Queries) ListVisibleCandidateViewSources(ctx context.Context, organizat
|
||||
&i.WorkFormats,
|
||||
&i.ParallelPeriodAcknowledgements,
|
||||
&i.ConfirmedCategories,
|
||||
&i.VerifiedRepositories,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -301,11 +315,21 @@ SELECT
|
||||
WHERE category.candidate_id = effective.user_id
|
||||
),
|
||||
'[]'::text
|
||||
) AS confirmed_categories
|
||||
) AS confirmed_categories,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT array_agg(repository.repository_key ORDER BY repository.repository_key)
|
||||
FROM candidate_project_repositories AS repository
|
||||
WHERE
|
||||
repository.candidate_id = effective.user_id
|
||||
AND repository.state = 'verified'
|
||||
),
|
||||
'{}'::text []
|
||||
)::text [] AS verified_repositories
|
||||
FROM candidate_effective_publications AS effective
|
||||
LEFT JOIN candidate_profile_claims AS claim
|
||||
ON claim.user_id = effective.user_id
|
||||
AND claim.kind IN ('stack', 'role', 'experience')
|
||||
AND claim.kind IN ('stack', 'role', 'experience', 'project')
|
||||
LEFT JOIN candidate_questionnaires AS questionnaire
|
||||
ON questionnaire.user_id = effective.user_id
|
||||
WHERE effective.user_id = $1
|
||||
@@ -326,6 +350,7 @@ type ReadCandidateViewSourceForPreviewRow struct {
|
||||
WorkFormats []string
|
||||
ParallelPeriodAcknowledgements interface{}
|
||||
ConfirmedCategories interface{}
|
||||
VerifiedRepositories []string
|
||||
}
|
||||
|
||||
// Read the candidate's current private projection inputs after the caller
|
||||
@@ -354,6 +379,7 @@ func (q *Queries) ReadCandidateViewSourceForPreview(ctx context.Context, candida
|
||||
&i.WorkFormats,
|
||||
&i.ParallelPeriodAcknowledgements,
|
||||
&i.ConfirmedCategories,
|
||||
&i.VerifiedRepositories,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: project_repositories.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deleteUnlinkedCandidateProjectRepositories = `-- name: DeleteUnlinkedCandidateProjectRepositories :exec
|
||||
DELETE FROM candidate_project_repositories
|
||||
WHERE
|
||||
candidate_id = $1
|
||||
AND NOT (repository_key = ANY($2::text []))
|
||||
`
|
||||
|
||||
type DeleteUnlinkedCandidateProjectRepositoriesParams struct {
|
||||
CandidateID pgtype.UUID
|
||||
LinkedKeys []string
|
||||
}
|
||||
|
||||
// Removes the checks of repositories that no project links any more.
|
||||
func (q *Queries) DeleteUnlinkedCandidateProjectRepositories(ctx context.Context, arg DeleteUnlinkedCandidateProjectRepositoriesParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteUnlinkedCandidateProjectRepositories, arg.CandidateID, arg.LinkedKeys)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCandidateProjectRepositoryForUpdate = `-- name: GetCandidateProjectRepositoryForUpdate :one
|
||||
SELECT
|
||||
candidate_id, repository_key, state, github_id, description, topics,
|
||||
languages, readme_excerpt, repository_etag, readme_etag, failure_class,
|
||||
checked_at, requested_at, created_at, updated_at
|
||||
FROM candidate_project_repositories
|
||||
WHERE candidate_id = $1 AND repository_key = $2
|
||||
FOR UPDATE
|
||||
`
|
||||
|
||||
type GetCandidateProjectRepositoryForUpdateParams struct {
|
||||
CandidateID pgtype.UUID
|
||||
RepositoryKey string
|
||||
}
|
||||
|
||||
func (q *Queries) GetCandidateProjectRepositoryForUpdate(ctx context.Context, arg GetCandidateProjectRepositoryForUpdateParams) (CandidateProjectRepository, error) {
|
||||
row := q.db.QueryRow(ctx, getCandidateProjectRepositoryForUpdate, arg.CandidateID, arg.RepositoryKey)
|
||||
var i CandidateProjectRepository
|
||||
err := row.Scan(
|
||||
&i.CandidateID,
|
||||
&i.RepositoryKey,
|
||||
&i.State,
|
||||
&i.GithubID,
|
||||
&i.Description,
|
||||
&i.Topics,
|
||||
&i.Languages,
|
||||
&i.ReadmeExcerpt,
|
||||
&i.RepositoryEtag,
|
||||
&i.ReadmeEtag,
|
||||
&i.FailureClass,
|
||||
&i.CheckedAt,
|
||||
&i.RequestedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getLatestRepositoryCheckRequest = `-- name: GetLatestRepositoryCheckRequest :one
|
||||
SELECT MAX(requested_at)::timestamptz AS requested_at
|
||||
FROM candidate_project_repositories
|
||||
WHERE candidate_id = $1
|
||||
`
|
||||
|
||||
// The latest check request of a candidate, for the per-candidate limit.
|
||||
func (q *Queries) GetLatestRepositoryCheckRequest(ctx context.Context, candidateID pgtype.UUID) (pgtype.Timestamptz, error) {
|
||||
row := q.db.QueryRow(ctx, getLatestRepositoryCheckRequest, candidateID)
|
||||
var requested_at pgtype.Timestamptz
|
||||
err := row.Scan(&requested_at)
|
||||
return requested_at, err
|
||||
}
|
||||
|
||||
const listCandidateProjectRepositories = `-- name: ListCandidateProjectRepositories :many
|
||||
|
||||
SELECT
|
||||
candidate_id, repository_key, state, github_id, description, topics,
|
||||
languages, readme_excerpt, repository_etag, readme_etag, failure_class,
|
||||
checked_at, requested_at, created_at, updated_at
|
||||
FROM candidate_project_repositories
|
||||
WHERE candidate_id = $1
|
||||
ORDER BY repository_key
|
||||
`
|
||||
|
||||
// Server checks of the GitHub repositories that candidate projects link.
|
||||
// Every statement is scoped by the candidate.
|
||||
func (q *Queries) ListCandidateProjectRepositories(ctx context.Context, candidateID pgtype.UUID) ([]CandidateProjectRepository, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidateProjectRepositories, candidateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []CandidateProjectRepository
|
||||
for rows.Next() {
|
||||
var i CandidateProjectRepository
|
||||
if err := rows.Scan(
|
||||
&i.CandidateID,
|
||||
&i.RepositoryKey,
|
||||
&i.State,
|
||||
&i.GithubID,
|
||||
&i.Description,
|
||||
&i.Topics,
|
||||
&i.Languages,
|
||||
&i.ReadmeExcerpt,
|
||||
&i.RepositoryEtag,
|
||||
&i.ReadmeEtag,
|
||||
&i.FailureClass,
|
||||
&i.CheckedAt,
|
||||
&i.RequestedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const requestCandidateProjectRepositoryCheck = `-- name: RequestCandidateProjectRepositoryCheck :exec
|
||||
INSERT INTO candidate_project_repositories (
|
||||
candidate_id, repository_key, state, requested_at, created_at, updated_at
|
||||
) VALUES (
|
||||
$1, $2, 'pending', $3,
|
||||
$3, $3
|
||||
)
|
||||
ON CONFLICT (candidate_id, repository_key) DO UPDATE
|
||||
SET
|
||||
requested_at = excluded.requested_at,
|
||||
updated_at = GREATEST(candidate_project_repositories.updated_at, excluded.updated_at)
|
||||
`
|
||||
|
||||
type RequestCandidateProjectRepositoryCheckParams struct {
|
||||
CandidateID pgtype.UUID
|
||||
RepositoryKey string
|
||||
RequestedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// A new repository starts pending; a known one only records the request.
|
||||
func (q *Queries) RequestCandidateProjectRepositoryCheck(ctx context.Context, arg RequestCandidateProjectRepositoryCheckParams) error {
|
||||
_, err := q.db.Exec(ctx, requestCandidateProjectRepositoryCheck, arg.CandidateID, arg.RepositoryKey, arg.RequestedAt)
|
||||
return err
|
||||
}
|
||||
|
||||
const saveCandidateProjectRepositoryCheck = `-- name: SaveCandidateProjectRepositoryCheck :exec
|
||||
UPDATE candidate_project_repositories
|
||||
SET
|
||||
state = $1,
|
||||
github_id = $2,
|
||||
description = $3,
|
||||
topics = $4,
|
||||
languages = $5,
|
||||
readme_excerpt = $6,
|
||||
repository_etag = $7,
|
||||
readme_etag = $8,
|
||||
failure_class = $9,
|
||||
checked_at = $10,
|
||||
updated_at = GREATEST(updated_at, $10)
|
||||
WHERE candidate_id = $11 AND repository_key = $12
|
||||
`
|
||||
|
||||
type SaveCandidateProjectRepositoryCheckParams struct {
|
||||
State string
|
||||
GithubID pgtype.Int8
|
||||
Description pgtype.Text
|
||||
Topics []string
|
||||
Languages []string
|
||||
ReadmeExcerpt pgtype.Text
|
||||
RepositoryEtag pgtype.Text
|
||||
ReadmeEtag pgtype.Text
|
||||
FailureClass pgtype.Text
|
||||
CheckedAt pgtype.Timestamptz
|
||||
CandidateID pgtype.UUID
|
||||
RepositoryKey string
|
||||
}
|
||||
|
||||
func (q *Queries) SaveCandidateProjectRepositoryCheck(ctx context.Context, arg SaveCandidateProjectRepositoryCheckParams) error {
|
||||
_, err := q.db.Exec(ctx, saveCandidateProjectRepositoryCheck,
|
||||
arg.State,
|
||||
arg.GithubID,
|
||||
arg.Description,
|
||||
arg.Topics,
|
||||
arg.Languages,
|
||||
arg.ReadmeExcerpt,
|
||||
arg.RepositoryEtag,
|
||||
arg.ReadmeEtag,
|
||||
arg.FailureClass,
|
||||
arg.CheckedAt,
|
||||
arg.CandidateID,
|
||||
arg.RepositoryKey,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -217,9 +217,19 @@ type Querier interface {
|
||||
DeleteExpiredCompanyCardViewQuotaUsage(ctx context.Context, arg DeleteExpiredCompanyCardViewQuotaUsageParams) (int64, error)
|
||||
DeleteMailRequest(ctx context.Context, id pgtype.UUID) (int64, error)
|
||||
DeleteOrganizationRepresentatives(ctx context.Context, organizationID pgtype.UUID) error
|
||||
// Stored embedding vectors. A candidate keeps one set of rows for a model:
|
||||
// the job deletes every other row of the candidate and model before it
|
||||
// inserts the new set, in one transaction. A need keeps the rows of its
|
||||
// latest computed requirements snapshot the same way.
|
||||
DeleteSemanticVectorsOfModel(ctx context.Context, arg DeleteSemanticVectorsOfModelParams) error
|
||||
// Removes every vector of a subject, of any model: a closed card or a need
|
||||
// without requirements keeps no derived data.
|
||||
DeleteSemanticVectorsOfSubject(ctx context.Context, arg DeleteSemanticVectorsOfSubjectParams) error
|
||||
// No raw Idempotency-Key or request body reaches these statements. Failure
|
||||
// responses pass {} as case_snapshot and the CASE stores SQL NULL instead.
|
||||
DeleteSupportCaseCreateOutcome(ctx context.Context, scopeHash []byte) error
|
||||
// Removes the checks of repositories that no project links any more.
|
||||
DeleteUnlinkedCandidateProjectRepositories(ctx context.Context, arg DeleteUnlinkedCandidateProjectRepositoriesParams) error
|
||||
// Deletes one batch of accounts that stayed unverified since before cutoff,
|
||||
// oldest first, with their tokens, sessions, mail requests, mail deliveries
|
||||
// (and through the deliveries their attempts), and consent records. The
|
||||
@@ -314,6 +324,7 @@ type Querier interface {
|
||||
// Reads one hiding of the candidate with the current name of the
|
||||
// organization.
|
||||
GetCandidateHiddenOrganization(ctx context.Context, arg GetCandidateHiddenOrganizationParams) (GetCandidateHiddenOrganizationRow, error)
|
||||
GetCandidateProjectRepositoryForUpdate(ctx context.Context, arg GetCandidateProjectRepositoryForUpdateParams) (CandidateProjectRepository, error)
|
||||
GetConsentText(ctx context.Context, arg GetConsentTextParams) (ConsentText, error)
|
||||
GetContactConsentRecordByInvitation(ctx context.Context, arg GetContactConsentRecordByInvitationParams) (GetContactConsentRecordByInvitationRow, error)
|
||||
// Read the grant of one invitation of one organization. An invitation of
|
||||
@@ -374,6 +385,8 @@ type Querier interface {
|
||||
// resend, which issues its token with the same credentials.
|
||||
GetLatestPendingRegistration(ctx context.Context, arg GetLatestPendingRegistrationParams) (GetLatestPendingRegistrationRow, error)
|
||||
GetLatestPolicyVersion(ctx context.Context, policyKey string) (PolicyVersion, error)
|
||||
// The latest check request of a candidate, for the per-candidate limit.
|
||||
GetLatestRepositoryCheckRequest(ctx context.Context, candidateID pgtype.UUID) (pgtype.Timestamptz, error)
|
||||
// Reads the latest root in a specialization, optionally restricted to grade.
|
||||
GetLatestRootAssessmentAttempt(ctx context.Context, arg GetLatestRootAssessmentAttemptParams) (AssessmentAttempt, error)
|
||||
GetLiveIdempotencyRecord(ctx context.Context, arg GetLiveIdempotencyRecordParams) (IdempotencyRecord, error)
|
||||
@@ -599,6 +612,7 @@ type Querier interface {
|
||||
// moves a deadline. A concurrent insert of the same key waits for the first
|
||||
// transaction and then inserts nothing, or inserts after its rollback.
|
||||
InsertScheduledJob(ctx context.Context, arg InsertScheduledJobParams) (int64, error)
|
||||
InsertSemanticVector(ctx context.Context, arg InsertSemanticVectorParams) error
|
||||
InsertSession(ctx context.Context, arg InsertSessionParams) error
|
||||
// The initial public history is inserted in the caller's case transaction.
|
||||
// Any unique business conflict leaves the transaction usable so the caller can
|
||||
@@ -687,6 +701,9 @@ type Querier interface {
|
||||
// have no delivery and are never listed. The candidate scopes the rows, so
|
||||
// no identifier of another candidate can appear.
|
||||
ListCandidateInvitations(ctx context.Context, arg ListCandidateInvitationsParams) ([]ListCandidateInvitationsRow, error)
|
||||
// The item vectors of the candidates that a search returns, at most a few
|
||||
// dozen candidates.
|
||||
ListCandidateItemVectors(ctx context.Context, arg ListCandidateItemVectorsParams) ([]ListCandidateItemVectorsRow, error)
|
||||
// The same selection for the candidate's own card preview, so the candidate
|
||||
// sees what an organization would read. It is scoped by the owner and runs
|
||||
// after the caller locked the effective C2 and publication; it does not apply
|
||||
@@ -697,6 +714,11 @@ type Querier interface {
|
||||
// read time, and is the current name. The page continues after the
|
||||
// (occurred_at, id) position of the last event of the previous page.
|
||||
ListCandidatePrivacyEvents(ctx context.Context, arg ListCandidatePrivacyEventsParams) ([]ListCandidatePrivacyEventsRow, error)
|
||||
// Server checks of the GitHub repositories that candidate projects link.
|
||||
// Every statement is scoped by the candidate.
|
||||
ListCandidateProjectRepositories(ctx context.Context, candidateID pgtype.UUID) ([]CandidateProjectRepository, error)
|
||||
// The whole-view vectors of the candidates of one search.
|
||||
ListCandidateWholeVectors(ctx context.Context, arg ListCandidateWholeVectorsParams) ([]ListCandidateWholeVectorsRow, error)
|
||||
// One page of the subject's ledger, newest grant first, optionally limited
|
||||
// to one state. Every record query is scoped by the subject, so a caller
|
||||
// never reads or revokes another subject's consent. The state is computed,
|
||||
@@ -721,6 +743,11 @@ type Querier interface {
|
||||
// One bounded newest-first page. Both the organization scope and the tuple
|
||||
// cursor are applied before the limit.
|
||||
ListInvitations(ctx context.Context, arg ListInvitationsParams) ([]ListInvitationsRow, error)
|
||||
// The vectors of a need whose texts match the given digests of the
|
||||
// requirements snapshot that the search renders.
|
||||
ListNeedVectors(ctx context.Context, arg ListNeedVectorsParams) ([]ListNeedVectorsRow, error)
|
||||
// Needs and their current requirements snapshot for the backfill.
|
||||
ListNeedsAfter(ctx context.Context, arg ListNeedsAfterParams) ([]ListNeedsAfterRow, error)
|
||||
// List only the authenticated recipient's rows, optionally narrowed to one
|
||||
// organization context. The caller resolves current source visibility before
|
||||
// returning content.
|
||||
@@ -763,13 +790,22 @@ type Querier interface {
|
||||
// Owner-scoped newest-first list. It omits descriptions, complaint reason,
|
||||
// and event history. The tuple cursor matches the composite sort key.
|
||||
ListOwnedSupportCases(ctx context.Context, arg ListOwnedSupportCasesParams) ([]ListOwnedSupportCasesRow, error)
|
||||
// Candidates with a saved profile for the backfill, in identifier order
|
||||
// after a cursor. The job of a candidate who is not published removes the
|
||||
// stored vectors, so a backfill also cleans up after a closed card.
|
||||
ListProfileCandidatesAfter(ctx context.Context, arg ListProfileCandidatesAfterParams) ([]pgtype.UUID, error)
|
||||
// The digests of the stored rows of a subject and model, for the job that
|
||||
// decides whether anything changed.
|
||||
ListSemanticVectorDigests(ctx context.Context, arg ListSemanticVectorDigestsParams) ([]ListSemanticVectorDigestsRow, error)
|
||||
// Organization-facing anonymous candidate projection inputs. The calling
|
||||
// usecase has already authorized the active organization membership. This
|
||||
// single statement snapshot filters both revoked/unpublished C2 states and
|
||||
// candidates hidden from this organization before any profile value is read.
|
||||
// The projection reads only stack, declared role, and experience dates. It
|
||||
// deliberately excludes names, contacts, salary, location, soft skills,
|
||||
// employer names, summaries, and imported excerpts. The only assessment data
|
||||
// The projection reads only stack, declared role, experience dates, and
|
||||
// projects with the keys of their verified repositories. It deliberately
|
||||
// excludes names, contacts, salary, location, soft skills, employer names,
|
||||
// summaries, and imported excerpts; the repository address of a project stays
|
||||
// in the private input and never reaches the card. The only assessment data
|
||||
// is the current category (specialization and grade) of the separate current
|
||||
// category table; it carries no attempt, score, review, policy, or history.
|
||||
ListVisibleCandidateViewSources(ctx context.Context, organizationID pgtype.UUID) ([]ListVisibleCandidateViewSourcesRow, error)
|
||||
@@ -904,6 +940,10 @@ type Querier interface {
|
||||
LockPublicationForCandidatePreview(ctx context.Context, candidateID pgtype.UUID) (pgtype.UUID, error)
|
||||
// Locks the active registration C1 while its pending registration is applied.
|
||||
LockRegistrationConsentRecord(ctx context.Context, arg LockRegistrationConsentRecordParams) (LockRegistrationConsentRecordRow, error)
|
||||
// Serializes the vector jobs of one subject: a job takes this lock before it
|
||||
// reads the subject, so the job that runs last also read last and its vectors
|
||||
// describe the latest committed state. User requests never take it.
|
||||
LockSemanticSubject(ctx context.Context, lockKey int64) error
|
||||
// Serialize per-owner budget checks even before the first event exists.
|
||||
LockSupportCaseRequestBudget(ctx context.Context, ownerID pgtype.UUID) error
|
||||
// Lock and recheck one candidate's exact current publication only after the
|
||||
@@ -1080,6 +1120,8 @@ type Querier interface {
|
||||
// the job did not cause the failure. The same guard as the completion
|
||||
// applies, one (id, attempt) pair per job. It returns the IDs it released.
|
||||
ReleaseScheduledJobs(ctx context.Context, arg ReleaseScheduledJobsParams) ([]int64, error)
|
||||
// A new repository starts pending; a known one only records the request.
|
||||
RequestCandidateProjectRepositoryCheck(ctx context.Context, arg RequestCandidateProjectRepositoryCheckParams) error
|
||||
// Stores the replay record of a command. A record whose retention has passed
|
||||
// is replaced, so the key is accepted as new after the retention. A live
|
||||
// record is left as it is and nothing is returned; the caller then reads it
|
||||
@@ -1109,6 +1151,7 @@ type Querier interface {
|
||||
// grading policy is read from the immutable opening, and the guard trigger
|
||||
// compares it with the policy captured in the assigned result.
|
||||
SaveCandidateAssessmentCategory(ctx context.Context, arg SaveCandidateAssessmentCategoryParams) (int64, error)
|
||||
SaveCandidateProjectRepositoryCheck(ctx context.Context, arg SaveCandidateProjectRepositoryCheckParams) error
|
||||
SaveCompanyCardViewQuotaUsage(ctx context.Context, arg SaveCompanyCardViewQuotaUsageParams) error
|
||||
SaveInvitationCreationResult(ctx context.Context, arg SaveInvitationCreationResultParams) error
|
||||
// Stores the immutable domain snapshot of a successful create command. The
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: semantic.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deleteSemanticVectorsOfModel = `-- name: DeleteSemanticVectorsOfModel :exec
|
||||
|
||||
DELETE FROM semantic_vectors
|
||||
WHERE
|
||||
subject_kind = $1
|
||||
AND subject_id = $2
|
||||
AND model_id = $3
|
||||
AND model_revision = $4
|
||||
AND prompt_version = $5
|
||||
`
|
||||
|
||||
type DeleteSemanticVectorsOfModelParams struct {
|
||||
SubjectKind string
|
||||
SubjectID pgtype.UUID
|
||||
ModelID string
|
||||
ModelRevision string
|
||||
PromptVersion string
|
||||
}
|
||||
|
||||
// Stored embedding vectors. A candidate keeps one set of rows for a model:
|
||||
// the job deletes every other row of the candidate and model before it
|
||||
// inserts the new set, in one transaction. A need keeps the rows of its
|
||||
// latest computed requirements snapshot the same way.
|
||||
func (q *Queries) DeleteSemanticVectorsOfModel(ctx context.Context, arg DeleteSemanticVectorsOfModelParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteSemanticVectorsOfModel,
|
||||
arg.SubjectKind,
|
||||
arg.SubjectID,
|
||||
arg.ModelID,
|
||||
arg.ModelRevision,
|
||||
arg.PromptVersion,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteSemanticVectorsOfSubject = `-- name: DeleteSemanticVectorsOfSubject :exec
|
||||
DELETE FROM semantic_vectors
|
||||
WHERE subject_kind = $1 AND subject_id = $2
|
||||
`
|
||||
|
||||
type DeleteSemanticVectorsOfSubjectParams struct {
|
||||
SubjectKind string
|
||||
SubjectID pgtype.UUID
|
||||
}
|
||||
|
||||
// Removes every vector of a subject, of any model: a closed card or a need
|
||||
// without requirements keeps no derived data.
|
||||
func (q *Queries) DeleteSemanticVectorsOfSubject(ctx context.Context, arg DeleteSemanticVectorsOfSubjectParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteSemanticVectorsOfSubject, arg.SubjectKind, arg.SubjectID)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertSemanticVector = `-- name: InsertSemanticVector :exec
|
||||
INSERT INTO semantic_vectors (
|
||||
subject_kind, subject_id, candidate_id, need_id, model_id, model_revision,
|
||||
prompt_version, item_key, content_sha256, label_sha256, dimension, vector,
|
||||
computed_at
|
||||
) VALUES (
|
||||
$1, $2, $3,
|
||||
$4, $5, $6,
|
||||
$7, $8, $9,
|
||||
$10, $11, $12,
|
||||
$13
|
||||
)
|
||||
`
|
||||
|
||||
type InsertSemanticVectorParams struct {
|
||||
SubjectKind string
|
||||
SubjectID pgtype.UUID
|
||||
CandidateID pgtype.UUID
|
||||
NeedID pgtype.UUID
|
||||
ModelID string
|
||||
ModelRevision string
|
||||
PromptVersion string
|
||||
ItemKey string
|
||||
ContentSha256 []byte
|
||||
LabelSha256 []byte
|
||||
Dimension int32
|
||||
Vector []byte
|
||||
ComputedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSemanticVector(ctx context.Context, arg InsertSemanticVectorParams) error {
|
||||
_, err := q.db.Exec(ctx, insertSemanticVector,
|
||||
arg.SubjectKind,
|
||||
arg.SubjectID,
|
||||
arg.CandidateID,
|
||||
arg.NeedID,
|
||||
arg.ModelID,
|
||||
arg.ModelRevision,
|
||||
arg.PromptVersion,
|
||||
arg.ItemKey,
|
||||
arg.ContentSha256,
|
||||
arg.LabelSha256,
|
||||
arg.Dimension,
|
||||
arg.Vector,
|
||||
arg.ComputedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const listCandidateItemVectors = `-- name: ListCandidateItemVectors :many
|
||||
SELECT candidate_id, item_key, label_sha256, dimension, vector
|
||||
FROM semantic_vectors
|
||||
WHERE
|
||||
subject_kind = 'candidate'
|
||||
AND item_key <> 'whole'
|
||||
AND model_id = $1
|
||||
AND model_revision = $2
|
||||
AND prompt_version = $3
|
||||
AND candidate_id = ANY($4::uuid [])
|
||||
ORDER BY candidate_id, item_key
|
||||
`
|
||||
|
||||
type ListCandidateItemVectorsParams struct {
|
||||
ModelID string
|
||||
ModelRevision string
|
||||
PromptVersion string
|
||||
CandidateIds []pgtype.UUID
|
||||
}
|
||||
|
||||
type ListCandidateItemVectorsRow struct {
|
||||
CandidateID pgtype.UUID
|
||||
ItemKey string
|
||||
LabelSha256 []byte
|
||||
Dimension int32
|
||||
Vector []byte
|
||||
}
|
||||
|
||||
// The item vectors of the candidates that a search returns, at most a few
|
||||
// dozen candidates.
|
||||
func (q *Queries) ListCandidateItemVectors(ctx context.Context, arg ListCandidateItemVectorsParams) ([]ListCandidateItemVectorsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidateItemVectors,
|
||||
arg.ModelID,
|
||||
arg.ModelRevision,
|
||||
arg.PromptVersion,
|
||||
arg.CandidateIds,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListCandidateItemVectorsRow
|
||||
for rows.Next() {
|
||||
var i ListCandidateItemVectorsRow
|
||||
if err := rows.Scan(
|
||||
&i.CandidateID,
|
||||
&i.ItemKey,
|
||||
&i.LabelSha256,
|
||||
&i.Dimension,
|
||||
&i.Vector,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listCandidateWholeVectors = `-- name: ListCandidateWholeVectors :many
|
||||
SELECT candidate_id, dimension, vector
|
||||
FROM semantic_vectors
|
||||
WHERE
|
||||
subject_kind = 'candidate'
|
||||
AND item_key = 'whole'
|
||||
AND model_id = $1
|
||||
AND model_revision = $2
|
||||
AND prompt_version = $3
|
||||
AND candidate_id = ANY($4::uuid [])
|
||||
ORDER BY candidate_id
|
||||
`
|
||||
|
||||
type ListCandidateWholeVectorsParams struct {
|
||||
ModelID string
|
||||
ModelRevision string
|
||||
PromptVersion string
|
||||
CandidateIds []pgtype.UUID
|
||||
}
|
||||
|
||||
type ListCandidateWholeVectorsRow struct {
|
||||
CandidateID pgtype.UUID
|
||||
Dimension int32
|
||||
Vector []byte
|
||||
}
|
||||
|
||||
// The whole-view vectors of the candidates of one search.
|
||||
func (q *Queries) ListCandidateWholeVectors(ctx context.Context, arg ListCandidateWholeVectorsParams) ([]ListCandidateWholeVectorsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidateWholeVectors,
|
||||
arg.ModelID,
|
||||
arg.ModelRevision,
|
||||
arg.PromptVersion,
|
||||
arg.CandidateIds,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListCandidateWholeVectorsRow
|
||||
for rows.Next() {
|
||||
var i ListCandidateWholeVectorsRow
|
||||
if err := rows.Scan(&i.CandidateID, &i.Dimension, &i.Vector); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listNeedVectors = `-- name: ListNeedVectors :many
|
||||
SELECT item_key, content_sha256, dimension, vector
|
||||
FROM semantic_vectors
|
||||
WHERE
|
||||
subject_kind = 'need'
|
||||
AND need_id = $1
|
||||
AND model_id = $2
|
||||
AND model_revision = $3
|
||||
AND prompt_version = $4
|
||||
AND content_sha256 = ANY($5::bytea [])
|
||||
ORDER BY item_key
|
||||
`
|
||||
|
||||
type ListNeedVectorsParams struct {
|
||||
NeedID pgtype.UUID
|
||||
ModelID string
|
||||
ModelRevision string
|
||||
PromptVersion string
|
||||
ContentDigests [][]byte
|
||||
}
|
||||
|
||||
type ListNeedVectorsRow struct {
|
||||
ItemKey string
|
||||
ContentSha256 []byte
|
||||
Dimension int32
|
||||
Vector []byte
|
||||
}
|
||||
|
||||
// The vectors of a need whose texts match the given digests of the
|
||||
// requirements snapshot that the search renders.
|
||||
func (q *Queries) ListNeedVectors(ctx context.Context, arg ListNeedVectorsParams) ([]ListNeedVectorsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listNeedVectors,
|
||||
arg.NeedID,
|
||||
arg.ModelID,
|
||||
arg.ModelRevision,
|
||||
arg.PromptVersion,
|
||||
arg.ContentDigests,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListNeedVectorsRow
|
||||
for rows.Next() {
|
||||
var i ListNeedVectorsRow
|
||||
if err := rows.Scan(
|
||||
&i.ItemKey,
|
||||
&i.ContentSha256,
|
||||
&i.Dimension,
|
||||
&i.Vector,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listNeedsAfter = `-- name: ListNeedsAfter :many
|
||||
SELECT id, organization_id, requirements_version
|
||||
FROM organization_needs
|
||||
WHERE id > $1
|
||||
ORDER BY id
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type ListNeedsAfterParams struct {
|
||||
AfterID pgtype.UUID
|
||||
PageSize int32
|
||||
}
|
||||
|
||||
type ListNeedsAfterRow struct {
|
||||
ID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
RequirementsVersion int64
|
||||
}
|
||||
|
||||
// Needs and their current requirements snapshot for the backfill.
|
||||
func (q *Queries) ListNeedsAfter(ctx context.Context, arg ListNeedsAfterParams) ([]ListNeedsAfterRow, error) {
|
||||
rows, err := q.db.Query(ctx, listNeedsAfter, arg.AfterID, arg.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListNeedsAfterRow
|
||||
for rows.Next() {
|
||||
var i ListNeedsAfterRow
|
||||
if err := rows.Scan(&i.ID, &i.OrganizationID, &i.RequirementsVersion); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listProfileCandidatesAfter = `-- name: ListProfileCandidatesAfter :many
|
||||
SELECT profiles.user_id
|
||||
FROM candidate_profiles AS profiles
|
||||
WHERE profiles.user_id > $1
|
||||
ORDER BY profiles.user_id
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type ListProfileCandidatesAfterParams struct {
|
||||
AfterID pgtype.UUID
|
||||
PageSize int32
|
||||
}
|
||||
|
||||
// Candidates with a saved profile for the backfill, in identifier order
|
||||
// after a cursor. The job of a candidate who is not published removes the
|
||||
// stored vectors, so a backfill also cleans up after a closed card.
|
||||
func (q *Queries) ListProfileCandidatesAfter(ctx context.Context, arg ListProfileCandidatesAfterParams) ([]pgtype.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, listProfileCandidatesAfter, arg.AfterID, arg.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []pgtype.UUID
|
||||
for rows.Next() {
|
||||
var user_id pgtype.UUID
|
||||
if err := rows.Scan(&user_id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, user_id)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listSemanticVectorDigests = `-- name: ListSemanticVectorDigests :many
|
||||
SELECT item_key, content_sha256
|
||||
FROM semantic_vectors
|
||||
WHERE
|
||||
subject_kind = $1
|
||||
AND subject_id = $2
|
||||
AND model_id = $3
|
||||
AND model_revision = $4
|
||||
AND prompt_version = $5
|
||||
ORDER BY item_key, content_sha256
|
||||
`
|
||||
|
||||
type ListSemanticVectorDigestsParams struct {
|
||||
SubjectKind string
|
||||
SubjectID pgtype.UUID
|
||||
ModelID string
|
||||
ModelRevision string
|
||||
PromptVersion string
|
||||
}
|
||||
|
||||
type ListSemanticVectorDigestsRow struct {
|
||||
ItemKey string
|
||||
ContentSha256 []byte
|
||||
}
|
||||
|
||||
// The digests of the stored rows of a subject and model, for the job that
|
||||
// decides whether anything changed.
|
||||
func (q *Queries) ListSemanticVectorDigests(ctx context.Context, arg ListSemanticVectorDigestsParams) ([]ListSemanticVectorDigestsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listSemanticVectorDigests,
|
||||
arg.SubjectKind,
|
||||
arg.SubjectID,
|
||||
arg.ModelID,
|
||||
arg.ModelRevision,
|
||||
arg.PromptVersion,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListSemanticVectorDigestsRow
|
||||
for rows.Next() {
|
||||
var i ListSemanticVectorDigestsRow
|
||||
if err := rows.Scan(&i.ItemKey, &i.ContentSha256); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const lockSemanticSubject = `-- name: LockSemanticSubject :exec
|
||||
SELECT pg_advisory_xact_lock($1::bigint)
|
||||
`
|
||||
|
||||
// Serializes the vector jobs of one subject: a job takes this lock before it
|
||||
// reads the subject, so the job that runs last also read last and its vectors
|
||||
// describe the latest committed state. User requests never take it.
|
||||
func (q *Queries) LockSemanticSubject(ctx context.Context, lockKey int64) error {
|
||||
_, err := q.db.Exec(ctx, lockSemanticSubject, lockKey)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user