feat: 知识库异步复制功能支持进度追踪和增量同步
This commit is contained in:
@@ -6,6 +6,7 @@ const (
|
||||
TypeFAQImport = "faq:import" // FAQ导入任务
|
||||
TypeQuestionGeneration = "question:generation" // 问题生成任务
|
||||
TypeSummaryGeneration = "summary:generation" // 摘要生成任务
|
||||
TypeKBClone = "kb:clone" // 知识库复制任务
|
||||
)
|
||||
|
||||
// ExtractChunkPayload represents the extract chunk task payload
|
||||
@@ -56,6 +57,39 @@ type SummaryGenerationPayload struct {
|
||||
KnowledgeID string `json:"knowledge_id"`
|
||||
}
|
||||
|
||||
// KBClonePayload represents the knowledge base clone task payload
|
||||
type KBClonePayload struct {
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
TaskID string `json:"task_id"`
|
||||
SourceID string `json:"source_id"`
|
||||
TargetID string `json:"target_id"`
|
||||
}
|
||||
|
||||
// KBCloneTaskStatus represents the status of a knowledge base clone task
|
||||
type KBCloneTaskStatus string
|
||||
|
||||
const (
|
||||
KBCloneStatusPending KBCloneTaskStatus = "pending"
|
||||
KBCloneStatusProcessing KBCloneTaskStatus = "processing"
|
||||
KBCloneStatusCompleted KBCloneTaskStatus = "completed"
|
||||
KBCloneStatusFailed KBCloneTaskStatus = "failed"
|
||||
)
|
||||
|
||||
// KBCloneProgress represents the progress of a knowledge base clone task
|
||||
type KBCloneProgress struct {
|
||||
TaskID string `json:"task_id"`
|
||||
SourceID string `json:"source_id"`
|
||||
TargetID string `json:"target_id"`
|
||||
Status KBCloneTaskStatus `json:"status"`
|
||||
Progress int `json:"progress"` // 0-100
|
||||
Total int `json:"total"` // 总知识数
|
||||
Processed int `json:"processed"` // 已处理数
|
||||
Message string `json:"message"` // 状态消息
|
||||
Error string `json:"error"` // 错误信息
|
||||
CreatedAt int64 `json:"created_at"` // 任务创建时间
|
||||
UpdatedAt int64 `json:"updated_at"` // 最后更新时间
|
||||
}
|
||||
|
||||
// ChunkContext represents chunk content with surrounding context
|
||||
type ChunkContext struct {
|
||||
ChunkID string `json:"chunk_id"`
|
||||
|
||||
@@ -61,6 +61,9 @@ type ChunkRepository interface {
|
||||
// UpdateChunkFieldsByTagID updates fields for all chunks with the specified tag ID.
|
||||
// Supports updating is_enabled and flags fields.
|
||||
UpdateChunkFieldsByTagID(ctx context.Context, tenantID uint64, kbID string, tagID string, isEnabled *bool, setFlags types.ChunkFlags, clearFlags types.ChunkFlags) ([]string, error)
|
||||
// FAQChunkDiff compares FAQ chunks between two knowledge bases and returns the differences.
|
||||
// Returns: chunksToAdd (content_hash in src but not in dst), chunksToDelete (content_hash in dst but not in src)
|
||||
FAQChunkDiff(ctx context.Context, srcTenantID uint64, srcKBID string, dstTenantID uint64, dstKBID string) (chunksToAdd []string, chunksToDelete []string, err error)
|
||||
}
|
||||
|
||||
// ChunkService defines the interface for chunk service operations
|
||||
|
||||
@@ -111,6 +111,12 @@ type KnowledgeService interface {
|
||||
ProcessQuestionGeneration(ctx context.Context, t *asynq.Task) error
|
||||
// ProcessSummaryGeneration handles Asynq summary generation tasks
|
||||
ProcessSummaryGeneration(ctx context.Context, t *asynq.Task) error
|
||||
// ProcessKBClone handles Asynq knowledge base clone tasks
|
||||
ProcessKBClone(ctx context.Context, t *asynq.Task) error
|
||||
// GetKBCloneProgress retrieves the progress of a knowledge base clone task
|
||||
GetKBCloneProgress(ctx context.Context, taskID string) (*types.KBCloneProgress, error)
|
||||
// SaveKBCloneProgress saves the progress of a knowledge base clone task
|
||||
SaveKBCloneProgress(ctx context.Context, progress *types.KBCloneProgress) error
|
||||
}
|
||||
|
||||
// KnowledgeRepository defines the interface for knowledge repositories.
|
||||
|
||||
Reference in New Issue
Block a user