feat(matching): rank with semantic embeddings and explain matches by evidence

This commit is contained in:
shira committed 2026-10-11 10:39:46 +03:00
1 parent facc1789b1
commit 24b64d698a
215 files changed
+16951 -327

No files matched your search

+29 -7
View File
@@ -2,9 +2,11 @@
-- 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.
-- name: ListVisibleCandidateViewSources :many
@@ -64,11 +66,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 (
@@ -202,11 +214,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 = sqlc.arg(candidate_id)
@@ -0,0 +1,62 @@
-- Server checks of the GitHub repositories that candidate projects link.
-- Every statement is scoped by the candidate.
-- 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 = sqlc.arg(candidate_id)
ORDER BY repository_key;
-- 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 = sqlc.arg(candidate_id) AND repository_key = sqlc.arg(repository_key)
FOR UPDATE;
-- A new repository starts pending; a known one only records the request.
-- name: RequestCandidateProjectRepositoryCheck :exec
INSERT INTO candidate_project_repositories (
candidate_id, repository_key, state, requested_at, created_at, updated_at
) VALUES (
sqlc.arg(candidate_id), sqlc.arg(repository_key), 'pending', sqlc.arg(requested_at),
sqlc.arg(requested_at), sqlc.arg(requested_at)
)
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);
-- name: SaveCandidateProjectRepositoryCheck :exec
UPDATE candidate_project_repositories
SET
state = sqlc.arg(state),
github_id = sqlc.narg(github_id),
description = sqlc.narg(description),
topics = sqlc.arg(topics),
languages = sqlc.arg(languages),
readme_excerpt = sqlc.narg(readme_excerpt),
repository_etag = sqlc.narg(repository_etag),
readme_etag = sqlc.narg(readme_etag),
failure_class = sqlc.narg(failure_class),
checked_at = sqlc.arg(checked_at),
updated_at = GREATEST(updated_at, sqlc.arg(checked_at))
WHERE candidate_id = sqlc.arg(candidate_id) AND repository_key = sqlc.arg(repository_key);
-- Removes the checks of repositories that no project links any more.
-- name: DeleteUnlinkedCandidateProjectRepositories :exec
DELETE FROM candidate_project_repositories
WHERE
candidate_id = sqlc.arg(candidate_id)
AND NOT (repository_key = ANY(sqlc.arg(linked_keys)::text []));
-- The latest check request of a candidate, for the per-candidate limit.
-- name: GetLatestRepositoryCheckRequest :one
SELECT MAX(requested_at)::timestamptz AS requested_at
FROM candidate_project_repositories
WHERE candidate_id = sqlc.arg(candidate_id);
+110
View File
@@ -0,0 +1,110 @@
-- 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.
-- name: DeleteSemanticVectorsOfModel :exec
DELETE FROM semantic_vectors
WHERE
subject_kind = sqlc.arg(subject_kind)
AND subject_id = sqlc.arg(subject_id)
AND model_id = sqlc.arg(model_id)
AND model_revision = sqlc.arg(model_revision)
AND prompt_version = sqlc.arg(prompt_version);
-- Removes every vector of a subject, of any model: a closed card or a need
-- without requirements keeps no derived data.
-- name: DeleteSemanticVectorsOfSubject :exec
DELETE FROM semantic_vectors
WHERE subject_kind = sqlc.arg(subject_kind) AND subject_id = sqlc.arg(subject_id);
-- 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 (
sqlc.arg(subject_kind), sqlc.arg(subject_id), sqlc.narg(candidate_id),
sqlc.narg(need_id), sqlc.arg(model_id), sqlc.arg(model_revision),
sqlc.arg(prompt_version), sqlc.arg(item_key), sqlc.arg(content_sha256),
sqlc.narg(label_sha256), sqlc.arg(dimension), sqlc.arg(vector),
sqlc.arg(computed_at)
);
-- The digests of the stored rows of a subject and model, for the job that
-- decides whether anything changed.
-- name: ListSemanticVectorDigests :many
SELECT item_key, content_sha256
FROM semantic_vectors
WHERE
subject_kind = sqlc.arg(subject_kind)
AND subject_id = sqlc.arg(subject_id)
AND model_id = sqlc.arg(model_id)
AND model_revision = sqlc.arg(model_revision)
AND prompt_version = sqlc.arg(prompt_version)
ORDER BY item_key, content_sha256;
-- The whole-view vectors of the candidates of one search.
-- name: ListCandidateWholeVectors :many
SELECT candidate_id, dimension, vector
FROM semantic_vectors
WHERE
subject_kind = 'candidate'
AND item_key = 'whole'
AND model_id = sqlc.arg(model_id)
AND model_revision = sqlc.arg(model_revision)
AND prompt_version = sqlc.arg(prompt_version)
AND candidate_id = ANY(sqlc.arg(candidate_ids)::uuid [])
ORDER BY candidate_id;
-- The item vectors of the candidates that a search returns, at most a few
-- dozen candidates.
-- 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 = sqlc.arg(model_id)
AND model_revision = sqlc.arg(model_revision)
AND prompt_version = sqlc.arg(prompt_version)
AND candidate_id = ANY(sqlc.arg(candidate_ids)::uuid [])
ORDER BY candidate_id, item_key;
-- The vectors of a need whose texts match the given digests of the
-- requirements snapshot that the search renders.
-- name: ListNeedVectors :many
SELECT item_key, content_sha256, dimension, vector
FROM semantic_vectors
WHERE
subject_kind = 'need'
AND need_id = sqlc.arg(need_id)
AND model_id = sqlc.arg(model_id)
AND model_revision = sqlc.arg(model_revision)
AND prompt_version = sqlc.arg(prompt_version)
AND content_sha256 = ANY(sqlc.arg(content_digests)::bytea [])
ORDER BY item_key;
-- 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.
-- name: ListProfileCandidatesAfter :many
SELECT profiles.user_id
FROM candidate_profiles AS profiles
WHERE profiles.user_id > sqlc.arg(after_id)
ORDER BY profiles.user_id
LIMIT sqlc.arg(page_size);
-- Needs and their current requirements snapshot for the backfill.
-- name: ListNeedsAfter :many
SELECT id, organization_id, requirements_version
FROM organization_needs
WHERE id > sqlc.arg(after_id)
ORDER BY id
LIMIT sqlc.arg(page_size);
-- 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.
-- name: LockSemanticSubject :exec
SELECT pg_advisory_xact_lock(sqlc.arg(lock_key)::bigint);