MCPcopy Create free account
hub / github.com/53AI/53AIHub / SplitRetrievalChunk

Function SplitRetrievalChunk

api/controller/retrieval_chunk.go:563–637  ·  view source on GitHub ↗

SplitRetrievalChunk godoc @Summary 拆分检索块 @Description 将一个检索块拆分为多个检索块 @Tags 检索块管理 @Accept json @Produce json @Security BearerAuth @Param retrieval_id path int true "检索块ID" @Param request body SplitRetrievalChunkRequest true "拆分检索块请求" @Success 200 {object} model.CommonResponse{data=[]model.RetrievalCh

(c *gin.Context)

Source from the content-addressed store, hash-verified

561// @Failure 500 {object} model.CommonResponse "服务器内部错误"
562// @Router /api/chunks/retrieval/{retrieval_id}/split [post]
563func SplitRetrievalChunk(c *gin.Context) {
564 eid := config.GetEID(c)
565 userID := config.GetUserId(c)
566
567 // 解析路径参数
568 retrievalChunkIDStr := c.Param("retrieval_id")
569 retrievalChunkID, err := strconv.ParseInt(retrievalChunkIDStr, 10, 64)
570 if err != nil {
571 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse("无效的检索块ID"))
572 return
573 }
574
575 // 解析请求体
576 var req SplitRetrievalChunkRequest
577 if err := c.ShouldBindJSON(&req); err != nil {
578 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err))
579 return
580 }
581
582 // 获取检索块信息以检查文档锁定状态
583 retrievalChunk, err := model.GetRetrievalChunkByID(eid, retrievalChunkID)
584 if err != nil {
585 c.JSON(http.StatusNotFound, model.NotFound.ToResponse("检索块不存在"))
586 return
587 }
588
589 // 检查文档是否被锁定
590 chunkerService := rag.NewChunkerService(model.DB)
591 if chunkerService.IsDocumentLocked(eid, retrievalChunk.FileID) {
592 c.JSON(http.StatusLocked, model.CommonResponse{
593 Code: 423,
594 Message: "文档正在处理中,无法拆分检索块",
595 })
596 return
597 }
598
599 // 检查检索块是否被锁定
600 if chunkerService.IsRetrievalChunkLocked(eid, retrievalChunkID) {
601 c.JSON(http.StatusLocked, model.CommonResponse{
602 Code: 423,
603 Message: "检索块正在被编辑,请稍后再试",
604 })
605 return
606 }
607
608 // 锁定检索块
609 if !chunkerService.TryLockRetrievalChunk(eid, retrievalChunkID, userID) {
610 c.JSON(http.StatusLocked, model.CommonResponse{
611 Code: 423,
612 Message: "无法获取检索块编辑锁,请稍后再试",
613 })
614 return
615 }
616 defer chunkerService.UnlockRetrievalChunk(eid, retrievalChunkID)
617
618 // 创建检索块服务
619 retrievalService := rag.NewRetrievalChunkService(model.DB)
620

Callers

nothing calls this directly

Calls 8

IsDocumentLockedMethod · 0.95
TryLockRetrievalChunkMethod · 0.95
UnlockRetrievalChunkMethod · 0.95
SplitRetrievalChunkMethod · 0.95
isTestModeFunction · 0.85
GetEIDMethod · 0.80
ToResponseMethod · 0.80

Tested by

no test coverage detected