Debdeep30 commited on
Commit
4448a55
·
verified ·
1 Parent(s): f7e4604

Upload pipeline/memory.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pipeline/memory.py +26 -0
pipeline/memory.py CHANGED
@@ -93,6 +93,32 @@ def get_context(patient_id: str, n_sessions: int = 3) -> dict:
93
  }
94
 
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  # ---------------------------------------------------------------------------
97
  # System prompt builder
98
  # ---------------------------------------------------------------------------
 
93
  }
94
 
95
 
96
+ def get_all_summaries(patient_id: str) -> list[dict]:
97
+ """
98
+ Returns a chronological list of all session summaries with metadata.
99
+ """
100
+ col = _get_collection()
101
+ results = col.get(
102
+ where={"patient_id": patient_id},
103
+ include=["documents", "metadatas"]
104
+ )
105
+
106
+ summaries = []
107
+ if results["documents"]:
108
+ for doc, meta in zip(results["documents"], results["metadatas"]):
109
+ summaries.append({
110
+ "summary": doc,
111
+ "timestamp": meta.get("timestamp"),
112
+ "emotional_state": meta.get("emotional_state"),
113
+ "confusion_level": meta.get("confusion_level"),
114
+ "facts": json.loads(meta.get("facts", "[]"))
115
+ })
116
+
117
+ # Sort by timestamp (ISO format strings sort correctly)
118
+ summaries.sort(key=lambda x: x["timestamp"], reverse=True)
119
+ return summaries
120
+
121
+
122
  # ---------------------------------------------------------------------------
123
  # System prompt builder
124
  # ---------------------------------------------------------------------------