Merge remote-tracking branch 'github_public/main'
This commit is contained in:
@@ -101,8 +101,9 @@ func (p *PluginMerge) OnEvent(ctx context.Context,
|
||||
}
|
||||
// Merge overlapping chunks
|
||||
if chunks[i].EndAt > lastChunk.EndAt {
|
||||
lastChunk.Content = lastChunk.Content +
|
||||
string([]rune(chunks[i].Content)[lastChunk.EndAt-chunks[i].StartAt:])
|
||||
content := string([]rune(chunks[i].Content))
|
||||
offset := len(content) - (chunks[i].EndAt - lastChunk.EndAt)
|
||||
lastChunk.Content = lastChunk.Content + content[offset:]
|
||||
lastChunk.EndAt = chunks[i].EndAt
|
||||
lastChunk.SubChunkID = append(lastChunk.SubChunkID, chunks[i].ID)
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ func (s *knowledgeService) isKnowledgeDeleting(ctx context.Context, tenantID uin
|
||||
|
||||
// CreateKnowledgeFromFile creates a knowledge entry from an uploaded file
|
||||
func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
||||
kbID string, file *multipart.FileHeader, metadata map[string]string, enableMultimodel *bool, customFileName string,
|
||||
kbID string, file *multipart.FileHeader, metadata map[string]string, enableMultimodel *bool, customFileName string, tagID string,
|
||||
) (*types.Knowledge, error) {
|
||||
logger.Info(ctx, "Start creating knowledge from file")
|
||||
|
||||
@@ -261,6 +261,7 @@ func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
||||
knowledge := &types.Knowledge{
|
||||
TenantID: tenantID,
|
||||
KnowledgeBaseID: kbID,
|
||||
TagID: tagID, // 设置分类ID,用于知识分类管理
|
||||
Type: "file",
|
||||
Title: safeFilename,
|
||||
FileName: safeFilename,
|
||||
@@ -358,8 +359,9 @@ func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
||||
}
|
||||
|
||||
// CreateKnowledgeFromURL creates a knowledge entry from a URL source
|
||||
// tagID is optional - when provided, the knowledge will be assigned to the specified tag/category.
|
||||
func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
|
||||
kbID string, url string, enableMultimodel *bool, title string,
|
||||
kbID string, url string, enableMultimodel *bool, title string, tagID string,
|
||||
) (*types.Knowledge, error) {
|
||||
logger.Info(ctx, "Start creating knowledge from URL")
|
||||
logger.Infof(ctx, "Knowledge base ID: %s, URL: %s", kbID, url)
|
||||
@@ -426,6 +428,7 @@ func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
EmbeddingModelID: kb.EmbeddingModelID,
|
||||
TagID: tagID, // 设置分类ID,用于知识分类管理
|
||||
}
|
||||
|
||||
// Save knowledge record
|
||||
@@ -557,6 +560,7 @@ func (s *knowledgeService) CreateKnowledgeFromManual(ctx context.Context,
|
||||
EmbeddingModelID: kb.EmbeddingModelID,
|
||||
FileName: fileName,
|
||||
FileType: types.KnowledgeTypeManual,
|
||||
TagID: payload.TagID, // 设置分类ID,用于知识分类管理
|
||||
}
|
||||
if err := knowledge.SetManualMetadata(meta); err != nil {
|
||||
logger.Errorf(ctx, "Failed to set manual metadata: %v", err)
|
||||
|
||||
@@ -164,8 +164,15 @@ func (h *KnowledgeHandler) CreateKnowledgeFromFile(c *gin.Context) {
|
||||
enableMultimodel = &parseBool
|
||||
}
|
||||
|
||||
// 获取分类ID(如果提供),用于知识分类管理
|
||||
tagID := c.PostForm("tag_id")
|
||||
// 过滤特殊值,空字符串或 "__untagged__" 表示未分类
|
||||
if tagID == "__untagged__" || tagID == "" {
|
||||
tagID = ""
|
||||
}
|
||||
|
||||
// Create knowledge entry from the file
|
||||
knowledge, err := h.kgService.CreateKnowledgeFromFile(ctx, kbID, file, metadata, enableMultimodel, customFileName)
|
||||
knowledge, err := h.kgService.CreateKnowledgeFromFile(ctx, kbID, file, metadata, enableMultimodel, customFileName, tagID)
|
||||
// Check for duplicate knowledge error
|
||||
if err != nil {
|
||||
if h.handleDuplicateKnowledgeError(c, err, knowledge, "file") {
|
||||
@@ -199,7 +206,7 @@ func (h *KnowledgeHandler) CreateKnowledgeFromFile(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "知识库ID"
|
||||
// @Param request body object{url=string,enable_multimodel=bool,title=string} true "URL请求"
|
||||
// @Param request body object{url=string,enable_multimodel=bool,title=string,tag_id=string} true "URL请求"
|
||||
// @Success 201 {object} map[string]interface{} "创建的知识"
|
||||
// @Failure 400 {object} errors.AppError "请求参数错误"
|
||||
// @Failure 409 {object} map[string]interface{} "URL重复"
|
||||
@@ -222,6 +229,7 @@ func (h *KnowledgeHandler) CreateKnowledgeFromURL(c *gin.Context) {
|
||||
URL string `json:"url" binding:"required"`
|
||||
EnableMultimodel *bool `json:"enable_multimodel"`
|
||||
Title string `json:"title"`
|
||||
TagID string `json:"tag_id"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error(ctx, "Failed to parse URL request", err)
|
||||
@@ -238,7 +246,7 @@ func (h *KnowledgeHandler) CreateKnowledgeFromURL(c *gin.Context) {
|
||||
)
|
||||
|
||||
// Create knowledge entry from the URL
|
||||
knowledge, err := h.kgService.CreateKnowledgeFromURL(ctx, kbID, req.URL, req.EnableMultimodel, req.Title)
|
||||
knowledge, err := h.kgService.CreateKnowledgeFromURL(ctx, kbID, req.URL, req.EnableMultimodel, req.Title, req.TagID)
|
||||
// Check for duplicate knowledge error
|
||||
if err != nil {
|
||||
if h.handleDuplicateKnowledgeError(c, err, knowledge, "url") {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
// KnowledgeService defines the interface for knowledge services.
|
||||
type KnowledgeService interface {
|
||||
// CreateKnowledgeFromFile creates knowledge from a file.
|
||||
// tagID is optional - when provided, the file will be assigned to the specified tag/category.
|
||||
CreateKnowledgeFromFile(
|
||||
ctx context.Context,
|
||||
kbID string,
|
||||
@@ -19,14 +20,17 @@ type KnowledgeService interface {
|
||||
metadata map[string]string,
|
||||
enableMultimodel *bool,
|
||||
customFileName string,
|
||||
tagID string,
|
||||
) (*types.Knowledge, error)
|
||||
// CreateKnowledgeFromURL creates knowledge from a URL.
|
||||
// tagID is optional - when provided, the knowledge will be assigned to the specified tag/category.
|
||||
CreateKnowledgeFromURL(
|
||||
ctx context.Context,
|
||||
kbID string,
|
||||
url string,
|
||||
enableMultimodel *bool,
|
||||
title string,
|
||||
tagID string,
|
||||
) (*types.Knowledge, error)
|
||||
// CreateKnowledgeFromPassage creates knowledge from text passages.
|
||||
CreateKnowledgeFromPassage(ctx context.Context, kbID string, passage []string) (*types.Knowledge, error)
|
||||
|
||||
@@ -144,6 +144,7 @@ type ManualKnowledgePayload struct {
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Status string `json:"status"`
|
||||
TagID string `json:"tag_id"`
|
||||
}
|
||||
|
||||
// NewManualKnowledgeMetadata creates a new ManualKnowledgeMetadata instance.
|
||||
|
||||
Reference in New Issue
Block a user