Update chunk/metadata cli (#15055)

### What problem does this PR solve?

Update chunk/metadata cli

### Type of change

- [ ] Refactoring
This commit is contained in:
qinling0210
2026-05-20 20:32:06 +08:00
committed by GitHub
parent 90c76e73d0
commit dbef3e361f
17 changed files with 602 additions and 147 deletions

View File

@@ -249,74 +249,6 @@ func (h *KnowledgebaseHandler) ListTagsFromKbs(c *gin.Context) {
jsonResponse(c, common.CodeSuccess, []string{}, "success")
}
// RemoveTags handles the remove tags request
// @Summary Remove Tags
// @Description Remove tags from a knowledge base
// @Tags knowledgebase
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param kb_id path string true "Knowledge Base ID"
// @Param request body object{tags []string} true "tags to remove"
// @Success 200 {object} map[string]interface{}
// @Router /v1/kb/{kb_id}/rm_tags [post]
func (h *KnowledgebaseHandler) RemoveTags(c *gin.Context) {
user, errorCode, errorMessage := GetUser(c)
if errorCode != common.CodeSuccess {
jsonError(c, errorCode, errorMessage)
return
}
kbID := c.Param("kb_id")
if kbID == "" {
jsonError(c, common.CodeDataError, "kb_id is required")
return
}
if !h.kbService.Accessible(kbID, user.ID) {
jsonError(c, common.CodeAuthenticationError, "No authorization.")
return
}
var req struct {
Tags []string `json:"tags" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
jsonError(c, common.CodeDataError, err.Error())
return
}
// Get KB to find tenant_id and build index name
kb, err := h.kbService.GetByID(kbID)
if err != nil {
jsonError(c, common.CodeDataError, "knowledge base not found")
return
}
// Build index name prefix: ragflow_<tenant_id>
indexName := "ragflow_" + kb.TenantID
// For each tag, call UpdateChunk to remove it from documents
for _, tag := range req.Tags {
condition := map[string]interface{}{
"tag_kwd": tag,
"kb_id": kbID,
}
newValue := map[string]interface{}{
"remove": map[string]interface{}{
"tag_kwd": tag,
},
}
err := h.kbService.RemoveTag(condition, newValue, indexName, kbID)
if err != nil {
jsonError(c, common.CodeServerError, "Failed to remove tag: "+err.Error())
return
}
}
jsonResponse(c, common.CodeSuccess, true, "success")
}
// RenameTag handles the rename tag request
// @Summary Rename Tag
// @Description Rename a tag in a knowledge base