feat: Add comprehensive documentation for WeKnora knowledge base and wiki features
- Introduced multiple new documentation files, including a complete documentation index, quick reference guides, and comprehensive analyses of the knowledge base and wiki settings. - The new files provide detailed insights into the architecture, data models, API endpoints, and implementation strategies for the knowledge base and wiki functionalities. - Enhanced navigation and usability for developers and team members by summarizing key components, configurations, and data flows related to the knowledge base system. These additions significantly improve the clarity and accessibility of documentation, supporting better onboarding and reference for current and future team members.
This commit is contained in:
@@ -89,7 +89,7 @@ func NewInitializationHandler(
|
||||
// KBModelConfigRequest 知识库模型配置请求(简化版,只传模型ID)
|
||||
type KBModelConfigRequest struct {
|
||||
LLMModelID string `json:"llmModelId" binding:"required"`
|
||||
EmbeddingModelID string `json:"embeddingModelId" binding:"required"`
|
||||
EmbeddingModelID string `json:"embeddingModelId"` // optional when RAG indexing is disabled
|
||||
VLMConfig *types.VLMConfig `json:"vlm_config"`
|
||||
ASRConfig *types.ASRConfig `json:"asr_config"`
|
||||
|
||||
@@ -236,7 +236,7 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查Embedding模型是否可以修改
|
||||
if kb.EmbeddingModelID != "" && kb.EmbeddingModelID != req.EmbeddingModelID {
|
||||
if kb.EmbeddingModelID != "" && req.EmbeddingModelID != "" && kb.EmbeddingModelID != req.EmbeddingModelID {
|
||||
// 检查是否已有文件
|
||||
knowledgeList, err := h.knowledgeService.ListPagedKnowledgeByKnowledgeBaseID(ctx,
|
||||
kbIdStr, &types.Pagination{
|
||||
@@ -258,16 +258,21 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
embeddingModel, err := h.modelService.GetModelByID(ctx, req.EmbeddingModelID)
|
||||
if err != nil || embeddingModel == nil {
|
||||
logger.Error(ctx, "Embedding model not found")
|
||||
c.Error(errors.NewBadRequestError("Embedding模型不存在"))
|
||||
return
|
||||
// Embedding模型仅在需要时验证(RAG检索启用时)
|
||||
if req.EmbeddingModelID != "" {
|
||||
embeddingModel, err := h.modelService.GetModelByID(ctx, req.EmbeddingModelID)
|
||||
if err != nil || embeddingModel == nil {
|
||||
logger.Error(ctx, "Embedding model not found")
|
||||
c.Error(errors.NewBadRequestError("Embedding模型不存在"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 更新知识库的模型ID
|
||||
kb.SummaryModelID = req.LLMModelID
|
||||
kb.EmbeddingModelID = req.EmbeddingModelID
|
||||
if req.EmbeddingModelID != "" {
|
||||
kb.EmbeddingModelID = req.EmbeddingModelID
|
||||
}
|
||||
|
||||
// 处理多模态模型配置
|
||||
kb.VLMConfig = types.VLMConfig{}
|
||||
|
||||
@@ -487,6 +487,51 @@ 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 删除指定的知识库及其所有内容
|
||||
|
||||
Reference in New Issue
Block a user