Spaces:
Running
Running
Update alz_companion/agent.py
Browse files- alz_companion/agent.py +14 -1
alz_companion/agent.py
CHANGED
|
@@ -116,6 +116,10 @@ FACTUAL_KEYPHRASES = [
|
|
| 116 |
r"\b(where is|where was) my\b",
|
| 117 |
r"\b(how old am i)\b",
|
| 118 |
# r"\b(when did|what did) the journal say\b"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
]
|
| 120 |
_FQ_PATTERNS = [re.compile(p, re.IGNORECASE) for p in FACTUAL_KEYPHRASES]
|
| 121 |
|
|
@@ -459,6 +463,14 @@ def route_query_type(query: str, severity: str = "Normal / Unspecified"):
|
|
| 459 |
print(f"Query classified as: {sum_hit} (summarization pre-router)")
|
| 460 |
return sum_hit
|
| 461 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
# Priority 4: Check for music requests.
|
| 463 |
# NEW Add Music Support before care_hit = _pre_router(query)
|
| 464 |
# the general "caregiving" keyword checker (_pre_router) is called before
|
|
@@ -479,7 +491,7 @@ def route_query_type(query: str, severity: str = "Normal / Unspecified"):
|
|
| 479 |
query_type = _llm_route_with_prompt(query, temperature=0.0)
|
| 480 |
print(f"Query classified as: {query_type} (LLM router)")
|
| 481 |
return query_type
|
| 482 |
-
|
| 483 |
|
| 484 |
# helper: put near other small utils in agent.py
|
| 485 |
# In agent.py, replace the _source_ids_for_eval function
|
|
@@ -665,6 +677,7 @@ def make_rag_chain(vs_general: FAISS, vs_personal: FAISS, *, for_evaluation: boo
|
|
| 665 |
# This logic retrieves all documents from the personal FAISS store and then
|
| 666 |
# filters them to include ONLY text-based sources, excluding media files.
|
| 667 |
print("[DEBUG] Personal Memory Route Activated. Retrieving all personal text documents...")
|
|
|
|
| 668 |
if vs_personal and vs_personal.docstore and len(vs_personal.index_to_docstore_id) > 0:
|
| 669 |
# 1. Get all documents from the FAISS docstore
|
| 670 |
all_personal_docs = list(vs_personal.docstore._dict.values())
|
|
|
|
| 116 |
r"\b(where is|where was) my\b",
|
| 117 |
r"\b(how old am i)\b",
|
| 118 |
# r"\b(when did|what did) the journal say\b"
|
| 119 |
+
# NEW below to handle what is/are movdies/videos separating from songs/music
|
| 120 |
+
r"\b(what|who|where|when|which)\b.*(is|are|was|were|am)\b.*\b(my|i|me|our)\b",
|
| 121 |
+
r"\b(do you remember|tell me about|what do you know about)\b.*\b(my|i|me|our)\b",
|
| 122 |
+
r"\b(my|our)\b.*\bfavorite\b"
|
| 123 |
]
|
| 124 |
_FQ_PATTERNS = [re.compile(p, re.IGNORECASE) for p in FACTUAL_KEYPHRASES]
|
| 125 |
|
|
|
|
| 463 |
print(f"Query classified as: {sum_hit} (summarization pre-router)")
|
| 464 |
return sum_hit
|
| 465 |
|
| 466 |
+
# --- START: ADDED FACTUAL CHECK ---
|
| 467 |
+
# Priority 3: Check for personal factual questions.
|
| 468 |
+
factual_hit = _pre_router_factual(query)
|
| 469 |
+
if factual_hit:
|
| 470 |
+
print(f"Query classified as: {factual_hit} (factual pre-router)")
|
| 471 |
+
return factual_hit
|
| 472 |
+
# --- END: ADDED FACTUAL CHECK ---
|
| 473 |
+
|
| 474 |
# Priority 4: Check for music requests.
|
| 475 |
# NEW Add Music Support before care_hit = _pre_router(query)
|
| 476 |
# the general "caregiving" keyword checker (_pre_router) is called before
|
|
|
|
| 491 |
query_type = _llm_route_with_prompt(query, temperature=0.0)
|
| 492 |
print(f"Query classified as: {query_type} (LLM router)")
|
| 493 |
return query_type
|
| 494 |
+
# END route_query_type
|
| 495 |
|
| 496 |
# helper: put near other small utils in agent.py
|
| 497 |
# In agent.py, replace the _source_ids_for_eval function
|
|
|
|
| 677 |
# This logic retrieves all documents from the personal FAISS store and then
|
| 678 |
# filters them to include ONLY text-based sources, excluding media files.
|
| 679 |
print("[DEBUG] Personal Memory Route Activated. Retrieving all personal text documents...")
|
| 680 |
+
|
| 681 |
if vs_personal and vs_personal.docstore and len(vs_personal.index_to_docstore_id) > 0:
|
| 682 |
# 1. Get all documents from the FAISS docstore
|
| 683 |
all_personal_docs = list(vs_personal.docstore._dict.values())
|