Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdavis committed Jan 9, 2025
1 parent 755bfca commit 4909768
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions apps/registry/pages/api/jobs-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,39 @@ export default async function handler(req, res) {
target: job.uuid,
value: job.similarity,
})),
...otherJobs
.map((lessRelevantJob) => {
const lessRelevantVector = JSON.parse(lessRelevantJob.embedding_v5);
const mostSimilarJob = [...topJobs].reduce(
(best, current) => {
const similarity = cosineSimilarity(
lessRelevantVector,
JSON.parse(current.embedding_v5),
);
return similarity > best.similarity
? { job: current, similarity }
: best;
},
{ job: null, similarity: -1 },
);

return mostSimilarJob.job
? {
source: mostSimilarJob.job.uuid,
target: lessRelevantJob.uuid,
value: mostSimilarJob.similarity,
}
: null;
})
.filter(Boolean),
// Process other jobs sequentially, each one only looking at previously processed jobs
...otherJobs.reduce((links, lessRelevantJob, index) => {
const lessRelevantVector = JSON.parse(lessRelevantJob.embedding_v5);

// Jobs to compare against: top jobs + already processed less relevant jobs
const availableJobs = [
...topJobs,
...otherJobs.slice(0, index)
];

const mostSimilarJob = availableJobs.reduce(
(best, current) => {
const similarity = cosineSimilarity(
lessRelevantVector,
JSON.parse(current.embedding_v5),
);
return similarity > best.similarity
? { job: current, similarity }
: best;
},
{ job: null, similarity: -1 },
);

if (mostSimilarJob.job) {
links.push({
source: mostSimilarJob.job.uuid,
target: lessRelevantJob.uuid,
value: mostSimilarJob.similarity,
});
}

return links;
}, []),
],
};

Expand Down

0 comments on commit 4909768

Please sign in to comment.