export const search = async ( text: string, { filterId }: { filterId?: string } = {},) => { if (!text) return []; const vector = await getEmbedding(text); const searchQuery = db.prepare(` WITH matching_products AS ( SELECT rowid, distance FROM products_vss WHERE vss_search(vector, ?) ${filterId ? 'AND rowid != ?' : ''} AND distance < 1.5 ORDER BY distance ASC LIMIT 5 ) SELECT p.*, mp.distance FROM products p INNER JOIN matching_products mp ON p.id = mp.rowid; `); return searchQuery.all(JSON.stringify(vector), filterId) as Product[];};