Skip to content

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

refa: remove Go artifact deletion APIs (#19519)

buua4366051b2150ff2
diff --git a/internal/handler/dataset_artifact.go b/internal/handler/dataset_artifact.go
index 1e615cbf39..10c36de214 100644
--- a/internal/handler/dataset_artifact.go
+++ b/internal/handler/dataset_artifact.go
@@ -220,20 +220,6 @@ func (h *DatasetArtifactHandler) GetArtifact(c *gin.Context) {
common.SuccessWithData(c, detail, "success")
}
-// DeleteArtifacts handles DELETE /artifacts — clear all wiki artifacts.
-func (h *DatasetArtifactHandler) DeleteArtifacts(c *gin.Context) {
- _, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
- if tenantID == "" {
- return
- }
- deleted, err := h.svc.ClearWiki(c.Request.Context(), tenantID, c.Param("dataset_id"))
- if err != nil {
- common.ErrorWithCode(c, common.CodeDataError, err.Error())
- return
- }
- common.SuccessWithData(c, deleted, "success")
-}
-
// ListArtifactTopics handles GET /artifacts/topics — list wiki topics.
func (h *DatasetArtifactHandler) ListArtifactTopics(c *gin.Context) {
_, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
@@ -316,34 +302,6 @@ func (h *DatasetArtifactHandler) ListStructures(c *gin.Context) {
common.SuccessWithData(c, resp, "success")
}
-// DeleteStructures handles DELETE /artifacts/structure?kind=<kind>&wipe=<bool> —
-// cancel the kind's task (wipe=false) or delete its dataset rows (wipe=true).
-// kind is REQUIRED.
-func (h *DatasetArtifactHandler) DeleteStructures(c *gin.Context) {
- _, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
- if tenantID == "" {
- return
- }
- datasetID := c.Param("dataset_id")
- kind := c.Query("kind")
- if kind == "" {
- common.ErrorWithCode(c, common.CodeArgumentError, "kind is required")
- return
- }
- wipe := c.Query("wipe") == "true"
- in := service.DatasetStructureGraphInput{TenantID: tenantID, DatasetID: datasetID, Kind: kind, Wipe: wipe}
- n, err := h.svc.DeleteDatasetStructure(c.Request.Context(), in)
- if err != nil {
- if errors.Is(err, service.ErrInvalidStructureKind) {
- common.ErrorWithCode(c, common.CodeArgumentError, err.Error())
- } else {
- common.ErrorWithCode(c, common.CodeServerError, err.Error())
- }
- return
- }
- common.SuccessWithData(c, gin.H{"deleted": n}, "success")
-}
-
// AnySkill handles HEAD /skills — any skill artifact present?
func (h *DatasetArtifactHandler) AnySkill(c *gin.Context) {
_, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
@@ -378,34 +336,6 @@ func (h *DatasetArtifactHandler) ListNavigation(c *gin.Context) {
common.SuccessWithData(c, gin.H{"total": total, "items": items}, "success")
}
-// DeleteNavigation handles DELETE /navigation — delete all navigation clusters.
-func (h *DatasetArtifactHandler) DeleteNavigation(c *gin.Context) {
- _, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
- if tenantID == "" {
- return
- }
- n, err := h.svc.DeleteNav(c.Request.Context(), tenantID, c.Param("dataset_id"))
- if err != nil {
- common.ErrorWithCode(c, common.CodeDataError, err.Error())
- return
- }
- common.SuccessWithData(c, gin.H{"deleted": n}, "success")
-}
-
-// DeleteNavigationNode handles DELETE /navigation/<name> — delete a single navigation cluster.
-func (h *DatasetArtifactHandler) DeleteNavigationNode(c *gin.Context) {
- _, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
- if tenantID == "" {
- return
- }
- n, err := h.svc.DeleteNavNode(c.Request.Context(), tenantID, c.Param("dataset_id"), c.Param("name"))
- if err != nil {
- common.ErrorWithCode(c, common.CodeDataError, err.Error())
- return
- }
- common.SuccessWithData(c, gin.H{"deleted": n}, "success")
-}
-
// ListNavigationChildren handles GET /navigation/<name>/children — list children of a navigation cluster.
func (h *DatasetArtifactHandler) ListNavigationChildren(c *gin.Context) {
_, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
@@ -506,19 +436,3 @@ func (h *DatasetArtifactHandler) GetDocumentGraph(c *gin.Context) {
}
common.SuccessWithData(c, resp, "success")
}
-
-// DeleteDocumentGraph handles DELETE /documents/<document_id>/structure/graph — delete document structure graph.
-func (h *DatasetArtifactHandler) DeleteDocumentGraph(c *gin.Context) {
- _, tenantID, _ := h.datasetOwner(c, c.Param("dataset_id"))
- if tenantID == "" {
- return
- }
- datasetID := c.Param("dataset_id")
- documentID := c.Param("document_id")
- n, err := h.svc.DeleteDocumentGraph(c.Request.Context(), tenantID, datasetID, documentID)
- if err != nil {
- common.ErrorWithCode(c, common.CodeDataError, err.Error())
- return
- }
- common.SuccessWithData(c, gin.H{"deleted": n}, "success")
-}
diff --git a/internal/router/router.go b/internal/router/router.go
index 736b71abe9..3a7824f228 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -362,19 +362,15 @@ func (r *Router) Setup(engine *gin.Engine) {
// Knowledge-compilation wiki artifacts
datasets.HEAD("/:dataset_id/artifacts", r.datasetArtifactHandler.AnyArtifact)
datasets.GET("/:dataset_id/artifacts", r.datasetArtifactHandler.ListArtifacts)
- datasets.DELETE("/:dataset_id/artifacts", r.datasetArtifactHandler.DeleteArtifacts)
datasets.GET("/:dataset_id/artifacts/topics", r.datasetArtifactHandler.ListArtifactTopics)
datasets.GET("/:dataset_id/artifacts/alteration", r.datasetArtifactHandler.GetArtifactAlteration)
datasets.GET("/:dataset_id/artifacts/graph", r.datasetArtifactHandler.GetArtifactGraph)
datasets.GET("/:dataset_id/artifacts/:page_type/*slug", r.datasetArtifactHandler.GetArtifact)
datasets.PUT("/:dataset_id/artifacts/:page_type/*slug", r.datasetArtifactHandler.UpdateArtifact)
datasets.GET("/:dataset_id/artifacts/structure", r.datasetArtifactHandler.ListStructures)
- datasets.DELETE("/:dataset_id/artifacts/structure", r.datasetArtifactHandler.DeleteStructures)
// Knowledge-compilation navigation
datasets.GET("/:dataset_id/navigation", r.datasetArtifactHandler.ListNavigation)
- datasets.DELETE("/:dataset_id/navigation", r.datasetArtifactHandler.DeleteNavigation)
- datasets.DELETE("/:dataset_id/navigation/:name", r.datasetArtifactHandler.DeleteNavigationNode)
datasets.GET("/:dataset_id/navigation/:name/children", r.datasetArtifactHandler.ListNavigationChildren)
// Knowledge-compilation skills
@@ -424,7 +420,6 @@ func (r *Router) Setup(engine *gin.Engine) {
datasets.DELETE("/:dataset_id/documents/:document_id/chunks", r.chunkHandler.RemoveChunks)
datasets.PUT("/:dataset_id/documents/:document_id/metadata/config", r.datasetsHandler.UpdateDocumentMetadataConfig)
datasets.GET("/:dataset_id/documents/:document_id/structure/graph", r.datasetArtifactHandler.GetDocumentGraph)
- datasets.DELETE("/:dataset_id/documents/:document_id/structure/graph", r.datasetArtifactHandler.DeleteDocumentGraph)
datasets.POST("/:dataset_id/metadata/update", r.documentHandler.MetadataBatchUpdate)
datasets.PATCH("/:dataset_id/documents/metadatas", r.documentHandler.UpdateDocumentMetadatas)
}
diff --git a/internal/service/dataset_artifact_nav_test.go b/internal/service/dataset_artifact_nav_test.go
deleted file mode 100644
index 2b7e90229b..0000000000
--- a/internal/service/dataset_artifact_nav_test.go
+++ /dev/null
@@ -1,95 +0,0 @@
-package service
-
-import (
- "context"
- "testing"
-
- "ragflow/internal/service/nav"
-)
-
-// fakeArtifactNav is an in-memory nav.NavService used to lock the limited
-// DeleteNav/DeleteNavNode semantics (direct doc children only; no sub-cluster
-// or cascade deletion).
-type fakeArtifactNav struct {
- clusters []nav.NavNode
- children map[string][]nav.NavNode
- removedDocs []string
-}
-
-func (f *fakeArtifactNav) UpsertDoc(context.Context, nav.UpsertDocInput) error { return nil }
-func (f *fakeArtifactNav) RemoveDoc(_ context.Context, _, _, docID string) error {
- f.removedDocs = append(f.removedDocs, docID)
- return nil
-}
-func (f *fakeArtifactNav) Search(context.Context, string, string, string, []float32, []string, int) ([]nav.NavHit, error) {
- return nil, nil
-}
-func (f *fakeArtifactNav) ListClusters(context.Context, string, string, int, int) ([]nav.NavNode, int64, error) {
- return f.clusters, int64(len(f.clusters)), nil
-}
-func (f *fakeArtifactNav) ListChildren(_ context.Context, _, _, name string, _, _ int) ([]nav.NavNode, int64, error) {
- return f.children[name], int64(len(f.children[name])), nil
-}
-func (f *fakeArtifactNav) SummariesByDocIDs(context.Context, string, string, []string) map[string]string {
- return nil
-}
-
-// TestDeleteNav_RemovesOnlyDirectDocChildren documents the limited semantic of
-// the deprecated DeleteNav: it removes the nav_doc rows directly under root
-// clusters, and does NOT touch sub-clusters (Python's full cascade is not
-// implemented in the minimal loop).
-func TestDeleteNav_RemovesOnlyDirectDocChildren(t *testing.T) {
- fake := &fakeArtifactNav{
- clusters: []nav.NavNode{{Name: "C1", Description: "root"}},
- children: map[string][]nav.NavNode{
- "C1": {{Name: "Sub", Type: "cluster"}, {Name: "DocA", Type: "doc", DocID: "d1"}},
- "Sub": {{Name: "DocB", Type: "doc", DocID: "d2"}},
- },
- }
- prev := nav.GetNavService()
- nav.SetNavService(fake)
- defer func() { nav.SetNavService(prev) }()
-
- svc := NewDatasetArtifactService()
- n, err := svc.DeleteNav(t.Context(), "t1", "kb1")
- if err != nil {
- t.Fatalf("DeleteNav: %v", err)
- }
- // Only the direct doc child (d1) under the root cluster is removed; the
- // sub-cluster's doc (d2) is NOT reached (no subtree traversal).
- if n != 1 {
- t.Errorf("deleted = %d, want 1 (direct doc child only)", n)
- }
- if len(fake.removedDocs) != 1 || fake.removedDocs[0] != "d1" {
- t.Errorf("removed docs = %v, want [d1] only (no cascade into Sub)", fake.removedDocs)
- }
-}
-
-// TestDeleteNavNode_RemovesDirectChildren documents that DeleteNavNode drains
-// only the immediate doc children of a named cluster.
-func TestDeleteNavNode_RemovesDirectChildren(t *testing.T) {
- fake := &fakeArtifactNav{
- children: map[string][]nav.NavNode{
- "C1": {
- {Name: "Sub2", Type: "cluster"},
- {Name: "DocA", Type: "doc", DocID: "d1"},
- {Name: "DocB", Type: "doc", DocID: "d2"},
- },
- },
- }
- prev := nav.GetNavService()
- nav.SetNavService(fake)
- defer func() { nav.SetNavService(prev) }()
-
- svc := NewDatasetArtifactService()
- n, err := svc.DeleteNavNode(t.Context(), "t1", "kb1", "C1")
- if err != nil {
- t.Fatalf("DeleteNavNode: %v", err)
- }
- if n != 2 {
- t.Errorf("deleted = %d, want 2 (direct doc children d1,d2)", n)
- }
- if len(fake.removedDocs) != 2 {
- t.Errorf("removed docs = %v, want [d1 d2]", fake.removedDocs)
- }
-}
diff --git a/internal/service/dataset_artifact_service.go b/internal/service/dataset_artifact_service.go
index 0498386d2c..2814b6a4c3 100644
--- a/internal/service/dataset_artifact_service.go
+++ b/internal/service/dataset_artifact_service.go
@@ -837,69 +837,6 @@ func sortedSetKeys(set map[string]struct{}) []string {
return ids
}
-// ClearWiki deletes all wiki artifacts for a dataset.
-func (s *DatasetArtifactService) ClearWiki(ctx context.Context, tenantID, datasetID string) (map[string]int, error) {
- docEngine := engine.Get()
- if docEngine == nil {
- return nil, fmt.Errorf("document engine is not initialized")
- }
- kwds := []string{CompileKwdWikiPage, CompileKwdWikiEntity, CompileKwdWikiRelation, CompileKwdWikiAlter}
- deleted := map[string]int{}
- for _, kwd := range kwds {
- chunks, _, err := s.searchCompiled(ctx, tenantID, datasetID,
- map[string]interface{}{"compile_kwd": []string{kwd}}, []string{"id"}, 0, 10000, nil)
- if err != nil {
- return nil, err
- }
- if len(chunks) == 0 {
- deleted[kwd] = 0
- continue
- }
- ids := make([]string, 0, len(chunks))
- for _, c := range chunks {
- if id, ok := c["id"].(string); ok {
- ids = append(ids, id)
- }
- }
- cond := map[string]interface{}{"id": ids, "kb_id": datasetID}
- if _, err := docEngine.DeleteChunks(ctx, cond, wikiIndexName(tenantID), datasetID); err != nil {
- return nil, err
- }
- deleted[kwd] = len(ids)
- }
- return deleted, nil
-}
-
-// DeleteDocumentGraph deletes the structure graph of a single document.
-func (s *DatasetArtifactService) DeleteDocumentGraph(ctx context.Context, tenantID, datasetID, documentID string) (int, error) {
- docEngine := engine.Get()
- if docEngine == nil {
- return 0, fmt.Errorf("document engine is not initialized")
- }
- filter := map[string]interface{}{
- "doc_id": []string{documentID},
- "compiled_graph_kwd": []string{"graph"},
- }
- chunks, _, err := s.searchCompiled(ctx, tenantID, datasetID, filter, []string{"id"}, 0, 10000, nil)
- if err != nil {
- return 0, err
- }
- if len(chunks) == 0 {
- return 0, nil
- }
- ids := make([]string, 0, len(chunks))
- for _, c := range chunks {
- if id, ok := c["id"].(string); ok {
- ids = append(ids, id)
- }
- }
- cond := map[string]interface{}{"id": ids, "kb_id": datasetID}
- if _, err := docEngine.DeleteChunks(ctx, cond, wikiIndexName(tenantID), datasetID); err != nil {
- return 0, err
- }
- return len(ids), nil
-}
-
// ListNavClusters returns the navigation clusters of a dataset. It delegates to
// the ES-backed NavService and returns the frontend DatasetNavNode shape
// (snake_case NavNode JSON), matching Python GET /navigation exactly. The old
@@ -931,65 +868,6 @@ func (s *DatasetArtifactService) ListNavChildren(ctx context.Context, tenantID,
return nodes, total, nil
}
-// DeleteNav removes the direct nav_doc children of every root cluster of a
-// dataset. DEPRECATED — this is the minimal-loop approximation of Python
-// delete_nav: it drains only the immediate nav_doc rows under root clusters and
-// does NOT implement Python's full subtree traversal or empty-cluster cascade
-// cleanup. Prefer the NavService (future work) for a complete delete. Returns
-// the number of nav_doc rows removed.
-func (s *DatasetArtifactService) DeleteNav(ctx context.Context, tenantID, datasetID string) (int, error) {
- ns := nav.GetNavService()
- if ns == nil {
- return 0, fmt.Errorf("datasetnav: NavService not initialized (SetNavService must be called at bootstrap)")
- }
- clusters, _, err := ns.ListClusters(ctx, tenantID, datasetID, 0, 10000)
- if err != nil {
- return 0, err
- }
- deleted := 0
- for _, c := range clusters {
- children, _, err := ns.ListChildren(ctx, tenantID, datasetID, c.Name, 0, 10000)
- if err != nil {
- continue
- }
- for _, ch := range children {
- if ch.DocID != "" {
- if err := ns.RemoveDoc(ctx, tenantID, datasetID, ch.DocID); err != nil {
- return deleted, err
- }
- deleted++
- }
- }
- }
- return deleted, nil
-}
-
-// DeleteNavNode deletes the direct nav_doc children of a named cluster.
-// DEPRECATED — the minimal loop only drains immediate doc children (returns the
-// count); it does NOT delete sub-clusters recursively nor perform Python's
-// empty-cluster cascade. A full tree-node delete is future NavService work.
-func (s *DatasetArtifactService) DeleteNavNode(ctx context.Context, tenantID, datasetID, name string) (int, error) {
- ns := nav.GetNavService()
- if ns == nil {
- return 0, fmt.Errorf("datasetnav: NavService not initialized (SetNavService must be called at bootstrap)")
- }
- // Minimal loop has no per-node delete; drain direct children's docs.
- children, _, err := ns.ListChildren(ctx, tenantID, datasetID, name, 0, 10000)
- if err != nil {
- return 0, err
- }
- deleted := 0
- for _, ch := range children {
- if ch.DocID != "" {
- if err := ns.RemoveDoc(ctx, tenantID, datasetID, ch.DocID); err != nil {
- return deleted, err
- }
- deleted++
- }
- }
- return deleted, nil
-}
-
// SkillTreeItem is a single skill-tree page summary.
type SkillTreeItem struct {
Kwd string `json:"kwd"`
diff --git a/internal/service/dataset_structure_graph.go b/internal/service/dataset_structure_graph.go
index 633969b1f9..96a20d6c96 100644
--- a/internal/service/dataset_structure_graph.go
+++ b/internal/service/dataset_structure_graph.go
@@ -16,7 +16,6 @@ import (
"sort"
"strings"
- "gorm.io/gorm"
"ragflow/internal/dao"
"ragflow/internal/engine"
"ragflow/internal/engine/types"
@@ -882,17 +881,15 @@ func containsStr(list []string, v string) bool {
}
// DatasetStructureGraphInput is the parsed request for the dataset-scope
-// structure graph endpoint (GET/DELETE /datasets/:id/artifacts/structure).
+// structure graph endpoint (GET /datasets/:id/artifacts/structure).
// Kind is REQUIRED (mirrors Python dataset_api.py:715): missing or invalid →
-// 400 ARGUMENT_ERROR. Wipe applies to DELETE: true deletes the dataset rows,
-// false only cancels the task (rows are left for the next rebuild to clean).
+// 400 ARGUMENT_ERROR.
type DatasetStructureGraphInput struct {
TenantID string
DatasetID string
Kind string
// Keywords selects the matching entity subgraph when non-empty.
Keywords string
- Wipe bool
}
// DatasetStructureGraphResponse mirrors Python get_dataset_structure's
@@ -1053,96 +1050,6 @@ func (s *DatasetArtifactService) GetDatasetStructure(ctx context.Context, in Dat
return resp, nil
}
-// DeleteDatasetStructure handles DELETE /datasets/:id/artifacts/structure?kind=&wipe=.
-// It validates kind like GET. wipe=false cancels the kind's task (via the task-id
-// field) without deleting rows; wipe=true deletes the kind's kg_build_meta marker
-// + dataset entity/relation rows (document-scope rows are never touched).
-func (s *DatasetArtifactService) DeleteDatasetStructure(ctx context.Context, in DatasetStructureGraphInput) (int, error) {
- resolved := resolveDatasetStructureKind(in.Kind)
- if resolved == "" {
- return 0, fmt.Errorf("%w: %q", ErrInvalidStructureKind, in.Kind)
- }
- if !in.Wipe {
- // Cancel the task without deleting rows. Task cancellation is task-id
- // granular (mirrors Python delete_index REDIS set "{task_id}-cancel"); the
- // actual row cleanup happens on the next rebuild. Rows are preserved.
- return s.cancelDatasetStructureTask(ctx, in.TenantID, in.DatasetID, resolved)
- }
- if !datasetStructureSupported() {
- return 0, errDatasetStructureUnsupported()
- }
- docEngine := engine.Get()
- if docEngine == nil {
- return 0, fmt.Errorf("document engine is not initialized")
- }
- indexName := fmt.Sprintf("ragflow_%s", in.TenantID)
- cond := map[string]interface{}{
- "kb_id": in.DatasetID,
- "scope_kwd": "dataset",
- "compilation_template_kind_kwd": resolved,
- "knowledge_graph_kwd": []string{"entity", "relation", "kg_build_meta"},
- }
- n, err := docEngine.DeleteChunks(ctx, cond, indexName, in.DatasetID)
- if err != nil {
- return 0, err
- }
- return int(n), nil
-}
-
-// cancelDatasetStructureTask cancels the running dataset-structure task for a
-// resolved kind by clearing both its per-index task-id and finish-at fields.
-// This mirrors Python delete_index (dataset_api_service.py), which clears
-// {task_id_field: "", task_finish_at_field: None} so the task state is fully
-// reset (a stale finish-at would otherwise leave the kind looking "done" after
-// cancel). The row cleanup itself is driven by the next rebuild; Go executes the
-// merge synchronously inside the ingestor (no independent task/marker), so there
-// is no Redis "{task_id}-cancel" marker to publish here.
-func (s *DatasetArtifactService) cancelDatasetStructureTask(ctx context.Context, tenantID, datasetID, resolvedKind string) (int, error) {
- field := datasetStructureTaskIDField(resolvedKind)
- if field == "" {
- return 0, nil
- }
- updates := map[string]interface{}{
- field: "",
- // gorm.Updates ignores nil values, so use an explicit NULL expression to
- // actually clear the finish-at timestamp (mirrors Python None).
- datasetStructureTaskFinishAtField(field): gorm.Expr("NULL"),
- }
- if err := dao.NewKnowledgebaseDAO().UpdateByID(ctx, dao.DB, datasetID, updates); err != nil {
- return 0, err
- }
- return 0, nil
-}
-
-// datasetStructureTaskFinishAtField maps a task-id field to its sibling finish-at
-// field, mirroring Python f"{task_id_field.replace('_task_id', '_task_finish_at')}".
-func datasetStructureTaskFinishAtField(taskIDField string) string {
- return strings.Replace(taskIDField, "_task_id", "_task_finish_at", 1)
-}
-
-// datasetStructureTaskIDField maps a resolved dataset-structure kind to its kb
-// task-id field name. It mirrors Python _INDEX_TYPE_TO_TASK_ID_FIELD: each
-// dataset-merge kind carries its own "<index_type>_task_id" field (structure_graph,
-// structure_mindmap, timeline, session_graph, session_essence), NOT the legacy
-// doc-level graphrag_task_id/mindmap_task_id. Empty means "no task-id field".
-func datasetStructureTaskIDField(resolvedKind string) string {
- switch resolvedKind {
- case "knowledge_graph":
- // "graph" is already normalized to "knowledge_graph" by
- // resolveDatasetStructureKind, so no separate "graph" case is needed.
- return "structure_graph_task_id"
- case "mindmap", "mind_map":
- return "structure_mindmap_task_id"
- case "timeline":
- return "timeline_task_id"
- case "session_graph":
- return "session_graph_task_id"
- case "session_essence":
- return "session_essence_task_id"
- }
- return ""
-}
-
// resolveGraphBucket mirrors Python _resolve_bucket.
func resolveGraphBucket(row map[string]interface{}, templateMeta map[string]map[string]interface{}, documentID string) (map[string]interface{}, map[string]interface{}) {
compileKwd := firstStringValue(row["compile_kwd"])