Rajhuggingface4253 commited on
Commit
20d4042
·
verified ·
1 Parent(s): fe9701d

Update vector.py

Browse files
Files changed (1) hide show
  1. vector.py +7 -4
vector.py CHANGED
@@ -162,7 +162,7 @@ class VectorDatabase:
162
 
163
  return chunks
164
 
165
- def store_session_document(self, text: str, filename: str, user_id: str):
166
  """Store extracted file content with user session isolation"""
167
  if not text or len(text) < 10 or not user_id:
168
  logger.warning(f"Invalid input for {filename}")
@@ -211,6 +211,7 @@ class VectorDatabase:
211
  "subtype": chunk.get("type", "general"),
212
  "name": chunk.get("name", "unknown"),
213
  "user_id": user_id,
 
214
  "timestamp": time.time(),
215
  "chunk_index": len(final_texts)
216
  })
@@ -250,7 +251,7 @@ class VectorDatabase:
250
  if user_vectors < expected_count:
251
  logger.warning(f"⚠️ Storage mismatch for user {user_id[:8]}")
252
 
253
- def store_chat_context(self, messages: list, user_id: str):
254
  """Store chat history as session memory"""
255
  if not messages or not user_id:
256
  return False
@@ -282,6 +283,7 @@ class VectorDatabase:
282
  "source": "chat_history",
283
  "type": "history",
284
  "user_id": user_id,
 
285
  "timestamp": time.time(),
286
  "chunk_index": i
287
  })
@@ -303,7 +305,7 @@ class VectorDatabase:
303
  logger.error(f"Failed to store chat history: {e}")
304
  return False
305
 
306
- def retrieve_session_context(self, query: str, user_id: str, filter_type: str = None, top_k=100, final_k=5):
307
  """Retrieve context only from the user's session"""
308
  if self.index.ntotal == 0 or not user_id:
309
  logger.warning(f"Empty index or missing user_id. Index size: {self.index.ntotal}")
@@ -340,7 +342,8 @@ class VectorDatabase:
340
  # STRICT user filtering
341
  if item.get("user_id") != user_id:
342
  continue
343
-
 
344
  # Optional type filtering
345
  if filter_type and item.get("type") != filter_type:
346
  continue
 
162
 
163
  return chunks
164
 
165
+ def store_session_document(self, text: str, filename: str, user_id: str, chat_id: str):
166
  """Store extracted file content with user session isolation"""
167
  if not text or len(text) < 10 or not user_id:
168
  logger.warning(f"Invalid input for {filename}")
 
211
  "subtype": chunk.get("type", "general"),
212
  "name": chunk.get("name", "unknown"),
213
  "user_id": user_id,
214
+ "chat_id": chat_id,
215
  "timestamp": time.time(),
216
  "chunk_index": len(final_texts)
217
  })
 
251
  if user_vectors < expected_count:
252
  logger.warning(f"⚠️ Storage mismatch for user {user_id[:8]}")
253
 
254
+ def store_chat_context(self, messages: list, user_id: str, chat_id: str):
255
  """Store chat history as session memory"""
256
  if not messages or not user_id:
257
  return False
 
283
  "source": "chat_history",
284
  "type": "history",
285
  "user_id": user_id,
286
+ "chat_id": chat_id,
287
  "timestamp": time.time(),
288
  "chunk_index": i
289
  })
 
305
  logger.error(f"Failed to store chat history: {e}")
306
  return False
307
 
308
+ def retrieve_session_context(self, query: str, user_id: str, chat_id: str, filter_type: str = None, top_k=100, final_k=5):
309
  """Retrieve context only from the user's session"""
310
  if self.index.ntotal == 0 or not user_id:
311
  logger.warning(f"Empty index or missing user_id. Index size: {self.index.ntotal}")
 
342
  # STRICT user filtering
343
  if item.get("user_id") != user_id:
344
  continue
345
+ if item.get("chat_id") != chat_id:
346
+ continue
347
  # Optional type filtering
348
  if filter_type and item.get("type") != filter_type:
349
  continue