RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(raptor): handle missing vector fields gracefully (#12713)
E.Gf367189703b2
diff --git a/rag/svr/task_executor.py b/rag/svr/task_executor.pyindex cf2a37bea0..15db3a8a76 100644--- a/rag/svr/task_executor.py+++ b/rag/svr/task_executor.py@@ -806,20 +806,49 @@ async def run_raptor_for_kb(row, kb_parser_config, chat_mdl, embd_mdl, vector_siif raptor_config.get("scope", "file") == "file":for x, doc_id in enumerate(doc_ids):chunks = []+ skipped_chunks = 0for d in settings.retriever.chunk_list(doc_id, row["tenant_id"], [str(row["kb_id"])],fields=["content_with_weight", vctr_nm],sort_by_position=True):+ # Skip chunks that don't have the required vector field (may have been indexed with different embedding model)+ if vctr_nm not in d or d[vctr_nm] is None:+ skipped_chunks += 1+ logging.warning(f"RAPTOR: Chunk missing vector field '{vctr_nm}' in doc {doc_id}, skipping")+ continuechunks.append((d["content_with_weight"], np.array(d[vctr_nm])))++ if skipped_chunks > 0:+ callback(msg=f"[WARN] Skipped {skipped_chunks} chunks without vector field '{vctr_nm}' for doc {doc_id}. Consider re-parsing the document with the current embedding model.")++ if not chunks:+ logging.warning(f"RAPTOR: No valid chunks with vectors found for doc {doc_id}")+ callback(msg=f"[WARN] No valid chunks with vectors found for doc {doc_id}, skipping")+ continue+await generate(chunks, doc_id)callback(prog=(x + 1.) / len(doc_ids))else:chunks = []+ skipped_chunks = 0for doc_id in doc_ids:for d in settings.retriever.chunk_list(doc_id, row["tenant_id"], [str(row["kb_id"])],fields=["content_with_weight", vctr_nm],sort_by_position=True):+ # Skip chunks that don't have the required vector field+ if vctr_nm not in d or d[vctr_nm] is None:+ skipped_chunks += 1+ logging.warning(f"RAPTOR: Chunk missing vector field '{vctr_nm}' in doc {doc_id}, skipping")+ continuechunks.append((d["content_with_weight"], np.array(d[vctr_nm])))+ if skipped_chunks > 0:+ callback(msg=f"[WARN] Skipped {skipped_chunks} chunks without vector field '{vctr_nm}'. Consider re-parsing documents with the current embedding model.")++ if not chunks:+ logging.error(f"RAPTOR: No valid chunks with vectors found in any document for kb {row['kb_id']}")+ callback(msg=f"[ERROR] No valid chunks with vectors found. Please ensure documents are parsed with the current embedding model (vector size: {vector_size}).")+ return res, tk_count+await generate(chunks, fake_doc_id)return res, tk_count