Spaces:
Sleeping
Sleeping
Fix: Add fallback object_path from cohort_key for document references
Browse files- rag/qa_pipeline.py +9 -0
rag/qa_pipeline.py
CHANGED
|
@@ -278,6 +278,15 @@ def ask_ai_stream_delta(message: str, history: List, hybrid_retriever, cohort_ke
|
|
| 278 |
if source_key not in seen_sources:
|
| 279 |
seen_sources.add(source_key)
|
| 280 |
object_path = str(doc_info.get('object_path') or '').strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
if object_path:
|
| 282 |
yield f"- **{object_path}** (Trang {doc_info['page']})\n"
|
| 283 |
else:
|
|
|
|
| 278 |
if source_key not in seen_sources:
|
| 279 |
seen_sources.add(source_key)
|
| 280 |
object_path = str(doc_info.get('object_path') or '').strip()
|
| 281 |
+
# Nếu không có object_path, thử tạo từ source_file
|
| 282 |
+
if not object_path and doc_info['source'] and doc_info['source'] != "Không rõ":
|
| 283 |
+
# Giả sử mỗi cohort có thư mục k65/, k66/ v.v.
|
| 284 |
+
# Fallback: nếu source có phần đầu là k\d, dùng nó; nếu không thì dùng tên file
|
| 285 |
+
source_file = doc_info['source']
|
| 286 |
+
# Kiểm tra xem có cohort_key trong source không (format "k65_document.pdf" hoặc tương tự)
|
| 287 |
+
if cohort_key:
|
| 288 |
+
object_path = f"{cohort_key}/{source_file}"
|
| 289 |
+
|
| 290 |
if object_path:
|
| 291 |
yield f"- **{object_path}** (Trang {doc_info['page']})\n"
|
| 292 |
else:
|