Update recursive_context.py
Browse files- recursive_context.py +25 -3
recursive_context.py
CHANGED
|
@@ -721,20 +721,42 @@ class RecursiveContextManager:
|
|
| 721 |
testament_results.sort(key=lambda r: (not r.get('is_testament', False)))
|
| 722 |
return testament_results[:n]
|
| 723 |
|
| 724 |
-
|
| 725 |
-
"""
|
| 726 |
try:
|
| 727 |
return {
|
| 728 |
"total_files": self.collection.count(),
|
| 729 |
"indexed_chunks": self.collection.count(),
|
| 730 |
"conversations": self.conversations.count(),
|
| 731 |
-
"chroma_path": CHROMA_DB_PATH,
|
| 732 |
"persistence_configured": self.persistence.is_configured,
|
| 733 |
"indexing_in_progress": False
|
| 734 |
}
|
| 735 |
except Exception as e:
|
| 736 |
return {"index_error": str(e)}
|
| 737 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
def save_conversation_turn(self, u, a, t_id):
|
| 739 |
"""Save turn locally and push the FULL history to the cloud to prevent memory loss."""
|
| 740 |
combined = f"USER: {u}\n\nASSISTANT: {a}"
|
|
|
|
| 721 |
testament_results.sort(key=lambda r: (not r.get('is_testament', False)))
|
| 722 |
return testament_results[:n]
|
| 723 |
|
| 724 |
+
def get_stats(self) -> dict:
|
| 725 |
+
"""WHY: Provides the 'Face Documentation' for the sidebar metrics."""
|
| 726 |
try:
|
| 727 |
return {
|
| 728 |
"total_files": self.collection.count(),
|
| 729 |
"indexed_chunks": self.collection.count(),
|
| 730 |
"conversations": self.conversations.count(),
|
| 731 |
+
"chroma_path": str(CHROMA_DB_PATH),
|
| 732 |
"persistence_configured": self.persistence.is_configured,
|
| 733 |
"indexing_in_progress": False
|
| 734 |
}
|
| 735 |
except Exception as e:
|
| 736 |
return {"index_error": str(e)}
|
| 737 |
|
| 738 |
+
def save_conversation_turn(self, u, a, t_id):
|
| 739 |
+
"""WHY: Prevents amnesia by pushing the FULL history to the cloud, not just the last turn."""
|
| 740 |
+
combined = f"USER: {u}\n\nASSISTANT: {a}"
|
| 741 |
+
u_id = f"turn_{int(time.time())}"
|
| 742 |
+
|
| 743 |
+
# 1. Save locally to Chroma
|
| 744 |
+
self.conversations.add(documents=[combined], metadatas=[{"turn": t_id}], ids=[u_id])
|
| 745 |
+
|
| 746 |
+
# 2. Retrieve ALL history so the cloud backup is a complete record
|
| 747 |
+
all_convs = self.conversations.get()
|
| 748 |
+
full_data = []
|
| 749 |
+
for i in range(len(all_convs['ids'])):
|
| 750 |
+
full_data.append({
|
| 751 |
+
"document": all_convs['documents'][i],
|
| 752 |
+
"metadata": all_convs['metadatas'][i],
|
| 753 |
+
"id": all_convs['ids'][i]
|
| 754 |
+
})
|
| 755 |
+
|
| 756 |
+
# 3. Push complete manifest to PRO storage
|
| 757 |
+
self.persistence.save_conversations(full_data)
|
| 758 |
+
|
| 759 |
+
|
| 760 |
def save_conversation_turn(self, u, a, t_id):
|
| 761 |
"""Save turn locally and push the FULL history to the cloud to prevent memory loss."""
|
| 762 |
combined = f"USER: {u}\n\nASSISTANT: {a}"
|