From 2aa81df9614651469927b084d2889f0a9534d1aa Mon Sep 17 00:00:00 2001 From: Apher Date: Thu, 23 Jul 2026 02:54:38 +0000 Subject: [PATCH] Add argument matching --- src/server.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/server.js b/src/server.js index 671f357..4928503 100644 --- a/src/server.js +++ b/src/server.js @@ -72,28 +72,45 @@ async function classifyIntent(text) { const INTENTS = await getIntents(); - let best = { + let bestIntent = { name: "unknown", confidence: 0.5, matched: null, + argument: null }; for (const intent of INTENTS) { for (const example of intent.examples) { const exampleEmbedding = await embed(example); - const score = cosineSimilarity(inputEmbedding, exampleEmbedding); + const intentScore = cosineSimilarity(inputEmbedding, exampleEmbedding); - if (score > best.confidence) { - best = { + if (intentScore > best.confidence) { + bestIntent = { name: intent.name, - confidence: score, + confidence: intentScore, matched: example, + argument: intent.arguments }; } } } - return best; + let bestArgumentScore = 0.5 + + if (best.arguments) { + for (const argument of best.arguments) { + const argumentEmbedding = await embed(argument); + const argumentScore = cosineSimilarity(inputEmbedding, argumentEmbedding); + + if (argumentScore > bestArgumentScore) { + bestArgumentScore = argumentScore; + + bestIntent.argument = argument + } + } + } + + return bestIntent; } async function handleIntent(streamKey, msg) {