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: "How do I make a peanut butter sandwich?",
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.
ragSearch({ modelId, workspace, query, topK }) and store the results.for (const result of results) loop that console.logs result.score and the first 80 chars of result.content.$ Run your code to see results
$