Skip to content

Commit

Permalink
cleanup sample
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 17, 2024
1 parent da1b97a commit 523b945
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions packages/sample/genaisrc/transformers-rank.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ const featureExtractor = await pipeline('feature-extraction');
// Function to rank documents
async function rank(query: string, files: WorkspaceFile[]) {
const documents = files.map(({ content }) => content);
// Extract features for the query
const queryEmbedding = (await featureExtractor(query)).tolist()[0][0]
console.log(queryEmbedding)
// Extract features for each document and compute similarity
const similarities = await Promise.all(documents.map(async (doc, i) => {
const docEmbedding = (await featureExtractor(doc)).tolist()[0][0]
const score = cos_sim(queryEmbedding, docEmbedding);
return { file: files[i], score };
}));

// Sort documents by similarity score in descending order
similarities.sort((a, b) => b.score - a.score);

return similarities
}

Expand Down

0 comments on commit 523b945

Please sign in to comment.