import { pipeline } from '@xenova/transformers'; import { parentPort } from 'worker_threads'; let model: any; parentPort?.on('message', async ({ id, text }) => { if(!model) model = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2'); const output = await model(text, { pooling: 'mean', normalize: true }); const embedding = Array.from(output.data); parentPort?.postMessage({ id, embedding }); });