Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: handle missing ES/OpenSearch index in check_embedding (HTTP 500 on empty dataset) (#16650)

OSHA-B779bf52549c6
diff --git a/api/apps/services/dataset_api_service.py b/api/apps/services/dataset_api_service.py
index 62ae708562..f972e35c3f 100644
--- a/api/apps/services/dataset_api_service.py
+++ b/api/apps/services/dataset_api_service.py
@@ -1152,18 +1152,28 @@ def check_embedding(dataset_id: str, tenant_id: str, req: dict):
base_fields=("docnm_kwd", "doc_id", "content_with_weight", "page_num_int", "position_int", "top_int"),
):
index_nm = search.index_name(tenant_id)
-
- res0 = docStoreConn.search(
- select_fields=[],
- highlight_fields=[],
- condition={"kb_id": kb_id, "available_int": 1},
- match_expressions=[],
- order_by=OrderByExpr(),
- offset=0,
- limit=1,
- index_names=index_nm,
- knowledgebase_ids=[kb_id],
- )
+ try:
+ res0 = docStoreConn.search(
+ select_fields=[],
+ highlight_fields=[],
+ condition={"kb_id": kb_id, "available_int": 1},
+ match_expressions=[],
+ order_by=OrderByExpr(),
+ offset=0,
+ limit=1,
+ index_names=index_nm,
+ knowledgebase_ids=[kb_id],
+ )
+ except Exception as e:
+ if "not_found_exception" in repr(e) or "index_not_found_exception" in repr(e):
+ logging.info(
+ "sample_random_chunks_with_vectors: index %s not yet created for tenant %s; "
+ "returning empty sample set",
+ index_nm,
+ tenant_id,
+ )
+ return []
+ raise
total = docStoreConn.get_total(res0)
if total <= 0:
return []