Ken Powers
commited on
Fix gemini and add results
Browse files- README.md +19 -0
- main.py +30 -1
- results/google-gemini/text-embedding-004.csv +0 -0
README.md
CHANGED
|
@@ -289,6 +289,25 @@ For high-level information about these models, see the [MTEB Leaderboard](https:
|
|
| 289 |
|
| 290 |
*... and 522 more queries*
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
### openai/text-embedding-ada-002 (BSB)
|
| 293 |
|
| 294 |
**Accuracy: 74.3%** (1186/1596 points across 532 queries)
|
|
|
|
| 289 |
|
| 290 |
*... and 522 more queries*
|
| 291 |
|
| 292 |
+
### google-gemini/text-embedding-004 (BSB)
|
| 293 |
+
|
| 294 |
+
**Accuracy: 76.1%** (1214/1596 points across 532 queries)
|
| 295 |
+
|
| 296 |
+
| Query | Expected | Top Result | Score | ✓ |
|
| 297 |
+
|-------|----------|------------|-------|---|
|
| 298 |
+
| isn't there a verse about god is love? | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.7386 | ✅ |
|
| 299 |
+
| god is love | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.7778 | ✅ |
|
| 300 |
+
| verse about they meant bad but god meant good (rou... | ['Genesis 50:20'] | Genesis 50:20 | 0.7120 | ✅ |
|
| 301 |
+
| they meant bad but god meant good | ['Genesis 50:20'] | Genesis 50:20 | 0.6916 | ✅ |
|
| 302 |
+
| isn't there a verse about god loves the world? | ['John 3:16'] | 1 John 4:8 | 0.6559 | ❌ |
|
| 303 |
+
| god loves the world | ['John 3:16'] | 1 John 2:15 | 0.6578 | ❌ |
|
| 304 |
+
| isn't there a verse about god loved the whole worl... | ['John 3:16'] | 1 John 4:8 | 0.6519 | ❌ |
|
| 305 |
+
| god loved the whole world | ['John 3:16'] | John 3:16 | 0.6571 | ✅ |
|
| 306 |
+
| isn't there a verse about in the beginning god cre... | ['Genesis 1:1'] | Genesis 1:1 | 0.7756 | ✅ |
|
| 307 |
+
| in the beginning god created | ['Genesis 1:1'] | Genesis 1:1 | 0.8750 | ✅ |
|
| 308 |
+
|
| 309 |
+
*... and 522 more queries*
|
| 310 |
+
|
| 311 |
### openai/text-embedding-ada-002 (BSB)
|
| 312 |
|
| 313 |
**Accuracy: 74.3%** (1186/1596 points across 532 queries)
|
main.py
CHANGED
|
@@ -124,8 +124,37 @@ class GeminiProvider(EmbeddingProvider):
|
|
| 124 |
async def embed_batch(self, texts: List[str]) -> List[List[float]]:
|
| 125 |
client = await self._get_client()
|
| 126 |
result = client.embed_content(model=f"models/{self.model_name}", content=texts)
|
|
|
|
| 127 |
# Gemini embeddings are automatically normalized to unit length
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
async def embed_queries_batch(self, queries: List[str], batch_size: int = 100) -> List[List[float]]:
|
| 131 |
"""Efficiently embed multiple queries using Gemini's batch capability."""
|
|
|
|
| 124 |
async def embed_batch(self, texts: List[str]) -> List[List[float]]:
|
| 125 |
client = await self._get_client()
|
| 126 |
result = client.embed_content(model=f"models/{self.model_name}", content=texts)
|
| 127 |
+
|
| 128 |
# Gemini embeddings are automatically normalized to unit length
|
| 129 |
+
# The result is a dictionary with an 'embedding' key containing the embedding vectors
|
| 130 |
+
if isinstance(result, dict) and 'embedding' in result:
|
| 131 |
+
embeddings = result['embedding']
|
| 132 |
+
|
| 133 |
+
# Handle case where embeddings is a list of embedding vectors
|
| 134 |
+
if isinstance(embeddings, list):
|
| 135 |
+
# Check if we have multiple embeddings (batch) or a single embedding
|
| 136 |
+
if len(embeddings) > 0:
|
| 137 |
+
# If first element is a list of numbers, we have direct embedding vectors
|
| 138 |
+
if isinstance(embeddings[0], (list, tuple)) and all(isinstance(x, (int, float)) for x in embeddings[0][:5]):
|
| 139 |
+
return embeddings
|
| 140 |
+
# If first element is a dict with 'embedding' key, extract them
|
| 141 |
+
elif isinstance(embeddings[0], dict) and 'embedding' in embeddings[0]:
|
| 142 |
+
return [emb['embedding'] for emb in embeddings]
|
| 143 |
+
# If first element is an object with embedding attribute
|
| 144 |
+
elif hasattr(embeddings[0], 'embedding'):
|
| 145 |
+
return [emb.embedding for emb in embeddings]
|
| 146 |
+
else:
|
| 147 |
+
# Assume it's a single embedding vector for all texts (unlikely but handle it)
|
| 148 |
+
return [embeddings] * len(texts)
|
| 149 |
+
else:
|
| 150 |
+
return []
|
| 151 |
+
# Handle case where embeddings is a single vector
|
| 152 |
+
elif isinstance(embeddings, (list, tuple)):
|
| 153 |
+
return [embeddings]
|
| 154 |
+
else:
|
| 155 |
+
return []
|
| 156 |
+
else:
|
| 157 |
+
raise ValueError(f"Unexpected Gemini API response format: {type(result)}")
|
| 158 |
|
| 159 |
async def embed_queries_batch(self, queries: List[str], batch_size: int = 100) -> List[List[float]]:
|
| 160 |
"""Efficiently embed multiple queries using Gemini's batch capability."""
|
results/google-gemini/text-embedding-004.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|