Fix false-positive validation error where DBSF (Distribution-Based Score Fusion) correctly produces scores > 1.0 but SearchResult validation incorrectly rejected them. **Root Cause**: SearchResult.__post_init__() enforced scores in [0.0, 1.0] range, but DBSF sums normalized scores from multiple retrieval systems (dense semantic + sparse BM25), resulting in scores like 1.55 when both systems strongly agree a document is relevant. **Changes**: - Relaxed validation to allow any score ≥ 0.0 (algorithms.py:147-157) - Updated SearchResult and SemanticSearchResult documentation to explain score ranges for RRF ([0.0, 1.0]) vs DBSF (unbounded) - Added comprehensive test coverage for both fusion methods - Added DBSF fusion option to vector visualization UI - Updated viz routes and vizApp() to support fusion parameter selection **Testing**: All 157 unit tests pass, type checking passes, ruff passes Fixes error: "Configuration error: Score must be between 0.0 and 1.0, got 1.1528953" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
324 lines
12 KiB
HTML
324 lines
12 KiB
HTML
<style>
|
|
.viz-card {
|
|
background: white;
|
|
border-radius: 8px;
|
|
padding: 20px;
|
|
margin-bottom: 20px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
.viz-controls {
|
|
margin-bottom: 20px;
|
|
}
|
|
.viz-control-row {
|
|
display: grid;
|
|
grid-template-columns: 2fr 1fr auto;
|
|
gap: 12px;
|
|
margin-bottom: 12px;
|
|
align-items: end;
|
|
}
|
|
.viz-control-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
.viz-control-group label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
font-weight: 500;
|
|
color: #333;
|
|
}
|
|
.viz-control-group input[type="text"],
|
|
.viz-control-group input[type="number"],
|
|
.viz-control-group select {
|
|
width: 100%;
|
|
padding: 8px 12px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
font-size: 14px;
|
|
}
|
|
.viz-control-group input[type="range"] {
|
|
width: 100%;
|
|
}
|
|
.viz-control-group select[multiple] {
|
|
min-height: 100px;
|
|
}
|
|
.viz-weight-display {
|
|
display: inline-block;
|
|
min-width: 40px;
|
|
text-align: right;
|
|
color: #666;
|
|
}
|
|
.viz-btn {
|
|
background: #0066cc;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
}
|
|
.viz-btn:hover {
|
|
background: #0052a3;
|
|
}
|
|
.viz-btn-secondary {
|
|
background: #6c757d;
|
|
color: white;
|
|
border: none;
|
|
padding: 6px 12px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 13px;
|
|
margin-bottom: 12px;
|
|
}
|
|
.viz-btn-secondary:hover {
|
|
background: #5a6268;
|
|
}
|
|
#viz-plot-container {
|
|
width: 100%;
|
|
height: 600px;
|
|
position: relative;
|
|
}
|
|
#viz-plot {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
.viz-loading {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #666;
|
|
}
|
|
.viz-loading-overlay {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: white;
|
|
color: #666;
|
|
}
|
|
.viz-no-results {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #666;
|
|
font-style: italic;
|
|
}
|
|
.viz-advanced-section {
|
|
margin-top: 16px;
|
|
padding: 16px;
|
|
background: #f8f9fa;
|
|
border-radius: 4px;
|
|
border: 1px solid #dee2e6;
|
|
}
|
|
.viz-advanced-grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 20px;
|
|
}
|
|
.viz-info-box {
|
|
background: #e3f2fd;
|
|
border-left: 4px solid #2196f3;
|
|
padding: 12px;
|
|
margin-bottom: 20px;
|
|
font-size: 14px;
|
|
}
|
|
.chunk-toggle-btn {
|
|
background: #6c757d;
|
|
color: white;
|
|
border: none;
|
|
padding: 4px 10px;
|
|
border-radius: 3px;
|
|
cursor: pointer;
|
|
font-size: 12px;
|
|
margin-top: 6px;
|
|
}
|
|
.chunk-toggle-btn:hover {
|
|
background: #5a6268;
|
|
}
|
|
.chunk-context {
|
|
background: #f8f9fa;
|
|
border: 1px solid #dee2e6;
|
|
border-radius: 4px;
|
|
padding: 12px;
|
|
margin-top: 8px;
|
|
font-family: monospace;
|
|
font-size: 13px;
|
|
line-height: 1.6;
|
|
white-space: pre-wrap;
|
|
word-wrap: break-word;
|
|
}
|
|
.chunk-text {
|
|
color: #666;
|
|
}
|
|
.chunk-matched {
|
|
background: #fff3cd;
|
|
border: 1px solid #ffc107;
|
|
padding: 2px 4px;
|
|
border-radius: 2px;
|
|
font-weight: 500;
|
|
color: #333;
|
|
}
|
|
.chunk-ellipsis {
|
|
color: #999;
|
|
font-style: italic;
|
|
}
|
|
</style>
|
|
|
|
<div x-data="vizApp()">
|
|
<div class="viz-card">
|
|
<h2>Vector Visualization</h2>
|
|
<div class="viz-info-box">
|
|
Testing search algorithms on your indexed documents. User: <strong>{{ username }}</strong>
|
|
</div>
|
|
|
|
<form @submit.prevent="executeSearch">
|
|
<div class="viz-controls">
|
|
<!-- Main Controls -->
|
|
<div class="viz-control-group">
|
|
<label>Search Query</label>
|
|
<input type="text" x-model="query" placeholder="Enter search query..." required />
|
|
</div>
|
|
|
|
<div class="viz-control-row">
|
|
<div class="viz-control-group" style="margin-bottom: 0;">
|
|
<label>Algorithm</label>
|
|
<select x-model="algorithm">
|
|
<option value="semantic">Semantic (Dense Vectors)</option>
|
|
<option value="bm25_hybrid" selected>BM25 Hybrid (Dense + Sparse)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="viz-control-group" style="margin-bottom: 0;" x-show="algorithm === 'bm25_hybrid'">
|
|
<label>Fusion Method</label>
|
|
<select x-model="fusion">
|
|
<option value="rrf" selected>RRF (Reciprocal Rank Fusion)</option>
|
|
<option value="dbsf">DBSF (Distribution-Based Score Fusion)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div style="display: flex; align-items: flex-end;">
|
|
<button type="submit" class="viz-btn" style="width: 100%;">Search & Visualize</button>
|
|
</div>
|
|
|
|
<div style="display: flex; align-items: flex-end;">
|
|
<button type="button" class="viz-btn-secondary" @click="showAdvanced = !showAdvanced" style="white-space: nowrap;">
|
|
<span x-text="showAdvanced ? 'Hide Advanced' : 'Advanced'"></span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Advanced Options (Collapsible) -->
|
|
<div class="viz-advanced-section" x-show="showAdvanced" x-transition.opacity.duration.200ms>
|
|
<h3 style="margin-top: 0; margin-bottom: 16px; font-size: 16px;">Advanced Options</h3>
|
|
|
|
<div class="viz-advanced-grid">
|
|
<div class="viz-control-group">
|
|
<label>Document Types</label>
|
|
<select x-model="docTypes" multiple>
|
|
<option value="">All Types (cross-app search)</option>
|
|
<option value="note">Notes</option>
|
|
<option value="file">Files</option>
|
|
<option value="calendar">Calendar Events</option>
|
|
<option value="contact">Contacts</option>
|
|
<option value="deck">Deck Cards</option>
|
|
</select>
|
|
<small style="color: #666; display: block; margin-top: 4px;">
|
|
Hold Ctrl/Cmd to select multiple
|
|
</small>
|
|
</div>
|
|
|
|
<div>
|
|
<div class="viz-control-group">
|
|
<label>Score Threshold (Semantic/Hybrid)</label>
|
|
<input type="number" x-model.number="scoreThreshold" min="0" max="1" step="0.1" />
|
|
</div>
|
|
|
|
<div class="viz-control-group">
|
|
<label>Result Limit</label>
|
|
<input type="number" x-model.number="limit" min="1" max="100" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Info: BM25 Hybrid fusion methods -->
|
|
<div x-show="algorithm === 'bm25_hybrid'" style="margin-top: 16px; padding: 12px; background: #e9ecef; border-radius: 4px;">
|
|
<p style="margin: 0; font-size: 14px; color: #666;">
|
|
<strong>BM25 Hybrid Search:</strong> Combines dense semantic vectors with sparse BM25 keyword vectors.
|
|
</p>
|
|
<p style="margin: 8px 0 0 0; font-size: 13px; color: #666;">
|
|
<strong>RRF:</strong> Reciprocal Rank Fusion - Rank-based fusion producing scores in [0.0, 1.0]
|
|
</p>
|
|
<p style="margin: 4px 0 0 0; font-size: 13px; color: #666;">
|
|
<strong>DBSF:</strong> Distribution-Based Score Fusion - Sums normalized scores (can exceed 1.0)
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="viz-card">
|
|
<div id="viz-plot-container">
|
|
<div x-show="loading" class="viz-loading-overlay" x-transition.opacity.duration.200ms>
|
|
Executing search and computing PCA projection...
|
|
</div>
|
|
<div id="viz-plot" x-show="!loading" x-transition.opacity.duration.200ms></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="viz-card">
|
|
<h3>Search Results (<span x-text="loading ? '...' : results.length"></span>)</h3>
|
|
|
|
<div x-show="loading" class="viz-loading" x-transition.opacity.duration.200ms>
|
|
Loading results...
|
|
</div>
|
|
|
|
<div x-show="!loading && results.length === 0" class="viz-no-results" x-transition.opacity.duration.200ms>
|
|
No results found. Try a different query or adjust your search parameters.
|
|
</div>
|
|
|
|
<template x-if="!loading && results.length > 0">
|
|
<div x-transition.opacity.duration.200ms>
|
|
<template x-for="result in results" :key="result.id">
|
|
<div style="padding: 12px; border-bottom: 1px solid #eee;">
|
|
<a :href="getNextcloudUrl(result)" target="_blank" style="font-weight: 500; color: #0066cc; text-decoration: none;">
|
|
<span x-text="result.title"></span>
|
|
</a>
|
|
<div style="font-size: 14px; color: #666; margin-top: 4px;" x-text="result.excerpt"></div>
|
|
<div style="font-size: 12px; color: #999; margin-top: 4px;">
|
|
Score: <span x-text="result.score.toFixed(3)"></span> |
|
|
Type: <span x-text="result.doc_type"></span>
|
|
</div>
|
|
|
|
<!-- Show Chunk button (only if chunk position is available) -->
|
|
<template x-if="hasChunkPosition(result)">
|
|
<button
|
|
class="chunk-toggle-btn"
|
|
@click="toggleChunk(result)"
|
|
x-text="isChunkExpanded(`${result.doc_type}_${result.id}`) ? 'Hide Chunk' : 'Show Chunk'"
|
|
></button>
|
|
</template>
|
|
|
|
<!-- Chunk context (expanded inline) -->
|
|
<template x-if="isChunkExpanded(`${result.doc_type}_${result.id}`)">
|
|
<div class="chunk-context" x-transition.opacity.duration.200ms>
|
|
<template x-if="chunkLoading[`${result.doc_type}_${result.id}`]">
|
|
<div style="color: #666; font-style: italic;">Loading chunk...</div>
|
|
</template>
|
|
<template x-if="!chunkLoading[`${result.doc_type}_${result.id}`]">
|
|
<div>
|
|
<template x-if="expandedChunks[`${result.doc_type}_${result.id}`]?.has_more_before">
|
|
<span class="chunk-ellipsis">...</span>
|
|
</template>
|
|
<span class="chunk-text" x-text="expandedChunks[`${result.doc_type}_${result.id}`]?.before_context"></span><span class="chunk-matched" x-text="expandedChunks[`${result.doc_type}_${result.id}`]?.chunk_text"></span><span class="chunk-text" x-text="expandedChunks[`${result.doc_type}_${result.id}`]?.after_context"></span><template x-if="expandedChunks[`${result.doc_type}_${result.id}`]?.has_more_after">
|
|
<span class="chunk-ellipsis">...</span>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</div>
|