Spaces:
Runtime error
Runtime error
change config and multithreading llm
Browse filesFiles changed (2)
- core/config.py+1-1
- core/qa_pipeline.py+39-5
44 unmodified lines4546474849505144 unmodified lines# Chunking and retrieval settingsCHUNK_SIZE = int(os.getenv('CHUNK_SIZE', '800'))CHUNK_OVERLAP = int(os.getenv('CHUNK_OVERLAP', '150'))TOP_K_RESULTS = int(os.getenv('TOP_K_RESULTS', '8'))FINAL_TOP_K = int(os.getenv('FINAL_TOP_K', '3'))QDRANT_COLLECTION = os.getenv('QDRANT_COLLECTION', 'rag_docs')44 unmodified lines4546474849505144 unmodified lines# Chunking and retrieval settingsCHUNK_SIZE = int(os.getenv('CHUNK_SIZE', '800'))CHUNK_OVERLAP = int(os.getenv('CHUNK_OVERLAP', '150'))TOP_K_RESULTS = int(os.getenv('TOP_K_RESULTS', '15'))FINAL_TOP_K = int(os.getenv('FINAL_TOP_K', '3'))QDRANT_COLLECTION = os.getenv('QDRANT_COLLECTION', 'rag_docs')
294 unmodified lines295296297298299300301302303304305306307308309294 unmodified linesyield quick_replyreturn# Phân tích câu hỏilogger.info(f"CÂU HỎI GỐC: {message}")question = generate_standalone_query(message, history)requested_year_range, mentioned_years = detect_requested_year(f"{message}\n{question}")year_scope_hint = requested_year_range or (", ".join(sorted(mentioned_years)) if mentioned_years else None)# Phân loại và mở rộng từ khóaprocessed_data = analyze_and_expand_query(question)if processed_data.get("question_type") == "normal":ans = processed_data.get("answer") or "Chào bạn 👋 Mình hỗ trợ tra cứu quy chế đào tạo."yield ans294 unmodified lines295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343294 unmodified linesyield quick_replyreturn# 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ểlogger.info(f"CÂU HỎI GỐC: {message}")try:with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:# Call 1: Tạo standalone question từ historyfuture_standalone = executor.submit(generate_standalone_query,message,history)# Call 2: Phân loại & mở rộng (song parallel)# Dùng message gốc luôn, LLM sẽ handle context từ messagefuture_classify = executor.submit(analyze_and_expand_query,message # ✅ Dùng message gốc, không chờ standalone xong)# Chờ cả 2 xong (timeout 15s)question = future_standalone.result(timeout=15)processed_data = future_classify.result(timeout=15)except concurrent.futures.TimeoutError:logger.warning("Timeout khi gọi LLM song parallel, fallback...")question = messageprocessed_data = {"question_type": "simple","answer": None,"expanded_queries": [message]}except Exception as e:logger.warning(f"Lỗi parallel execution: {e}, fallback...")question = messageprocessed_data = {"question_type": "simple","answer": None,"expanded_queries": [message]}requested_year_range, mentioned_years = detect_requested_year(f"{message}\n{question}")year_scope_hint = requested_year_range or (", ".join(sorted(mentioned_years)) if mentioned_years else None)if processed_data.get("question_type") == "normal":ans = processed_data.get("answer") or "Chào bạn 👋 Mình hỗ trợ tra cứu quy chế đào tạo."yield ans
core/config.py+1-1
core/qa_pipeline.py+39-5