import gradio as gr
import os
import time
import random
import pandas as pd
from src.vector_db import UnifiedQdrant
from src.router import LearnedRouter
from src.data_pipeline import get_embedding
# --- Configuration ---
COLLECTION_NAME = "dashVector_v1"
VECTOR_SIZE = 384 # MiniLM-L6-v2
NUM_CLUSTERS = 16
EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
# --- Initialize Backend ---
# We initialize once at startup
vector_db = UnifiedQdrant(COLLECTION_NAME, VECTOR_SIZE, NUM_CLUSTERS)
vector_db.initialize()
# Load Router (Ensure it exists, else mock/warn)
ROUTER_PATH = "models/router_v1.pkl"
try:
router = LearnedRouter.load(ROUTER_PATH)
except Exception as e:
print(f"Warning: Could not load router: {e}. Using dummy router for UI demo if needed.")
router = None
# --- HTML Templates (Extracted from dashVector_benchmark.html) ---
# --- HTML Templates (Extracted from dashVector_benchmark.html) ---
HEAD_HTML = """
"""
NAVBAR_HTML = """
dashVector
Improves search efficiency by using a Router Model to predict specific data shards, reducing the search space on the Vector DB.
Utilizes Qdrant for high-performance vector storage and retrieval, benchmarking direct search vs. routed search across 16 shards.
Router predicts shard probabilities. Shards are iteratively added to the search scope until the cumulative confidence > 0.9, balancing accuracy and speed.
Ready to benchmark
Enter a query above to compare routing architectures.
An error occurred while running the benchmark:
{error_msg}