Fixed initial load being slow

This commit is contained in:
2026-02-19 21:38:39 +00:00
parent edc1327987
commit e452b66a7f
8 changed files with 69 additions and 84 deletions
+6 -9
View File
@@ -1,18 +1,15 @@
import { env, pipeline, type FeatureExtractionPipeline } from '@xenova/transformers'
// Serve model files from /models/ (Vite serves public/ at root)
env.localModelPath = '/models/'
env.allowRemoteModels = false
env.useBrowserCache = false
let extractor: FeatureExtractionPipeline | null = null
let extractor: import('@xenova/transformers').FeatureExtractionPipeline | null = null
let loading = false
export async function initModel(): Promise<void> {
if (extractor || loading) return
loading = true
try {
extractor = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2') as FeatureExtractionPipeline
const { env, pipeline } = await import('@xenova/transformers')
env.localModelPath = '/models/'
env.allowRemoteModels = false
env.useBrowserCache = false
extractor = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2') as import('@xenova/transformers').FeatureExtractionPipeline
} catch {
// Silently swallow — model unavailable, semantic search won't activate
} finally {