{"record":{"id":"2b4443a7a136bf32","repo":"iflytek/astron-agent","slug":"chunkdeletefailed","errorCode":"ChunkDeleteFailed","errorMessage":"Deletion failed: {error_msg}","messagePattern":"Deletion failed: (.+?)","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/knowledge/service/impl/ragflow_strategy.py","lineNumber":1059,"sourceCode":"\n            logger.info(f\"Using dataset: {dataset_id}\")\n\n            # 2. Call RAGFlow deletion API directly\n            delete_response = await ragflow_client.delete_chunks(\n                dataset_id=dataset_id, document_id=docId, chunk_ids=chunkIds\n            )\n\n            logger.info(f\"RAGFlow chunk deletion response: {delete_response}\")\n\n            # 3. Process response\n            if delete_response.get(\"code\") == 0:\n                logger.info(f\"Successfully deleted {len(chunkIds)} chunks\")\n                return None  # Success, let API layer handle the response\n            else:\n                # RAGFlow deletion failed\n                error_msg = delete_response.get(\"message\", \"Deletion failed\")\n                logger.error(f\"RAGFlow deletion failed: {error_msg}\")\n                raise CustomException(\n                    CodeEnum.ChunkDeleteFailed, f\"Deletion failed: {error_msg}\"\n                )\n\n        except CustomException:\n            raise  # Re-raise custom exceptions\n        except Exception as e:\n            logger.error(f\"Chunk deletion operation failed: {e}\")\n            raise CustomException(\n                CodeEnum.ChunkDeleteFailed, f\"Deletion operation failed: {str(e)}\"\n            )\n\n    async def query_doc(self, docId: str, **kwargs: Any) -> List[Dict[str, Any]]:\n        \"\"\"Query all chunk information for a document using RAGFlow.\"\"\"\n        try:\n            logger.info(f\"Starting document chunk query: docId={docId}\")\n\n            dataset_id = await self._resolve_dataset_id(kwargs.get(_DATASET_ID_KWARG))\n            if not dataset_id:","sourceCodeStart":1041,"sourceCodeEnd":1077,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/service/impl/ragflow_strategy.py#L1041-L1077","documentation":"chunks_delete reached RAGFlow successfully but RAGFlow returned a non-success response for the delete operation. The strategy extracts response['message'] (default 'Deletion failed') and raises CustomException with ChunkDeleteFailed prefixed by 'Deletion failed:'. This is an application-level failure reported by the RAGFlow API, not a transport exception.","triggerScenarios":"RAGFlow delete-chunk API returns code != 0 — e.g. chunk already deleted, chunk ID not found in the dataset/document, wrong dataset_id/docId pairing, or RAGFlow-side permission/validation rejection.","commonSituations":"Stale chunk IDs in the UI after someone else deleted the chunk; document recreated so chunk IDs no longer match; RAGFlow dataset permissions changed.","solutions":["Inspect the message after 'Deletion failed:' — it is RAGFlow's own error text and usually names the offending chunk or reason.","Verify docId and chunkIds still exist via query_doc before deleting; refresh stale IDs.","Confirm the dataset_id used to build the RAGFlow request matches the document's actual dataset.","Treat 'not found' style messages as idempotent success if your workflow allows concurrent deletes."],"exampleFix":"// before\nawait strategy.chunks_delete(docId, chunk_ids)\n// after\ntry:\n    await strategy.chunks_delete(docId, chunk_ids)\nexcept CustomException as e:\n    if \"not found\" in str(e).lower():\n        logger.warning(\"Chunks already gone, treating as success\")\n    else:\n        raise","handlingStrategy":"try-catch","validationCode":"existing = await strategy.query_doc(docId)\nexisting_ids = {c[\"id\"] for c in existing}\ndeletable = [cid for cid in chunk_ids if cid in existing_ids]","typeGuard":"null","tryCatchPattern":"try:\n    await strategy.chunks_delete(docId, chunk_ids)\nexcept CustomException as e:\n    if e.code == CodeEnum.ChunkDeleteFailed and \"not found\" in str(e).lower():\n        logger.warning(\"Chunks already deleted: %s\", e)\n    else:\n        raise","preventionTips":["Refresh chunk IDs via query_doc before deleting; never cache chunk IDs across sessions.","Treat not-found deletes as idempotent success in concurrent workflows.","Verify dataset_id/docId pairing matches RAGFlow's actual layout."],"tags":["ragflow","delete","api-error","chunks"],"backgroundTag":"api-error-response","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}