RobertoBarrosoLuque commited on
Commit
fe002f3
·
1 Parent(s): 6903420
Files changed (2) hide show
  1. tests/test_detailed.py +34 -0
  2. tests/test_stages.py +34 -0
tests/test_detailed.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from src.search.vector_search import (
2
+ search_vector_with_expansion,
3
+ search_vector_with_reranking,
4
+ )
5
+
6
+ if __name__ == "__main__":
7
+ query = "wireless headphones"
8
+ print(f"=== Testing: {query} ===\n")
9
+
10
+ # Stage 3: Query Expansion
11
+ print("STAGE 3: Query Expansion Results")
12
+ results_3 = search_vector_with_expansion(query)
13
+ for i, r in enumerate(results_3[:5], 1):
14
+ print(f"{i}. [{r['score']:.4f}] {r['product_name']}")
15
+
16
+ print("\n" + "=" * 80 + "\n")
17
+
18
+ # Stage 4: Reranking
19
+ print("STAGE 4: Reranking Results")
20
+ results_4 = search_vector_with_reranking(query)
21
+ for i, r in enumerate(results_4[:5], 1):
22
+ print(f"{i}. [{r['score']:.4f}] {r['product_name']}")
23
+
24
+ print("\n" + "=" * 80 + "\n")
25
+ print("Analysis:")
26
+ print(
27
+ f"Stage 3 Top-1: {results_3[0]['score']:.4f} - {results_3[0]['product_name']}"
28
+ )
29
+ print(
30
+ f"Stage 4 Top-1: {results_4[0]['score']:.4f} - {results_4[0]['product_name']}"
31
+ )
32
+
33
+ if results_3[0]["product_name"] != results_4[0]["product_name"]:
34
+ print("\n⚠️ Reranker changed the top result!")
tests/test_stages.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from src.app import search_stage_2, search_stage_3, search_stage_4
2
+
3
+
4
+ if __name__ == "__main__":
5
+ # Test with a few different queries
6
+ test_queries = [
7
+ "outdoor activities",
8
+ "science experiments for kids",
9
+ "wireless headphones",
10
+ ]
11
+
12
+ for query in test_queries:
13
+ print(f"\n=== Testing: {query} ===")
14
+
15
+ _, metrics_2 = search_stage_2(query)
16
+ _, metrics_3 = search_stage_3(query)
17
+ _, metrics_4 = search_stage_4(query)
18
+
19
+ print(
20
+ f'Stage 2 (Vector): Top-1: {metrics_2["top1_score"]:.4f}, Top-5: {metrics_2["top5_avg"]:.4f}, Latency: {metrics_2["latency_ms"]}ms'
21
+ )
22
+ print(
23
+ f'Stage 3 (+ Expansion): Top-1: {metrics_3["top1_score"]:.4f}, Top-5: {metrics_3["top5_avg"]:.4f}, Latency: {metrics_3["latency_ms"]}ms'
24
+ )
25
+ print(
26
+ f'Stage 4 (+ Reranking): Top-1: {metrics_4["top1_score"]:.4f}, Top-5: {metrics_4["top5_avg"]:.4f}, Latency: {metrics_4["latency_ms"]}ms'
27
+ )
28
+
29
+ if metrics_4["top1_score"] < metrics_3["top1_score"]:
30
+ diff = metrics_3["top1_score"] - metrics_4["top1_score"]
31
+ print(f"⚠️ WARNING: Reranking decreased top-1 score by {diff:.4f}")
32
+ else:
33
+ diff = metrics_4["top1_score"] - metrics_3["top1_score"]
34
+ print(f"✓ Reranking improved top-1 score by {diff:.4f}")