Ken Powers commited on
Commit
ea34d21
·
1 Parent(s): 42d4694

See https://discuss.huggingface.co/t/why-are-my-benchmark-results-so-different-from-the-mteb-leaderboard/168305

.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  .direnv
2
  .envrc.local
 
 
1
  .direnv
2
  .envrc.local
3
+ __pycache__
README.md CHANGED
@@ -295,6 +295,25 @@ For high-level information about these models, see the [MTEB Leaderboard](https:
295
 
296
  *... and 522 more queries*
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  ### openai/text-embedding-3-small (BSB)
299
 
300
  **Accuracy: 81.0%** (1293/1596 points across 532 queries)
@@ -371,6 +390,25 @@ For high-level information about these models, see the [MTEB Leaderboard](https:
371
 
372
  *... and 522 more queries*
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  ### huggingface/thenlper-gte-large (BSB)
375
 
376
  **Accuracy: 73.1%** (1166/1596 points across 532 queries)
@@ -409,6 +447,25 @@ For high-level information about these models, see the [MTEB Leaderboard](https:
409
 
410
  *... and 522 more queries*
411
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  ### huggingface/intfloat-e5-large-v2 (BSB)
413
 
414
  **Accuracy: 72.1%** (1150/1596 points across 532 queries)
@@ -428,25 +485,6 @@ For high-level information about these models, see the [MTEB Leaderboard](https:
428
 
429
  *... and 522 more queries*
430
 
431
- ### huggingface/Qwen-Qwen3-Embedding-8B (BSB)
432
-
433
- **Accuracy: 71.5%** (1141/1596 points across 532 queries)
434
-
435
- | Query | Expected | Top Result | Score | ✓ |
436
- |-------|----------|------------|-------|---|
437
- | isn't there a verse about god is love? | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.7362 | ✅ |
438
- | god is love | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.7374 | ✅ |
439
- | verse about they meant bad but god meant good (rou... | ['Genesis 50:20'] | Romans 12:21 | 0.6828 | ⚠️ |
440
- | they meant bad but god meant good | ['Genesis 50:20'] | Romans 12:21 | 0.7262 | ❌ |
441
- | isn't there a verse about god loves the world? | ['John 3:16'] | 1 John 4:8 | 0.7306 | ❌ |
442
- | god loves the world | ['John 3:16'] | Psalms 67:7 | 0.7223 | ❌ |
443
- | isn't there a verse about god loved the whole worl... | ['John 3:16'] | Psalms 67:7 | 0.7155 | ⚠️ |
444
- | god loved the whole world | ['John 3:16'] | Psalms 145:9 | 0.7543 | ❌ |
445
- | isn't there a verse about in the beginning god cre... | ['Genesis 1:1'] | Genesis 1:1 | 0.8065 | ✅ |
446
- | in the beginning god created | ['Genesis 1:1'] | Genesis 1:1 | 0.8381 | ✅ |
447
-
448
- *... and 522 more queries*
449
-
450
  ### huggingface/nomic-ai-nomic-embed-text-v1.5 (BSB)
451
 
452
  **Accuracy: 70.0%** (1117/1596 points across 532 queries)
@@ -675,25 +713,6 @@ For high-level information about these models, see the [MTEB Leaderboard](https:
675
 
676
  *... and 522 more queries*
677
 
678
- ### huggingface/Qwen-Qwen3-Embedding-4B (BSB)
679
-
680
- **Accuracy: 58.9%** (940/1596 points across 532 queries)
681
-
682
- | Query | Expected | Top Result | Score | ✓ |
683
- |-------|----------|------------|-------|---|
684
- | isn't there a verse about god is love? | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.7756 | ✅ |
685
- | god is love | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.7562 | ✅ |
686
- | verse about they meant bad but god meant good (rou... | ['Genesis 50:20'] | Genesis 50:20 | 0.7200 | ✅ |
687
- | they meant bad but god meant good | ['Genesis 50:20'] | Genesis 50:20 | 0.7370 | ✅ |
688
- | isn't there a verse about god loves the world? | ['John 3:16'] | 1 John 4:8 | 0.7019 | ❌ |
689
- | god loves the world | ['John 3:16'] | Job 20:5 | 0.7062 | ❌ |
690
- | isn't there a verse about god loved the whole worl... | ['John 3:16'] | 1 John 4:11 | 0.7045 | ❌ |
691
- | god loved the whole world | ['John 3:16'] | 1 Corinthians 16:14 | 0.7100 | ❌ |
692
- | isn't there a verse about in the beginning god cre... | ['Genesis 1:1'] | Genesis 1:1 | 0.7725 | ✅ |
693
- | in the beginning god created | ['Genesis 1:1'] | Genesis 1:1 | 0.8114 | ✅ |
694
-
695
- *... and 522 more queries*
696
-
697
  ### huggingface/BAAI-bge-base-en (BSB)
698
 
699
  **Accuracy: 56.9%** (908/1596 points across 532 queries)
@@ -713,25 +732,6 @@ For high-level information about these models, see the [MTEB Leaderboard](https:
713
 
714
  *... and 522 more queries*
715
 
716
- ### huggingface/Qwen-Qwen3-Embedding-0.6B (BSB)
717
-
718
- **Accuracy: 56.8%** (907/1596 points across 532 queries)
719
-
720
- | Query | Expected | Top Result | Score | ✓ |
721
- |-------|----------|------------|-------|---|
722
- | isn't there a verse about god is love? | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.6569 | ✅ |
723
- | god is love | ['1 John 4:8', '1 John 4:16'] | Psalms 59:10 | 0.7234 | ❌ |
724
- | verse about they meant bad but god meant good (rou... | ['Genesis 50:20'] | Proverbs 16:4 | 0.6752 | ⚠️ |
725
- | they meant bad but god meant good | ['Genesis 50:20'] | Proverbs 16:4 | 0.6880 | ❌ |
726
- | isn't there a verse about god loves the world? | ['John 3:16'] | 1 John 2:15 | 0.6984 | ❌ |
727
- | god loves the world | ['John 3:16'] | Psalms 47:7 | 0.6723 | ❌ |
728
- | isn't there a verse about god loved the whole worl... | ['John 3:16'] | 1 John 2:15 | 0.6837 | ⚠️ |
729
- | god loved the whole world | ['John 3:16'] | Psalms 67:7 | 0.6642 | ❌ |
730
- | isn't there a verse about in the beginning god cre... | ['Genesis 1:1'] | Genesis 1:1 | 0.6984 | ✅ |
731
- | in the beginning god created | ['Genesis 1:1'] | John 1:2 | 0.7343 | ⚠️ |
732
-
733
- *... and 522 more queries*
734
-
735
  ### huggingface/BAAI-bge-large-en (BSB)
736
 
737
  **Accuracy: 47.4%** (756/1596 points across 532 queries)
 
295
 
296
  *... and 522 more queries*
297
 
298
+ ### huggingface/Qwen-Qwen3-Embedding-8B (BSB)
299
+
300
+ **Accuracy: 82.8%** (1322/1596 points across 532 queries)
301
+
302
+ | Query | Expected | Top Result | Score | ✓ |
303
+ |-------|----------|------------|-------|---|
304
+ | isn't there a verse about god is love? | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.6020 | ✅ |
305
+ | god is love | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.6260 | ✅ |
306
+ | verse about they meant bad but god meant good (rou... | ['Genesis 50:20'] | Genesis 50:20 | 0.6016 | ✅ |
307
+ | they meant bad but god meant good | ['Genesis 50:20'] | Genesis 50:20 | 0.6255 | ✅ |
308
+ | isn't there a verse about god loves the world? | ['John 3:16'] | John 3:16 | 0.6166 | ✅ |
309
+ | god loves the world | ['John 3:16'] | 1 John 4:8 | 0.6084 | ❌ |
310
+ | isn't there a verse about god loved the whole worl... | ['John 3:16'] | John 3:16 | 0.6256 | ✅ |
311
+ | god loved the whole world | ['John 3:16'] | John 3:16 | 0.6262 | ✅ |
312
+ | isn't there a verse about in the beginning god cre... | ['Genesis 1:1'] | Genesis 1:1 | 0.6202 | ✅ |
313
+ | in the beginning god created | ['Genesis 1:1'] | Genesis 1:1 | 0.6736 | ✅ |
314
+
315
+ *... and 522 more queries*
316
+
317
  ### openai/text-embedding-3-small (BSB)
318
 
319
  **Accuracy: 81.0%** (1293/1596 points across 532 queries)
 
390
 
391
  *... and 522 more queries*
392
 
393
+ ### huggingface/Qwen-Qwen3-Embedding-0.6B (BSB)
394
+
395
+ **Accuracy: 73.9%** (1179/1596 points across 532 queries)
396
+
397
+ | Query | Expected | Top Result | Score | ✓ |
398
+ |-------|----------|------------|-------|---|
399
+ | isn't there a verse about god is love? | ['1 John 4:8', '1 John 4:16'] | 1 John 4:16 | 0.6455 | ✅ |
400
+ | god is love | ['1 John 4:8', '1 John 4:16'] | 1 John 4:16 | 0.6461 | ✅ |
401
+ | verse about they meant bad but god meant good (rou... | ['Genesis 50:20'] | Genesis 50:20 | 0.6596 | ✅ |
402
+ | they meant bad but god meant good | ['Genesis 50:20'] | Genesis 50:20 | 0.6567 | ✅ |
403
+ | isn't there a verse about god loves the world? | ['John 3:16'] | 1 John 2:15 | 0.6730 | ❌ |
404
+ | god loves the world | ['John 3:16'] | 1 John 2:15 | 0.6744 | ❌ |
405
+ | isn't there a verse about god loved the whole worl... | ['John 3:16'] | John 3:16 | 0.6674 | ✅ |
406
+ | god loved the whole world | ['John 3:16'] | John 3:16 | 0.6288 | ✅ |
407
+ | isn't there a verse about in the beginning god cre... | ['Genesis 1:1'] | Genesis 2:4 | 0.6557 | ❌ |
408
+ | in the beginning god created | ['Genesis 1:1'] | Genesis 1:1 | 0.6935 | ✅ |
409
+
410
+ *... and 522 more queries*
411
+
412
  ### huggingface/thenlper-gte-large (BSB)
413
 
414
  **Accuracy: 73.1%** (1166/1596 points across 532 queries)
 
447
 
448
  *... and 522 more queries*
449
 
450
+ ### huggingface/Qwen-Qwen3-Embedding-4B (BSB)
451
+
452
+ **Accuracy: 72.4%** (1156/1596 points across 532 queries)
453
+
454
+ | Query | Expected | Top Result | Score | ✓ |
455
+ |-------|----------|------------|-------|---|
456
+ | isn't there a verse about god is love? | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.6945 | ✅ |
457
+ | god is love | ['1 John 4:8', '1 John 4:16'] | 1 John 4:8 | 0.6686 | ✅ |
458
+ | verse about they meant bad but god meant good (rou... | ['Genesis 50:20'] | Genesis 50:20 | 0.6868 | ✅ |
459
+ | they meant bad but god meant good | ['Genesis 50:20'] | Genesis 50:20 | 0.6910 | ✅ |
460
+ | isn't there a verse about god loves the world? | ['John 3:16'] | 1 John 4:7 | 0.6471 | ❌ |
461
+ | god loves the world | ['John 3:16'] | 1 John 4:7 | 0.6258 | ❌ |
462
+ | isn't there a verse about god loved the whole worl... | ['John 3:16'] | 1 John 4:7 | 0.6446 | ❌ |
463
+ | god loved the whole world | ['John 3:16'] | 1 John 4:7 | 0.6103 | ❌ |
464
+ | isn't there a verse about in the beginning god cre... | ['Genesis 1:1'] | Genesis 1:1 | 0.6311 | ✅ |
465
+ | in the beginning god created | ['Genesis 1:1'] | Genesis 1:1 | 0.6547 | ✅ |
466
+
467
+ *... and 522 more queries*
468
+
469
  ### huggingface/intfloat-e5-large-v2 (BSB)
470
 
471
  **Accuracy: 72.1%** (1150/1596 points across 532 queries)
 
485
 
486
  *... and 522 more queries*
487
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  ### huggingface/nomic-ai-nomic-embed-text-v1.5 (BSB)
489
 
490
  **Accuracy: 70.0%** (1117/1596 points across 532 queries)
 
713
 
714
  *... and 522 more queries*
715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
716
  ### huggingface/BAAI-bge-base-en (BSB)
717
 
718
  **Accuracy: 56.9%** (908/1596 points across 532 queries)
 
732
 
733
  *... and 522 more queries*
734
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
735
  ### huggingface/BAAI-bge-large-en (BSB)
736
 
737
  **Accuracy: 47.4%** (756/1596 points across 532 queries)
__pycache__/main.cpython-313.pyc DELETED
Binary file (97.5 kB)
 
main.py CHANGED
@@ -49,6 +49,10 @@ class EmbeddingProvider(ABC):
49
  """Generate embeddings for a batch of texts."""
50
  pass
51
 
 
 
 
 
52
 
53
  class OpenAIProvider(EmbeddingProvider):
54
  """OpenAI embedding provider."""
@@ -246,10 +250,23 @@ class HuggingFaceProvider(EmbeddingProvider):
246
  def __init__(self, model_name: str):
247
  self.model_name = model_name
248
  self.model = None
 
249
 
250
  def get_name(self) -> str:
251
  # Convert model path to filename-safe format
252
  return self.model_name.replace("/", "-").replace("_", "-")
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
  def _get_model(self):
255
  if self.model is None:
@@ -288,6 +305,32 @@ class HuggingFaceProvider(EmbeddingProvider):
288
  model = self._get_model()
289
  embedding = model.encode([text], normalize_embeddings=True)[0]
290
  return embedding.tolist()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
 
292
  async def embed_batch(self, texts: List[str]) -> List[List[float]]:
293
  model = self._get_model()
@@ -295,8 +338,37 @@ class HuggingFaceProvider(EmbeddingProvider):
295
  embeddings = model.encode(texts, normalize_embeddings=True)
296
  return [emb.tolist() for emb in embeddings]
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  async def embed_queries_batch(self, queries: List[str], batch_size: int = 500) -> List[List[float]]:
299
- """Efficiently embed multiple queries using HuggingFace's batch capability."""
300
  all_embeddings = []
301
 
302
  # HuggingFace can handle larger batches efficiently since it's local
@@ -305,14 +377,14 @@ class HuggingFaceProvider(EmbeddingProvider):
305
  print(f"Embedding batch {i//batch_size + 1}/{(len(queries) + batch_size - 1)//batch_size} ({len(batch)} queries)")
306
 
307
  try:
308
- batch_embeddings = await self.embed_batch(batch)
309
  all_embeddings.extend(batch_embeddings)
310
  except Exception as e:
311
  print(f"Error in batch embedding: {e}")
312
  # Fall back to individual embedding for this batch
313
  for query in batch:
314
  try:
315
- embedding = await self.embed_text(query)
316
  all_embeddings.append(embedding)
317
  except Exception as e2:
318
  print(f"Error embedding query '{query}': {e2}")
@@ -1111,7 +1183,7 @@ async def search_embeddings(
1111
 
1112
  # Generate embedding for the query
1113
  print(f"Generating embedding for query: '{query}'")
1114
- query_embedding = await provider.embed_text(query)
1115
 
1116
  # Use HNSW when explicitly requested
1117
  if use_hnsw:
 
49
  """Generate embeddings for a batch of texts."""
50
  pass
51
 
52
+ async def embed_query(self, query: str) -> List[float]:
53
+ """Generate embedding for a query. Base implementation falls back to embed_text."""
54
+ return await self.embed_text(query)
55
+
56
 
57
  class OpenAIProvider(EmbeddingProvider):
58
  """OpenAI embedding provider."""
 
250
  def __init__(self, model_name: str):
251
  self.model_name = model_name
252
  self.model = None
253
+ self.query_prompt_config = self._get_query_prompt_config()
254
 
255
  def get_name(self) -> str:
256
  # Convert model path to filename-safe format
257
  return self.model_name.replace("/", "-").replace("_", "-")
258
+
259
+ def _get_query_prompt_config(self) -> dict:
260
+ """Get query prompt configuration for specific models."""
261
+ # Model-specific query prompt configurations
262
+ if "Qwen3-Embedding" in self.model_name:
263
+ return {
264
+ "enabled": True,
265
+ "prompt_name": "query",
266
+ "instruction_template": "Instruct: Given a biblical passage, retrieve verses that are semantically related or answer the query\nQuery: {query}"
267
+ }
268
+ # Add other model-specific configurations here as needed
269
+ return {"enabled": False}
270
 
271
  def _get_model(self):
272
  if self.model is None:
 
305
  model = self._get_model()
306
  embedding = model.encode([text], normalize_embeddings=True)[0]
307
  return embedding.tolist()
308
+
309
+ async def embed_query(self, query: str) -> List[float]:
310
+ """Embed a query with model-specific prompting if needed."""
311
+ model = self._get_model()
312
+
313
+ if self.query_prompt_config["enabled"]:
314
+ # Apply model-specific query prompting
315
+ if "prompt_name" in self.query_prompt_config:
316
+ # Use prompt_name parameter (for Qwen3)
317
+ embedding = model.encode(
318
+ [query],
319
+ normalize_embeddings=True,
320
+ prompt_name=self.query_prompt_config["prompt_name"]
321
+ )[0]
322
+ elif "instruction_template" in self.query_prompt_config:
323
+ # Use instruction template formatting
324
+ formatted_query = self.query_prompt_config["instruction_template"].format(query=query)
325
+ embedding = model.encode([formatted_query], normalize_embeddings=True)[0]
326
+ else:
327
+ # Fallback to regular embedding
328
+ embedding = model.encode([query], normalize_embeddings=True)[0]
329
+ else:
330
+ # No special prompting needed
331
+ embedding = model.encode([query], normalize_embeddings=True)[0]
332
+
333
+ return embedding.tolist()
334
 
335
  async def embed_batch(self, texts: List[str]) -> List[List[float]]:
336
  model = self._get_model()
 
338
  embeddings = model.encode(texts, normalize_embeddings=True)
339
  return [emb.tolist() for emb in embeddings]
340
 
341
+ async def embed_queries_batch_internal(self, queries: List[str]) -> List[List[float]]:
342
+ """Embed a batch of queries with model-specific prompting if needed."""
343
+ model = self._get_model()
344
+
345
+ if self.query_prompt_config["enabled"]:
346
+ # Apply model-specific query prompting
347
+ if "prompt_name" in self.query_prompt_config:
348
+ # Use prompt_name parameter (for Qwen3)
349
+ embeddings = model.encode(
350
+ queries,
351
+ normalize_embeddings=True,
352
+ prompt_name=self.query_prompt_config["prompt_name"]
353
+ )
354
+ elif "instruction_template" in self.query_prompt_config:
355
+ # Use instruction template formatting
356
+ formatted_queries = [
357
+ self.query_prompt_config["instruction_template"].format(query=query)
358
+ for query in queries
359
+ ]
360
+ embeddings = model.encode(formatted_queries, normalize_embeddings=True)
361
+ else:
362
+ # Fallback to regular embedding
363
+ embeddings = model.encode(queries, normalize_embeddings=True)
364
+ else:
365
+ # No special prompting needed
366
+ embeddings = model.encode(queries, normalize_embeddings=True)
367
+
368
+ return [emb.tolist() for emb in embeddings]
369
+
370
  async def embed_queries_batch(self, queries: List[str], batch_size: int = 500) -> List[List[float]]:
371
+ """Efficiently embed multiple queries using HuggingFace's batch capability with model-specific prompting."""
372
  all_embeddings = []
373
 
374
  # HuggingFace can handle larger batches efficiently since it's local
 
377
  print(f"Embedding batch {i//batch_size + 1}/{(len(queries) + batch_size - 1)//batch_size} ({len(batch)} queries)")
378
 
379
  try:
380
+ batch_embeddings = await self.embed_queries_batch_internal(batch)
381
  all_embeddings.extend(batch_embeddings)
382
  except Exception as e:
383
  print(f"Error in batch embedding: {e}")
384
  # Fall back to individual embedding for this batch
385
  for query in batch:
386
  try:
387
+ embedding = await self.embed_query(query)
388
  all_embeddings.append(embedding)
389
  except Exception as e2:
390
  print(f"Error embedding query '{query}': {e2}")
 
1183
 
1184
  # Generate embedding for the query
1185
  print(f"Generating embedding for query: '{query}'")
1186
+ query_embedding = await provider.embed_query(query)
1187
 
1188
  # Use HNSW when explicitly requested
1189
  if use_hnsw:
results/huggingface/Qwen-Qwen3-Embedding-0.6B.csv CHANGED
The diff for this file is too large to render. See raw diff
 
results/huggingface/Qwen-Qwen3-Embedding-4B.csv CHANGED
The diff for this file is too large to render. See raw diff
 
results/huggingface/Qwen-Qwen3-Embedding-8B.csv CHANGED
The diff for this file is too large to render. See raw diff