We've got a workspace from the previous lesson. This lesson queries it.
ragSearch({ modelId, workspace, query, topK }) returns an array of { score, content }. The modelId must match the one used at ingest, because different models put vectors in different spaces and cross-model similarity scores are meaningless.
Result is sorted by score descending. The call passes all four options to ragSearch:
const results = await ragSearch({
modelId,
workspace,
query,
topK: 3,
});slice(0, 80) clips the preview to one line. 80 chars is arbitrary, pick what fits your terminal. Also, the loop uses toFixed(4) for the score so keep that in mind:
let i = 0;
for (const result of results) {
console.log(`Score ${result.score.toFixed(4)}: ${result.content.slice(0, 80)}...`);
i += 1;
}Each result carries the same content we put in, with a score field added (higher means more similar).
Note:
topKis an integer, not a "score threshold". If you want to filter by confidence, sort byscoreand drop anything below your threshold.
Question 1 of 2
What has to be true about the modelId passed to ragSearch for similarity scores to mean anything?
Question 2 of 2
What does topK control on a ragSearch call?
Run your code, check your answer, or ask a question. It all shows up here.