Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FFDuBhMKvoWjrWT3ZnGmmr
15 lines
617 B
TypeScript
15 lines
617 B
TypeScript
export async function embedText(text: string): Promise<number[]> {
|
|
if (!process.env.VOYAGE_API_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 ${process.env.VOYAGE_API_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
|
|
}
|