mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-03 16:57:48 +08:00
Implement Create/Drop Index/Metadata index in GO (#13791)
### What problem does this PR solve? Implement Create/Drop Index/Metadata index in GO New API handling in GO: POST/kb/index DELETE /kb/index POST /tenant/doc_meta_index DELETE /tenant/doc_meta_index CREATE INDEX FOR DATASET 'dataset_name' VECTOR_SIZE 1024; DROP INDEX FOR DATASET 'dataset_name'; CREATE INDEX DOC_META; DROP INDEX DOC_META; ### Type of change - [x] Refactoring
This commit is contained in:
@ -622,3 +622,84 @@ func (h *KnowledgebaseHandler) GetBasicInfo(c *gin.Context) {
|
||||
|
||||
jsonResponse(c, common.CodeSuccess, map[string]interface{}{}, "success")
|
||||
}
|
||||
|
||||
// CreateIndex handles the create index request for a knowledge base
|
||||
// @Summary Create Index
|
||||
// @Description Create the Infinity index/table for a knowledge base
|
||||
// @Tags knowledgebase
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param request body service.CreateIndexRequest true "create index request"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /v1/kb/index [post]
|
||||
func (h *KnowledgebaseHandler) CreateIndex(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
jsonError(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
var req service.CreateIndexRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
jsonError(c, common.CodeDataError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Check authorization
|
||||
if !h.kbService.Accessible(req.KBID, user.ID) {
|
||||
jsonError(c, common.CodeAuthenticationError, "No authorization.")
|
||||
return
|
||||
}
|
||||
|
||||
result, code, err := h.kbService.CreateIndex(&req)
|
||||
if err != nil {
|
||||
jsonError(c, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(c, common.CodeSuccess, result, "success")
|
||||
}
|
||||
|
||||
// DeleteIndexRequest represents the request for deleting an index
|
||||
type DeleteIndexRequest struct {
|
||||
KBID string `json:"kb_id" binding:"required"`
|
||||
}
|
||||
|
||||
// DeleteIndex handles the delete index request for a knowledge base
|
||||
// @Summary Delete Index
|
||||
// @Description Delete the Infinity index/table for a knowledge base
|
||||
// @Tags knowledgebase
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param request body DeleteIndexRequest true "delete index request"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /v1/kb/index [delete]
|
||||
func (h *KnowledgebaseHandler) DeleteIndex(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
jsonError(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
var req DeleteIndexRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
jsonError(c, common.CodeDataError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Check authorization
|
||||
if !h.kbService.Accessible(req.KBID, user.ID) {
|
||||
jsonError(c, common.CodeAuthenticationError, "No authorization.")
|
||||
return
|
||||
}
|
||||
|
||||
code, err := h.kbService.DeleteIndex(req.KBID)
|
||||
if err != nil {
|
||||
jsonError(c, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(c, common.CodeSuccess, nil, "success")
|
||||
}
|
||||
|
||||
@ -113,3 +113,67 @@ func (h *TenantHandler) TenantList(c *gin.Context) {
|
||||
"data": tenantList,
|
||||
})
|
||||
}
|
||||
|
||||
// CreateDocMetaIndex handles the create doc meta index request
|
||||
// @Summary Create Doc Meta Index
|
||||
// @Description Create the document metadata index for a tenant
|
||||
// @Tags tenants
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /v1/tenant/doc_meta_index [post]
|
||||
func (h *TenantHandler) CreateDocMetaIndex(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
jsonError(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
// Use user.ID as tenant ID (user IS the tenant in user mode)
|
||||
tenantID := user.ID
|
||||
|
||||
code, err := h.tenantService.CreateDocMetaIndex(tenantID)
|
||||
if err != nil {
|
||||
jsonError(c, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeSuccess,
|
||||
"message": "success",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteDocMetaIndex handles the delete doc meta index request
|
||||
// @Summary Delete Doc Meta Index
|
||||
// @Description Delete the document metadata index for a tenant
|
||||
// @Tags tenants
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /v1/tenant/doc_meta_index [delete]
|
||||
func (h *TenantHandler) DeleteDocMetaIndex(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
jsonError(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
// Use user.ID as tenant ID (user IS the tenant in user mode)
|
||||
tenantID := user.ID
|
||||
|
||||
code, err := h.tenantService.DeleteDocMetaIndex(tenantID)
|
||||
if err != nil {
|
||||
jsonError(c, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeSuccess,
|
||||
"message": "success",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user