KeenWoo commited on
Commit
045f4b3
·
verified ·
1 Parent(s): dae4621

Update alz_companion/agent.py

Browse files
Files changed (1) hide show
  1. alz_companion/agent.py +11 -20
alz_companion/agent.py CHANGED
@@ -483,32 +483,21 @@ def route_query_type(query: str, severity: str = "Normal / Unspecified"):
483
 
484
  # helper: put near other small utils in agent.py
485
  # In agent.py, replace the _source_ids_for_eval function
486
- def _source_ids_for_eval(docs, cap=5):
487
- """
488
- Return the source identifiers for evaluation.
489
- - For jsonl files, it returns the numeric chunk ID or the scene_id if present.
490
- - For ANY other source, it returns the generic name "Text Input".
491
- - It excludes the 'placeholder' source.
492
- """
493
  out, seen = [], set()
494
  for d in docs or []:
495
  md = getattr(d, "metadata", {}) or {}
496
- src = str(md.get("source", "")).lower()
497
 
498
- if src == 'placeholder':
499
  continue
500
 
501
- key = None
502
-
503
- if src.endswith(".jsonl"):
504
- # Prioritize 'scene_id' if it exists (for alive_inside.jsonl)
505
- if 'scene_id' in md:
506
- key = str(md['scene_id'])
507
- # Fallback to numeric chunk ID for other jsonl files
508
- elif 'chunk' in md and isinstance(md['chunk'], int):
509
- key = str(md['chunk'])
510
- else:
511
- key = "Text Input"
512
 
513
  if key and key not in seen:
514
  seen.add(key)
@@ -517,6 +506,8 @@ def _source_ids_for_eval(docs, cap=5):
517
  break
518
  return out
519
 
 
 
520
 
521
  # In agent.py, replace the ENTIRE make_rag_chain function with this one.
522
  # def make_rag_chain(vs_general: FAISS, vs_personal: FAISS, *, for_evaluation: bool = False, role: str = "patient", temperature: float = 0.6, language: str = "English", patient_name: str = "the patient", caregiver_name: str = "the caregiver", tone: str = "warm"):
 
483
 
484
  # helper: put near other small utils in agent.py
485
  # In agent.py, replace the _source_ids_for_eval function
486
+ # In agent.py, inside _source_ids_for_eval(...)
487
+
488
+ def _source_ids_for_eval(docs, cap=3): # NEW change from 5 to 3
 
 
 
 
489
  out, seen = [], set()
490
  for d in docs or []:
491
  md = getattr(d, "metadata", {}) or {}
492
+ src = md.get("source")
493
 
494
+ if not src or src == 'placeholder':
495
  continue
496
 
497
+ # --- MODIFICATION START ---
498
+ # Always use the filename as the key, regardless of file type.
499
+ key = src
500
+ # --- MODIFICATION END ---
 
 
 
 
 
 
 
501
 
502
  if key and key not in seen:
503
  seen.add(key)
 
506
  break
507
  return out
508
 
509
+
510
+
511
 
512
  # In agent.py, replace the ENTIRE make_rag_chain function with this one.
513
  # def make_rag_chain(vs_general: FAISS, vs_personal: FAISS, *, for_evaluation: bool = False, role: str = "patient", temperature: float = 0.6, language: str = "English", patient_name: str = "the patient", caregiver_name: str = "the caregiver", tone: str = "warm"):