export async function embedText(text: string, apiKey?: string): Promise { const key = apiKey ?? process.env.VOYAGE_API_KEY if (!key) throw new Error('VOYAGE_API_KEY is not set') const res = await fetch('https://api.voyageai.com/v1/embeddings', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${key}`, }, body: JSON.stringify({ input: [text], model: 'voyage-3-lite' }), }) if (!res.ok) throw new Error(`Voyage embed failed: ${res.status}`) const json = await res.json() as { data: Array<{ embedding: number[] }> } return json.data[0].embedding }