raviix46 commited on
Commit
6747e10
·
verified ·
1 Parent(s): 9890c71

Create rag_sessions.py

Browse files
Files changed (1) hide show
  1. rag_sessions.py +29 -0
rag_sessions.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import uuid
2
+
3
+ SESSIONS = {} # session_id -> {thread_id, recent_turns, entity_memory}
4
+
5
+
6
+ def start_session(thread_id: str) -> str:
7
+ """Create a new session fixed to a given thread."""
8
+ sid = str(uuid.uuid4())
9
+ SESSIONS[sid] = {
10
+ "thread_id": thread_id,
11
+ "recent_turns": [],
12
+ "entity_memory": {}, # extend later if needed
13
+ }
14
+ return sid
15
+
16
+
17
+ def get_session(session_id: str):
18
+ return SESSIONS.get(session_id)
19
+
20
+
21
+ def reset_session(session_id: str):
22
+ """Reset memory but keep the same thread."""
23
+ if session_id in SESSIONS:
24
+ tid = SESSIONS[session_id]["thread_id"]
25
+ SESSIONS[session_id] = {
26
+ "thread_id": tid,
27
+ "recent_turns": [],
28
+ "entity_memory": {},
29
+ }