arbabarshad commited on
Commit
452ed79
·
1 Parent(s): f7bad94

matched_species_i fixed but only less number of tags issue remainign while db creation

Browse files
README.md CHANGED
@@ -47,7 +47,8 @@ This repository encountered several Git LFS issues during setup. Here's a summar
47
 
48
 
49
  while running in claude code :
50
- source ~/miniconda3/etc/profile.d/conda.sh && conda activate agthinker
 
51
 
52
  run command like example: source ~/miniconda3/etc/profile.d/conda.sh && conda activate agllm-env1-updates-1 && │
53
  │ python whatebverscriptis.py
 
47
 
48
 
49
  while running in claude code :
50
+ source ~/miniconda3/etc/profile.d/conda.sh && conda install -c conda-forge numpy
51
+ ate agthinker
52
 
53
  run command like example: source ~/miniconda3/etc/profile.d/conda.sh && conda activate agllm-env1-updates-1 && │
54
  │ python whatebverscriptis.py
retrieval_evaluation.py CHANGED
@@ -42,8 +42,9 @@ class QuestionGenerator:
42
 
43
  # Build context from metadata
44
  context_parts = []
45
- if 'species' in metadata:
46
- context_parts.append(f"Species: {metadata['species']}")
 
47
  if 'common_name' in metadata:
48
  context_parts.append(f"Common Name: {metadata['common_name']}")
49
  if 'region' in metadata:
@@ -79,7 +80,7 @@ Generate a single, clear question (no explanations, just the question):"""
79
  except Exception as e:
80
  print(f"Error generating question: {e}")
81
  # Fallback question
82
- species = metadata.get('species', 'this species')
83
  return f"What IPM information is available for {species}?"
84
 
85
  class RetrievalEvaluator:
@@ -140,16 +141,31 @@ class RetrievalEvaluator:
140
  metadata = sample.metadata
141
 
142
  # Define filter strategies (using ChromaDB filter format)
 
 
 
143
  filters = {
144
  'no_filter': None,
145
- 'species_only': {'species': {'$eq': metadata['species']}} if 'species' in metadata else None,
146
- 'region_only': {'region': {'$eq': metadata['region']}} if 'region' in metadata else None,
 
 
 
 
 
 
147
  'species_and_region': {
148
  '$and': [
149
- {'species': {'$eq': metadata['species']}},
150
- {'region': {'$eq': metadata['region']}}
 
 
 
 
 
 
151
  ]
152
- } if 'species' in metadata and 'region' in metadata else None
153
  }
154
 
155
  for filter_name, filter_dict in filters.items():
@@ -233,6 +249,25 @@ def main():
233
  chunks = load_chunks_from_vectordb(VECTOR_DB_PATH, sample_size=SAMPLE_SIZE)
234
  print(f" Loaded {len(chunks)} chunks")
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  # Step 2: Generate questions for chunks
237
  print("\n2. Generating questions from chunks...")
238
  question_generator = QuestionGenerator()
@@ -273,13 +308,35 @@ def main():
273
  print("\n4. Evaluation Results:")
274
  print("=" * 50)
275
 
276
- for pipeline_name, metrics in results.items():
277
- print(f"\n{pipeline_name.upper()} Pipeline:")
278
- for metric_name, values in metrics.items():
279
- if isinstance(values, dict):
280
- mean = values['mean']
281
- std = values['std']
282
- print(f" {metric_name}: {mean:.3f} ± {std:.3f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
 
284
  # Save detailed results
285
  with open(OUTPUT_FILE, 'w') as f:
@@ -287,27 +344,5 @@ def main():
287
 
288
  print(f"\nDetailed results saved to {OUTPUT_FILE}")
289
 
290
- # Generate comparison statement for paper
291
- print("\n" + "=" * 50)
292
- print("RESULTS SUMMARY FOR PAPER:")
293
- print("=" * 50)
294
-
295
- baseline = results.get('no_filter', {})
296
- species_region = results.get('species_and_region', {})
297
-
298
- if baseline and species_region:
299
- for k in K_VALUES:
300
- precision_baseline = baseline.get(f'precision@{k}', {}).get('mean', 0)
301
- precision_filtered = species_region.get(f'precision@{k}', {}).get('mean', 0)
302
- ndcg_baseline = baseline.get(f'ndcg@{k}', {}).get('mean', 0)
303
- ndcg_filtered = species_region.get(f'ndcg@{k}', {}).get('mean', 0)
304
-
305
- precision_improvement = ((precision_filtered - precision_baseline) / precision_baseline * 100) if precision_baseline > 0 else 0
306
- ndcg_improvement = ((ndcg_filtered - ndcg_baseline) / ndcg_baseline * 100) if ndcg_baseline > 0 else 0
307
-
308
- print(f"\nCompared to a region-agnostic baseline, precision@{k} improves from {precision_baseline:.3f} "
309
- f"to {precision_filtered:.3f} ({precision_improvement:+.1f}%) and nDCG@{k} from {ndcg_baseline:.3f} "
310
- f"to {ndcg_filtered:.3f} ({ndcg_improvement:+.1f}%) when using species and region filters.")
311
-
312
  if __name__ == "__main__":
313
  main()
 
42
 
43
  # Build context from metadata
44
  context_parts = []
45
+ species_name = metadata.get('matched_specie_0')
46
+ if species_name:
47
+ context_parts.append(f"Species: {species_name}")
48
  if 'common_name' in metadata:
49
  context_parts.append(f"Common Name: {metadata['common_name']}")
50
  if 'region' in metadata:
 
80
  except Exception as e:
81
  print(f"Error generating question: {e}")
82
  # Fallback question
83
+ species = metadata.get('matched_specie_0', 'this species')
84
  return f"What IPM information is available for {species}?"
85
 
86
  class RetrievalEvaluator:
 
141
  metadata = sample.metadata
142
 
143
  # Define filter strategies (using ChromaDB filter format)
144
+ species_value = metadata.get('matched_specie_0')
145
+ region_value = metadata.get('region')
146
+
147
  filters = {
148
  'no_filter': None,
149
+ 'species_only': {
150
+ '$or': [
151
+ {'matched_specie_0': {'$eq': species_value}},
152
+ {'matched_specie_1': {'$eq': species_value}},
153
+ {'matched_specie_2': {'$eq': species_value}}
154
+ ]
155
+ } if species_value else None,
156
+ 'region_only': {'region': {'$eq': region_value}} if region_value else None,
157
  'species_and_region': {
158
  '$and': [
159
+ {
160
+ '$or': [
161
+ {'matched_specie_0': {'$eq': species_value}},
162
+ {'matched_specie_1': {'$eq': species_value}},
163
+ {'matched_specie_2': {'$eq': species_value}}
164
+ ]
165
+ },
166
+ {'region': {'$eq': region_value}}
167
  ]
168
+ } if species_value and region_value else None
169
  }
170
 
171
  for filter_name, filter_dict in filters.items():
 
249
  chunks = load_chunks_from_vectordb(VECTOR_DB_PATH, sample_size=SAMPLE_SIZE)
250
  print(f" Loaded {len(chunks)} chunks")
251
 
252
+ # Step 1.5: Analyze metadata availability
253
+ print("\n Metadata Analysis:")
254
+ matched_specie_count = sum(1 for chunk in chunks if chunk['metadata'].get('matched_specie_0'))
255
+ region_count = sum(1 for chunk in chunks if chunk['metadata'].get('region'))
256
+ both_species_region = sum(1 for chunk in chunks if chunk['metadata'].get('matched_specie_0') and chunk['metadata'].get('region'))
257
+
258
+ print(f" - Chunks with 'matched_specie_0' field: {matched_specie_count}")
259
+ print(f" - Chunks with 'region' field: {region_count}")
260
+ print(f" - Chunks with species and region: {both_species_region}")
261
+
262
+ # Show sample metadata
263
+ if chunks:
264
+ sample_metadata = chunks[0]['metadata']
265
+ print(f" - Sample metadata keys: {list(sample_metadata.keys())}")
266
+ species_field = sample_metadata.get('matched_specie_0')
267
+ region_field = sample_metadata.get('region')
268
+ print(f" - Sample species: {species_field}")
269
+ print(f" - Sample region: {region_field}")
270
+
271
  # Step 2: Generate questions for chunks
272
  print("\n2. Generating questions from chunks...")
273
  question_generator = QuestionGenerator()
 
308
  print("\n4. Evaluation Results:")
309
  print("=" * 50)
310
 
311
+ # Create results table
312
+ pipelines = ['no_filter', 'species_only', 'region_only', 'species_and_region']
313
+ pipeline_names = ['No Filter', 'Species Only', 'Region Only', 'Species + Region']
314
+
315
+ # Precision table
316
+ print("\nPRECISION RESULTS:")
317
+ print("-" * 70)
318
+ print(f"{'Pipeline':<15} {'P@1':<8} {'P@3':<8} {'P@5':<8}")
319
+ print("-" * 70)
320
+
321
+ for i, pipeline in enumerate(pipelines):
322
+ if pipeline in results:
323
+ p1 = results[pipeline].get('precision@1', {}).get('mean', 0.0)
324
+ p3 = results[pipeline].get('precision@3', {}).get('mean', 0.0)
325
+ p5 = results[pipeline].get('precision@5', {}).get('mean', 0.0)
326
+ print(f"{pipeline_names[i]:<15} {p1:<8.3f} {p3:<8.3f} {p5:<8.3f}")
327
+
328
+ # nDCG table
329
+ print("\nnDCG RESULTS:")
330
+ print("-" * 70)
331
+ print(f"{'Pipeline':<15} {'nDCG@1':<8} {'nDCG@3':<8} {'nDCG@5':<8}")
332
+ print("-" * 70)
333
+
334
+ for i, pipeline in enumerate(pipelines):
335
+ if pipeline in results:
336
+ n1 = results[pipeline].get('ndcg@1', {}).get('mean', 0.0)
337
+ n3 = results[pipeline].get('ndcg@3', {}).get('mean', 0.0)
338
+ n5 = results[pipeline].get('ndcg@5', {}).get('mean', 0.0)
339
+ print(f"{pipeline_names[i]:<15} {n1:<8.3f} {n3:<8.3f} {n5:<8.3f}")
340
 
341
  # Save detailed results
342
  with open(OUTPUT_FILE, 'w') as f:
 
344
 
345
  print(f"\nDetailed results saved to {OUTPUT_FILE}")
346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  if __name__ == "__main__":
348
  main()
retrieval_evaluation_results.json CHANGED
@@ -1,130 +1,130 @@
1
  {
2
  "no_filter": {
3
  "precision@1": {
4
- "mean": 0.75,
5
- "std": 0.4330127018922193,
6
  "count": 20
7
  },
8
  "precision@3": {
9
- "mean": 0.95,
10
- "std": 0.21794494717703372,
11
  "count": 20
12
  },
13
  "precision@5": {
14
- "mean": 1.0,
15
- "std": 0.0,
16
  "count": 20
17
  },
18
  "ndcg@1": {
19
- "mean": 0.75,
20
- "std": 0.4330127018922193,
21
  "count": 20
22
  },
23
  "ndcg@3": {
24
- "mean": 0.8696394630357187,
25
- "std": 0.2567840676954238,
26
  "count": 20
27
  },
28
  "ndcg@5": {
29
- "mean": 0.8911732909393884,
30
- "std": 0.19311947983364772,
31
  "count": 20
32
  }
33
  },
34
  "species_only": {
35
  "precision@1": {
36
- "mean": 1.0,
37
- "std": 0.0,
38
- "count": 5
39
  },
40
  "precision@3": {
41
- "mean": 1.0,
42
- "std": 0.0,
43
- "count": 5
44
  },
45
  "precision@5": {
46
  "mean": 1.0,
47
  "std": 0.0,
48
- "count": 5
49
  },
50
  "ndcg@1": {
51
- "mean": 1.0,
52
- "std": 0.0,
53
- "count": 5
54
  },
55
  "ndcg@3": {
56
- "mean": 1.0,
57
- "std": 0.0,
58
- "count": 5
59
  },
60
  "ndcg@5": {
61
- "mean": 1.0,
62
- "std": 0.0,
63
- "count": 5
64
  }
65
  },
66
  "region_only": {
67
  "precision@1": {
68
- "mean": 0.75,
69
- "std": 0.4330127018922193,
70
  "count": 20
71
  },
72
  "precision@3": {
73
- "mean": 0.95,
74
- "std": 0.21794494717703372,
75
  "count": 20
76
  },
77
  "precision@5": {
78
- "mean": 1.0,
79
- "std": 0.0,
80
  "count": 20
81
  },
82
  "ndcg@1": {
83
- "mean": 0.75,
84
- "std": 0.4330127018922193,
85
  "count": 20
86
  },
87
  "ndcg@3": {
88
- "mean": 0.8696394630357187,
89
- "std": 0.2567840676954238,
90
  "count": 20
91
  },
92
  "ndcg@5": {
93
- "mean": 0.8911732909393884,
94
- "std": 0.19311947983364772,
95
  "count": 20
96
  }
97
  },
98
  "species_and_region": {
99
  "precision@1": {
100
- "mean": 1.0,
101
- "std": 0.0,
102
- "count": 5
103
  },
104
  "precision@3": {
105
- "mean": 1.0,
106
- "std": 0.0,
107
- "count": 5
108
  },
109
  "precision@5": {
110
  "mean": 1.0,
111
  "std": 0.0,
112
- "count": 5
113
  },
114
  "ndcg@1": {
115
- "mean": 1.0,
116
- "std": 0.0,
117
- "count": 5
118
  },
119
  "ndcg@3": {
120
- "mean": 1.0,
121
- "std": 0.0,
122
- "count": 5
123
  },
124
  "ndcg@5": {
125
- "mean": 1.0,
126
- "std": 0.0,
127
- "count": 5
128
  }
129
  }
130
  }
 
1
  {
2
  "no_filter": {
3
  "precision@1": {
4
+ "mean": 0.55,
5
+ "std": 0.49749371855331,
6
  "count": 20
7
  },
8
  "precision@3": {
9
+ "mean": 0.85,
10
+ "std": 0.3570714214271425,
11
  "count": 20
12
  },
13
  "precision@5": {
14
+ "mean": 0.9,
15
+ "std": 0.30000000000000004,
16
  "count": 20
17
  },
18
  "ndcg@1": {
19
+ "mean": 0.55,
20
+ "std": 0.49749371855331,
21
  "count": 20
22
  },
23
  "ndcg@3": {
24
+ "mean": 0.7327324383928644,
25
+ "std": 0.353724839687973,
26
  "count": 20
27
  },
28
  "ndcg@5": {
29
+ "mean": 0.7542662662965341,
30
+ "std": 0.319960314564507,
31
  "count": 20
32
  }
33
  },
34
  "species_only": {
35
  "precision@1": {
36
+ "mean": 0.7692307692307693,
37
+ "std": 0.4213250442347432,
38
+ "count": 13
39
  },
40
  "precision@3": {
41
+ "mean": 0.9230769230769231,
42
+ "std": 0.26646935501059654,
43
+ "count": 13
44
  },
45
  "precision@5": {
46
  "mean": 1.0,
47
  "std": 0.0,
48
+ "count": 13
49
  },
50
  "ndcg@1": {
51
+ "mean": 0.7692307692307693,
52
+ "std": 0.4213250442347432,
53
+ "count": 13
54
  },
55
  "ndcg@3": {
56
+ "mean": 0.8662968851648396,
57
+ "std": 0.28284691370224896,
58
+ "count": 13
59
  },
60
  "ndcg@5": {
61
+ "mean": 0.8960547934136506,
62
+ "std": 0.19766235701592574,
63
+ "count": 13
64
  }
65
  },
66
  "region_only": {
67
  "precision@1": {
68
+ "mean": 0.6,
69
+ "std": 0.48989794855663565,
70
  "count": 20
71
  },
72
  "precision@3": {
73
+ "mean": 0.85,
74
+ "std": 0.3570714214271425,
75
  "count": 20
76
  },
77
  "precision@5": {
78
+ "mean": 0.9,
79
+ "std": 0.30000000000000004,
80
  "count": 20
81
  },
82
  "ndcg@1": {
83
+ "mean": 0.6,
84
+ "std": 0.48989794855663565,
85
  "count": 20
86
  },
87
  "ndcg@3": {
88
+ "mean": 0.7511859507142915,
89
+ "std": 0.3575390024008766,
90
  "count": 20
91
  },
92
  "ndcg@5": {
93
+ "mean": 0.7727197786179613,
94
+ "std": 0.32294384868681797,
95
  "count": 20
96
  }
97
  },
98
  "species_and_region": {
99
  "precision@1": {
100
+ "mean": 0.8461538461538461,
101
+ "std": 0.36080121229410994,
102
+ "count": 13
103
  },
104
  "precision@3": {
105
+ "mean": 0.9230769230769231,
106
+ "std": 0.26646935501059654,
107
+ "count": 13
108
  },
109
  "precision@5": {
110
  "mean": 1.0,
111
  "std": 0.0,
112
+ "count": 13
113
  },
114
  "ndcg@1": {
115
+ "mean": 0.8461538461538461,
116
+ "std": 0.36080121229410994,
117
+ "count": 13
118
  },
119
  "ndcg@3": {
120
+ "mean": 0.8946869041208814,
121
+ "std": 0.27624290045474437,
122
+ "count": 13
123
  },
124
  "ndcg@5": {
125
+ "mean": 0.9244448123696922,
126
+ "std": 0.18354431531186644,
127
+ "count": 13
128
  }
129
  }
130
  }
vector-databases-deployed/db5-agllm-data-isu-field-insects-all-species/chroma.sqlite3 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0323fbf65a7d0d8cfbad75ed514829fc5d979a0d89603c61f511ed46c87dd69e
3
  size 9072640
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4942e0dbb09693a3162b420dd2471ef8fcfaa541f479979627fa6125d12f2af6
3
  size 9072640
vector-databases-deployed/db5-agllm-data-isu-field-insects-all-species/e82d58e5-16f1-41a6-9289-211464329861/length.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b0eca7ce2600dfc137188f7b969056d2155f188796a248ab9b3b78f60431df7e
3
  size 40000
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e632323b84e2258a31c2401bbb859c7fc59cd994aa4f6b2217651488f3cf3be3
3
  size 40000