Spaces:
Sleeping
Sleeping
fix set_payloaf qdrant
Browse files- core/document_ingest_service.py +23 -34
core/document_ingest_service.py
CHANGED
|
@@ -242,47 +242,36 @@ def _get_or_create_deduplicated_points(
|
|
| 242 |
"source_updated_at": source_updated_at or existing_payload.get("source_updated_at"),
|
| 243 |
}
|
| 244 |
|
| 245 |
-
|
|
|
|
| 246 |
collection_name=collection_name,
|
| 247 |
-
|
| 248 |
points=[existing_point_id],
|
| 249 |
)
|
| 250 |
logger.info(f"Đã cập nhật years cho hash {content_hash[:8]}...: {merged_years}")
|
|
|
|
|
|
|
| 251 |
except Exception as e:
|
| 252 |
logger.warning(f"Lỗi cập nhật years cho point đã tồn tại: {e}, sẽ tạo point mới")
|
| 253 |
-
# Fallback: tạo point mới
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
# Tạo point mới
|
| 271 |
-
point_id = str(uuid.uuid4())
|
| 272 |
-
payload = _build_payload(
|
| 273 |
-
document, source_object_ref, chunk_text, index, metadata,
|
| 274 |
-
academic_year, years, content_hash, source_url,
|
| 275 |
-
source_updated_at, source_etag, created_at, effective_source_path
|
| 276 |
-
)
|
| 277 |
-
points.append(PointStruct(id=point_id, vector=vector, payload=payload))
|
| 278 |
-
db_chunk_rows.append(
|
| 279 |
-
DocumentChunk(
|
| 280 |
-
document_id=document.id,
|
| 281 |
-
chunk_index=index,
|
| 282 |
-
content_preview=chunk_text[:200],
|
| 283 |
-
qdrant_point_id=point_id,
|
| 284 |
-
)
|
| 285 |
)
|
|
|
|
| 286 |
|
| 287 |
return points, db_chunk_rows
|
| 288 |
|
|
|
|
| 242 |
"source_updated_at": source_updated_at or existing_payload.get("source_updated_at"),
|
| 243 |
}
|
| 244 |
|
| 245 |
+
# ✅ Dùng set_payload để cập nhật payload
|
| 246 |
+
client.set_payload(
|
| 247 |
collection_name=collection_name,
|
| 248 |
+
payload=updated_payload,
|
| 249 |
points=[existing_point_id],
|
| 250 |
)
|
| 251 |
logger.info(f"Đã cập nhật years cho hash {content_hash[:8]}...: {merged_years}")
|
| 252 |
+
# ✅ QUAN TRỌNG: Bỏ qua tạo point mới - vì đã cập nhật point đã tồn tại
|
| 253 |
+
continue
|
| 254 |
except Exception as e:
|
| 255 |
logger.warning(f"Lỗi cập nhật years cho point đã tồn tại: {e}, sẽ tạo point mới")
|
| 256 |
+
# Fallback: tạo point mới nếu cập nhật thất bại
|
| 257 |
+
pass
|
| 258 |
+
|
| 259 |
+
# Tạo point mới
|
| 260 |
+
point_id = str(uuid.uuid4())
|
| 261 |
+
payload = _build_payload(
|
| 262 |
+
document, source_object_ref, chunk_text, index, metadata,
|
| 263 |
+
academic_year, years, content_hash, source_url,
|
| 264 |
+
source_updated_at, source_etag, created_at, effective_source_path
|
| 265 |
+
)
|
| 266 |
+
points.append(PointStruct(id=point_id, vector=vector, payload=payload))
|
| 267 |
+
db_chunk_rows.append(
|
| 268 |
+
DocumentChunk(
|
| 269 |
+
document_id=document.id,
|
| 270 |
+
chunk_index=index,
|
| 271 |
+
content_preview=chunk_text[:200],
|
| 272 |
+
qdrant_point_id=point_id,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
)
|
| 274 |
+
)
|
| 275 |
|
| 276 |
return points, db_chunk_rows
|
| 277 |
|