From bd0ddfbb24705995c84d7dd9ff7e1ada9b8f4d74 Mon Sep 17 00:00:00 2001 From: DominikDoom Date: Mon, 2 Oct 2023 00:16:58 +0200 Subject: [PATCH] Fix embeddings not at top (only affecting the "include embeddings in normal results" option) --- javascript/tagAutocomplete.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 1d0048d..19714f0 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -1158,8 +1158,14 @@ async function autocomplete(textArea, prompt, fixedTag = null) { const aUseStats = counts.find(c => c.name === aName && c.type === a.type); const bUseStats = counts.find(c => c.name === bName && c.type === b.type); - const aWeight = calculateUsageBias(a.count || 0, aUseStats ? aUseStats.count : 0); - const bWeight = calculateUsageBias(b.count || 0, bUseStats ? bUseStats.count : 0); + let aNoCountFallback = 0; + let bNoCountFallback = 0; + if (TAC_CFG.includeEmbeddingsInNormalResults) { + aNoCountFallback = a.type === ResultType.embedding ? Infinity : 0; + bNoCountFallback = b.type === ResultType.embedding ? Infinity : 0; + } + const aWeight = calculateUsageBias(a.count || aNoCountFallback, aUseStats ? aUseStats.count : 0); + const bWeight = calculateUsageBias(b.count || bNoCountFallback, bUseStats ? bUseStats.count : 0); return bWeight - aWeight; });