INNER CODE UNIT · TypeScript

getEmbedding

winstonkoh87/Athena-Public · supabase/functions/sync-athena/index.ts:29

async function getEmbedding(text: string): Promise<number[]> {
  const truncatedText = text.slice(0, 32000); // Truncate to ~8000 tokens
  
  const response = await fetch(
    `https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent?key=${GOOGLE_API_KEY}`,
    {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        model: "models/text-embedding-004",
        content: { parts: [{ text: truncatedText }] },
      }),
    }
  );

  if (!response.ok) {
    throw new Error(`Embedding API error: ${response.statusText}`);
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…