feat: Remove RebuildKnowledgeBaseIndex and associated handler from knowledge service
- Deleted the RebuildKnowledgeBaseIndex function from the knowledge service, which was responsible for reprocessing all documents in a knowledge base. - Removed the RebuildIndex handler from the KnowledgeBaseHandler, eliminating the endpoint that triggered the rebuild process. - Updated the router to remove the route for rebuilding the index, streamlining the knowledge base management functionality.
This commit is contained in:
@@ -3057,34 +3057,6 @@ func (s *knowledgeService) enqueueManualProcessing(ctx context.Context,
|
||||
return nil
|
||||
}
|
||||
|
||||
// RebuildKnowledgeBaseIndex re-processes all documents in a knowledge base by enqueuing
|
||||
// reparse tasks. Used when the indexing strategy changes (e.g., enabling wiki on an
|
||||
// existing KB with documents) and all documents need to be re-indexed.
|
||||
func (s *knowledgeService) RebuildKnowledgeBaseIndex(ctx context.Context, kbID string) (int, error) {
|
||||
logger.Infof(ctx, "Start rebuilding index for knowledge base: %s", kbID)
|
||||
|
||||
knowledgeList, err := s.ListKnowledgeByKnowledgeBaseID(ctx, kbID)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("list knowledge for KB %s: %w", kbID, err)
|
||||
}
|
||||
|
||||
count := 0
|
||||
for _, k := range knowledgeList {
|
||||
// Skip knowledge that is being deleted or has failed status
|
||||
if k.ParseStatus == types.ParseStatusDeleting {
|
||||
continue
|
||||
}
|
||||
if _, err := s.ReparseKnowledge(ctx, k.ID); err != nil {
|
||||
logger.Warnf(ctx, "Failed to enqueue reparse for knowledge %s: %v", k.ID, err)
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Rebuild index: enqueued %d/%d documents for KB %s", count, len(knowledgeList), kbID)
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// ReparseKnowledge deletes existing document content and re-parses the knowledge asynchronously.
|
||||
// This method reuses the logic from UpdateManualKnowledge for resource cleanup and async parsing.
|
||||
func (s *knowledgeService) ReparseKnowledge(ctx context.Context, knowledgeID string) (*types.Knowledge, error) {
|
||||
|
||||
@@ -487,51 +487,6 @@ func (h *KnowledgeBaseHandler) UpdateKnowledgeBase(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// RebuildIndex godoc
|
||||
// @Summary 重建索引
|
||||
// @Description 当索引策略变更后,对知识库中已有文档重新处理(重新分块、向量化、Wiki生成等)
|
||||
// @Tags 知识库
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "知识库ID"
|
||||
// @Success 200 {object} map[string]interface{} "重建结果"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Security Bearer
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /knowledge-bases/{id}/rebuild-index [post]
|
||||
func (h *KnowledgeBaseHandler) RebuildIndex(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
logger.Info(ctx, "Start rebuilding knowledge base index")
|
||||
|
||||
// Validate and get the knowledge base
|
||||
_, id, _, permission, err := h.validateAndGetKnowledgeBase(c)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Only admin/editor can rebuild index
|
||||
if permission != types.OrgRoleAdmin && permission != types.OrgRoleEditor {
|
||||
c.Error(apperrors.NewForbiddenError("No permission to rebuild index"))
|
||||
return
|
||||
}
|
||||
|
||||
count, err := h.knowledgeService.RebuildKnowledgeBaseIndex(ctx, id)
|
||||
if err != nil {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(apperrors.NewInternalServerError(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Rebuild index enqueued for KB %s: %d documents", id, count)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": gin.H{
|
||||
"document_count": count,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteKnowledgeBase godoc
|
||||
// @Summary 删除知识库
|
||||
// @Description 删除指定的知识库及其所有内容
|
||||
@@ -885,4 +840,4 @@ func (h *KnowledgeBaseHandler) ListMoveTargets(c *gin.Context) {
|
||||
"success": true,
|
||||
"data": targets,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,8 +278,6 @@ func RegisterKnowledgeBaseRoutes(r *gin.RouterGroup, handler *handler.KnowledgeB
|
||||
kb.GET("/copy/progress/:task_id", handler.GetKBCloneProgress)
|
||||
// 获取可移动目标知识库列表
|
||||
kb.GET("/:id/move-targets", handler.ListMoveTargets)
|
||||
// 重建索引(当索引策略变更后,对已有文档重新处理)
|
||||
kb.POST("/:id/rebuild-index", handler.RebuildIndex)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user