@@ -1934,22 +1934,21 @@ tinyDancer
19341934 } ) ;
19351935
19361936tinyDancer
1937- . command ( 'route <model>' )
1938- . description ( 'Route a query through a trained model. --query: JSON embedding array; --candidates: JSON file of [{id, embedding}]' )
1939- . requiredOption ( '--query <json>' , 'Query embedding as a JSON array or @file' )
1940- . requiredOption ( '--candidates <file>' , 'Candidates JSON file: [{ id, embedding }]' )
1941- . option ( '--threshold <n>' , 'Confidence threshold' , '0.85' )
1937+ . command ( 'score <model>' )
1938+ . description ( 'Score a query embedding with a trained model. High = the cheap model is good enough (route cheap)' )
1939+ . requiredOption ( '--query <json>' , 'Query embedding as a JSON array or @file (length must match the model input dim)' )
1940+ . option ( '--threshold <n>' , 'Decision threshold for cheap-vs-strong' , '0.5' )
19421941 . action ( async ( model , options ) => {
19431942 const td = loadTinyDancer ( ) ;
1944- const queryEmbedding = JSON . parse ( options . query . startsWith ( '@' ) ? fs . readFileSync ( options . query . slice ( 1 ) , 'utf8' ) : options . query ) ;
1945- const candidates = JSON . parse ( fs . readFileSync ( options . candidates , 'utf8' ) ) ;
1946- const router = new td . Router ( { modelPath : model , confidenceThreshold : parseFloat ( options . threshold ) } ) ;
1947- const resp = await router . route ( { queryEmbedding , candidates } ) ;
1948- console . log ( chalk . cyan ( '\n Routing decisions (best first):' ) ) ;
1949- for ( const d of resp . decisions ) {
1950- console . log ( ` ${ chalk . white ( d . candidateId ) } conf= ${ d . confidence . toFixed ( 3 ) } light= ${ d . useLightweight } unc= ${ d . uncertainty . toFixed ( 3 ) } ` ) ;
1951- }
1952- console . log ( chalk . gray ( ` inference ${ resp . inferenceTimeUs } µs over ${ resp . candidatesProcessed } candidates\n` ) ) ;
1943+ const embedding = JSON . parse ( options . query . startsWith ( '@' ) ? fs . readFileSync ( options . query . slice ( 1 ) , 'utf8' ) : options . query ) ;
1944+ const s = await td . score ( model , embedding ) ;
1945+ const threshold = parseFloat ( options . threshold ) ;
1946+ console . log ( chalk . cyan ( `\n score = ${ s . toFixed ( 4 ) } ` ) ) ;
1947+ console . log (
1948+ s >= threshold
1949+ ? chalk . green ( ' → route to the CHEAP model (good enough)\n' )
1950+ : chalk . yellow ( ' → route to a STRONGER model\n' )
1951+ ) ;
19531952 } ) ;
19541953
19551954tinyDancer
@@ -1960,7 +1959,7 @@ tinyDancer
19601959 const td = require ( '@ruvector/tiny-dancer' ) ;
19611960 console . log ( chalk . green ( `\n @ruvector/tiny-dancer ${ td . version ( ) } — ${ td . hello ( ) } ` ) ) ;
19621961 console . log ( chalk . gray ( ' train: npx ruvector tiny-dancer train <draco.json> --out model.safetensors' ) ) ;
1963- console . log ( chalk . gray ( ' route : npx ruvector tiny-dancer route <model.safetensors> --query <emb> --candidates <file >\n' ) ) ;
1962+ console . log ( chalk . gray ( ' score : npx ruvector tiny-dancer score <model.safetensors> --query <embedding.json >\n' ) ) ;
19641963 } catch {
19651964 console . log ( chalk . yellow ( '\n @ruvector/tiny-dancer not installed. npm install @ruvector/tiny-dancer\n' ) ) ;
19661965 }
0 commit comments