AOSSIE-Org / AOSSIE-Org/Ell-ena

BUG: embeddings generation error "models/embedding-001 is not found"

Aperta
#161 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Dart
Stelle
54
Fork
110
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

## 📌 Issue Overview

The `get-embedding` Edge Function is using an incorrect Gemini API endpoint and model name, causing all embedding generation requests to fail with a "model not found" error. This breaks the AI-powered semantic search and meeting summarization features that depend on embeddings.

## 🔍 Steps to Reproduce

1. Deploy the current index.ts to Supabase
2. Call the Edge Function with a test request:
```bash
curl -X POST "https://your-project.supabase.co/functions/v1/get-embedding" \
-H "Authorization: Bearer YOUR_ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Test meeting about AI"}' | jq
```
3. Observe the error response

## 🎯 Expected Behavior

The function should successfully generate a 768-dimension embedding vector using the Gemini API and return:
```json
{
"embedding": [0.123, -0.456, 0.789, ...]
}
```

## 🚨 Actual Behavior

The function fails with the following error:
```json
{
"error": "Error generating embedding: models/embedding-001 is not found for API version v1, or is not supported for embedContent. Call ListModels to see the list of available models and their supported methods."
}
```

**Root Cause:**
- Current implementation uses `/v1/models/embedding-001` which doesn't exist
- Gemini's embedding model is actually `gemini-embedding-001` and requires the `/v1beta` API version
- Request body includes unnecessary `model` and `taskType` fields

## 📷 Screenshot

**Error output:**

![Image](https://github.com/user-attachments/assets/878d43d0-a1bd-4f31-8e92-97fc2acdefb0)

**Verified correct model via Gemini API:**
```bash
$ curl "https://generativelanguage.googleapis.com/v1beta/models?key=API_KEY" | \
jq '.models[] | select(.name | contains("embedding"))'

{
"name": "models/gemini-embedding-001",
"supportedGenerationMethods": [
"embedContent",
"countTextTokens",
"countTokens",
"asyncBatchEmbedContent"
]
}
```

## 💡 Suggested Improvements

### Fix Required Changes

**Current (broken) code in index.ts:**
```typescript
const embeddingResponse = await fetch(
"https://generativelanguage.googleapis.com/v1/models/embedding-001:embedContent?key=" + GEMINI_API_KEY,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "embedding-001", // ❌ Incorrect
content: {
parts: [{ text: text }]
},
taskType: "RETRIEVAL_QUERY" // ❌ Unnecessary
}),
}
);
```

**Proposed fix:**
```typescript
const embeddingResponse = await fetch(
"https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key=" + GEMINI_API_KEY,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content: {
parts: [{ text: text }]
}
}),
}
);
```

### Changes Summary:
1. ✅ Update API version: `/v1` → `/v1beta`
2. ✅ Update model name: `embedding-001` → `gemini-embedding-001`
3. ✅ Remove `model` field from request body (redundant - already in URL)
4. ✅ Remove `taskType` field (not required by v1beta API)

### Verification
After applying the fix, the function works correctly:
```bash
$ curl -X POST "https://your-project.supabase.co/functions/v1/get-embedding" \
-H "Authorization: Bearer YOUR_ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Test meeting about AI"}' | jq

{
"embedding": [0.034567, -0.012345, 0.056789, ..., 0.023456] // 768 dimensions
}
```

---

**Impact:** This bug prevents all AI-powered features (semantic search, meeting insights, similarity matching) from functioning. Fixing it is critical for the application to work as intended.

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.