minh-4T commited on
Commit
bb5223e
·
1 Parent(s): 75f2cf3

change config and multithreading llm

Browse files
Files changed (2) hide show
  1. core/config.py +1 -1
  2. core/qa_pipeline.py +39 -5
core/config.py CHANGED
@@ -45,7 +45,7 @@ CROSS_ENCODER_MODEL = os.getenv('CROSS_ENCODER_MODEL', 'itdainb/PhoRanker')
45
  # Chunking and retrieval settings
46
  CHUNK_SIZE = int(os.getenv('CHUNK_SIZE', '800'))
47
  CHUNK_OVERLAP = int(os.getenv('CHUNK_OVERLAP', '150'))
48
- TOP_K_RESULTS = int(os.getenv('TOP_K_RESULTS', '8'))
49
  FINAL_TOP_K = int(os.getenv('FINAL_TOP_K', '3'))
50
 
51
  QDRANT_COLLECTION = os.getenv('QDRANT_COLLECTION', 'rag_docs')
 
45
  # Chunking and retrieval settings
46
  CHUNK_SIZE = int(os.getenv('CHUNK_SIZE', '800'))
47
  CHUNK_OVERLAP = int(os.getenv('CHUNK_OVERLAP', '150'))
48
+ TOP_K_RESULTS = int(os.getenv('TOP_K_RESULTS', '15'))
49
  FINAL_TOP_K = int(os.getenv('FINAL_TOP_K', '3'))
50
 
51
  QDRANT_COLLECTION = os.getenv('QDRANT_COLLECTION', 'rag_docs')
core/qa_pipeline.py CHANGED
@@ -295,15 +295,49 @@ def ask_ai_stream_delta(message: str, history: List, hybrid_retriever) -> Genera
295
  yield quick_reply
296
  return
297
 
298
- # Phân tích câu hỏi
299
  logger.info(f"CÂU HỎI GỐC: {message}")
300
- question = generate_standalone_query(message, history)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  requested_year_range, mentioned_years = detect_requested_year(f"{message}\n{question}")
302
  year_scope_hint = requested_year_range or (", ".join(sorted(mentioned_years)) if mentioned_years else None)
303
 
304
- # Phân loại và mở rộng từ khóa
305
- processed_data = analyze_and_expand_query(question)
306
-
307
  if processed_data.get("question_type") == "normal":
308
  ans = processed_data.get("answer") or "Chào bạn 👋 Mình hỗ trợ tra cứu quy chế đào tạo."
309
  yield ans
 
295
  yield quick_reply
296
  return
297
 
298
+ # Song song : generate_standalone_query + analyze_and_expand_query cùng 1 lúc, không chờ đợi lẫn nhau, giảm độ trễ tổng thể
299
  logger.info(f"CÂU HỎI GỐC: {message}")
300
+
301
+ try:
302
+ with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
303
+ # Call 1: Tạo standalone question từ history
304
+ future_standalone = executor.submit(
305
+ generate_standalone_query,
306
+ message,
307
+ history
308
+ )
309
+
310
+ # Call 2: Phân loại & mở rộng (song parallel)
311
+ # Dùng message gốc luôn, LLM sẽ handle context từ message
312
+ future_classify = executor.submit(
313
+ analyze_and_expand_query,
314
+ message # ✅ Dùng message gốc, không chờ standalone xong
315
+ )
316
+
317
+ # Chờ cả 2 xong (timeout 15s)
318
+ question = future_standalone.result(timeout=15)
319
+ processed_data = future_classify.result(timeout=15)
320
+
321
+ except concurrent.futures.TimeoutError:
322
+ logger.warning("Timeout khi gọi LLM song parallel, fallback...")
323
+ question = message
324
+ processed_data = {
325
+ "question_type": "simple",
326
+ "answer": None,
327
+ "expanded_queries": [message]
328
+ }
329
+ except Exception as e:
330
+ logger.warning(f"Lỗi parallel execution: {e}, fallback...")
331
+ question = message
332
+ processed_data = {
333
+ "question_type": "simple",
334
+ "answer": None,
335
+ "expanded_queries": [message]
336
+ }
337
+
338
  requested_year_range, mentioned_years = detect_requested_year(f"{message}\n{question}")
339
  year_scope_hint = requested_year_range or (", ".join(sorted(mentioned_years)) if mentioned_years else None)
340
 
 
 
 
341
  if processed_data.get("question_type") == "normal":
342
  ans = processed_data.get("answer") or "Chào bạn 👋 Mình hỗ trợ tra cứu quy chế đào tạo."
343
  yield ans