mirror of
https://github.com/open-webui/open-webui
synced 2024-11-08 01:30:40 +00:00
only show relevance pertentage score if distances are in cosinus silimarity range
This commit is contained in:
parent
741230bcdb
commit
9d4d96429f
@ -11,19 +11,20 @@
|
|||||||
let mergedDocuments = [];
|
let mergedDocuments = [];
|
||||||
|
|
||||||
function calculatePercentage(distance) {
|
function calculatePercentage(distance) {
|
||||||
return Math.max(0, Math.min(100, (1 - distance / 2) * 100));
|
if (distance < 0) return 100;
|
||||||
|
if (distance > 1) return 0;
|
||||||
|
return Math.round((1 - distance) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRelevanceColor(percentage) {
|
function shouldShowPercentage(documents) {
|
||||||
if (percentage >= 80)
|
const validDistances = documents.filter(
|
||||||
return 'bg-green-200 dark:bg-green-800 text-green-800 dark:text-green-200';
|
(d) => d.distance !== undefined && d.distance >= 0 && d.distance <= 1
|
||||||
if (percentage >= 60)
|
);
|
||||||
return 'bg-yellow-200 dark:bg-yellow-800 text-yellow-800 dark:text-yellow-200';
|
return validDistances.length >= 2;
|
||||||
if (percentage >= 40)
|
|
||||||
return 'bg-orange-200 dark:bg-orange-800 text-orange-800 dark:text-orange-200';
|
|
||||||
return 'bg-red-200 dark:bg-red-800 text-red-800 dark:text-red-200';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: showPercentage = shouldShowPercentage(mergedDocuments);
|
||||||
|
|
||||||
$: if (citation) {
|
$: if (citation) {
|
||||||
mergedDocuments = citation.document?.map((c, i) => {
|
mergedDocuments = citation.document?.map((c, i) => {
|
||||||
return {
|
return {
|
||||||
@ -104,15 +105,23 @@
|
|||||||
<div class="text-sm font-medium dark:text-gray-300 mt-2">
|
<div class="text-sm font-medium dark:text-gray-300 mt-2">
|
||||||
{$i18n.t('Relevance')}
|
{$i18n.t('Relevance')}
|
||||||
</div>
|
</div>
|
||||||
|
{#if showPercentage}
|
||||||
{@const percentage = calculatePercentage(document.distance)}
|
{@const percentage = calculatePercentage(document.distance)}
|
||||||
<div class="text-sm my-1 dark:text-gray-400 flex items-center gap-2">
|
<div class="text-sm my-1 dark:text-gray-400 flex items-center gap-2">
|
||||||
<span class={`px-1 rounded font-medium ${getRelevanceColor(percentage)}`}>
|
<span class={`px-1 rounded font-medium ${getRelevanceColor(percentage)}`}>
|
||||||
{percentage.toFixed(0)}%
|
{percentage}%
|
||||||
</span>
|
</span>
|
||||||
<span class="text-gray-500 dark:text-gray-500"
|
<span class="text-gray-500 dark:text-gray-500"
|
||||||
>({document.distance.toFixed(4)})</span
|
>({document.distance.toFixed(4)})</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="text-sm my-1 dark:text-gray-400 flex items-center gap-2">
|
||||||
|
<span class="text-gray-500 dark:text-gray-500">
|
||||||
|
{document.distance.toFixed(4)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<div class="text-sm dark:text-gray-400">
|
<div class="text-sm dark:text-gray-400">
|
||||||
|
Loading…
Reference in New Issue
Block a user