mirror of
https://github.com/open-webui/open-webui
synced 2025-04-27 01:32:43 +00:00
fix: do not show relevances it you have mixed collections (cosine + l2)
This commit is contained in:
parent
33c3dbd9fa
commit
79c834d0e4
@ -11,18 +11,34 @@
|
|||||||
|
|
||||||
let _citations = [];
|
let _citations = [];
|
||||||
let showPercentage = false;
|
let showPercentage = false;
|
||||||
|
let showRelevance = true;
|
||||||
|
|
||||||
let showCitationModal = false;
|
let showCitationModal = false;
|
||||||
let selectedCitation: any = null;
|
let selectedCitation: any = null;
|
||||||
let isCollapsibleOpen = false;
|
let isCollapsibleOpen = false;
|
||||||
|
|
||||||
|
function calculateShowRelevance(citations: any[]) {
|
||||||
|
const distances = citations.flatMap((citation) => citation.distances ?? []);
|
||||||
|
const inRange = distances.filter((d) => d !== undefined && d >= -1 && d <= 1).length;
|
||||||
|
const outOfRange = distances.filter((d) => d !== undefined && (d < -1 || d > 1)).length;
|
||||||
|
|
||||||
|
if (distances.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(inRange === distances.length - 1 && outOfRange === 1) ||
|
||||||
|
(outOfRange === distances.length - 1 && inRange === 1)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function shouldShowPercentage(citations: any[]) {
|
function shouldShowPercentage(citations: any[]) {
|
||||||
return citations.every(
|
const distances = citations.flatMap((citation) => citation.distances ?? []);
|
||||||
(citation) =>
|
return distances.every((d) => d !== undefined && d >= -1 && d <= 1);
|
||||||
citation.distances &&
|
|
||||||
citation.distances.length > 0 &&
|
|
||||||
citation.distances.every((d: number) => d !== undefined && d >= -1 && d <= 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
@ -60,11 +76,17 @@
|
|||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
showRelevance = calculateShowRelevance(_citations);
|
||||||
showPercentage = shouldShowPercentage(_citations);
|
showPercentage = shouldShowPercentage(_citations);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CitationsModal bind:show={showCitationModal} citation={selectedCitation} {showPercentage} />
|
<CitationsModal
|
||||||
|
bind:show={showCitationModal}
|
||||||
|
citation={selectedCitation}
|
||||||
|
{showPercentage}
|
||||||
|
{showRelevance}
|
||||||
|
/>
|
||||||
|
|
||||||
{#if _citations.length > 0}
|
{#if _citations.length > 0}
|
||||||
<div class="mt-1 mb-2 w-full flex gap-1 items-center flex-wrap">
|
<div class="mt-1 mb-2 w-full flex gap-1 items-center flex-wrap">
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
export let show = false;
|
export let show = false;
|
||||||
export let citation;
|
export let citation;
|
||||||
export let showPercentage = false;
|
export let showPercentage = false;
|
||||||
|
export let showRelevance = true;
|
||||||
|
|
||||||
let mergedDocuments = [];
|
let mergedDocuments = [];
|
||||||
|
|
||||||
@ -103,6 +104,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
{#if showRelevance}
|
||||||
<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>
|
||||||
@ -133,6 +135,7 @@
|
|||||||
{$i18n.t('No distance available')}
|
{$i18n.t('No distance available')}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<div class="text-sm dark:text-gray-400">
|
<div class="text-sm dark:text-gray-400">
|
||||||
{$i18n.t('No source available')}
|
{$i18n.t('No source available')}
|
||||||
|
Loading…
Reference in New Issue
Block a user