Skip to content

Commit

Permalink
More logging in semanticSort, which helps see why it isn't swapping v…
Browse files Browse the repository at this point in the history
…ery often.

Part of #688.
  • Loading branch information
jkomoros committed Apr 8, 2024
1 parent 50889da commit 1262a5d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion functions/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,25 @@ const swapIfBetter = (index: number, cards : CardID[], vectors: Record<CardID, E
const d = vectors[dID];

//This might happen for cards that don't have embeddings yet.
if (!a || !b || !c || !d) return false;
if (!a) {
console.warn(`No embedding for ${aID}`);
return false;
}

if (!b) {
console.warn(`No embedding for ${bID}`);
return false;
}

if (!c) {
console.warn(`No embedding for ${cID}`);
return false;
}

if (!d) {
console.warn(`No embedding for ${dID}`);
return false;
}

//b anc c will be next to each other no matter what. We're seeing which is
//better, similarity(a,b) + similarity(c,d) (in which case there should be
Expand All @@ -558,7 +576,11 @@ const swapIfBetter = (index: number, cards : CardID[], vectors: Record<CardID, E
const simAC = cosineSimilarity(a, c);
const simBD = cosineSimilarity(b, d);

console.log(`Comparing ${bID} and ${cID} with ${simAB} + ${simCD} (${simAB + simCD}) vs ${simAC} + ${simBD} (${simAC + simBD})`);

if (simAB + simCD >= simAC + simBD) return false;

console.log('Swapping');

//A swap is better!
const temp = cards[index];
Expand Down

0 comments on commit 1262a5d

Please sign in to comment.