feat: Implement delete functionality for generated questions in knowledge base, including API and UI updates

This commit is contained in:
wizardchen
2025-12-04 01:26:30 +08:00
parent 740974c53e
commit a50f53d205
18 changed files with 415 additions and 18 deletions
+19 -1
View File
@@ -19,12 +19,30 @@ type FAQChunkMetadata struct {
Source string `json:"source,omitempty"`
}
// GeneratedQuestion 表示AI生成的单个问题
type GeneratedQuestion struct {
ID string `json:"id"` // 唯一标识,用于构造 source_id
Question string `json:"question"` // 问题内容
}
// DocumentChunkMetadata 定义文档 Chunk 的元数据结构
// 用于存储AI生成的问题等增强信息
type DocumentChunkMetadata struct {
// GeneratedQuestions 存储AI为该Chunk生成的相关问题
// 这些问题会被独立索引以提高召回率
GeneratedQuestions []string `json:"generated_questions,omitempty"`
GeneratedQuestions []GeneratedQuestion `json:"generated_questions,omitempty"`
}
// GetQuestionStrings 返回问题内容字符串列表(兼容旧代码)
func (m *DocumentChunkMetadata) GetQuestionStrings() []string {
if m == nil || len(m.GeneratedQuestions) == 0 {
return nil
}
result := make([]string, len(m.GeneratedQuestions))
for i, q := range m.GeneratedQuestions {
result[i] = q.Question
}
return result
}
// DocumentMetadata 解析 Chunk 中的文档元数据
+3
View File
@@ -83,4 +83,7 @@ type ChunkService interface {
ListChunkByParentID(ctx context.Context, tenantID uint64, parentID string) ([]*types.Chunk, error)
// GetRepository gets the chunk repository
GetRepository() ChunkRepository
// DeleteGeneratedQuestion deletes a single generated question from a chunk by question ID
// This updates the chunk metadata and removes the corresponding vector index
DeleteGeneratedQuestion(ctx context.Context, chunkID string, questionID string) error
}
+5
View File
@@ -32,6 +32,8 @@ type RetrieveEngineRepository interface {
// DeleteByChunkIDList deletes the index info by chunk id list
DeleteByChunkIDList(ctx context.Context, indexIDList []string, dimension int) error
// DeleteBySourceIDList deletes the index info by source id list
DeleteBySourceIDList(ctx context.Context, sourceIDList []string, dimension int) error
// 复制索引数据
// sourceKnowledgeBaseID: 源知识库ID
// sourceToTargetChunkIDMap: 源分块ID到目标分块ID的映射关系
@@ -105,6 +107,9 @@ type RetrieveEngineService interface {
// DeleteByChunkIDList deletes the index info by chunk id list
DeleteByChunkIDList(ctx context.Context, indexIDList []string, dimension int) error
// DeleteBySourceIDList deletes the index info by source id list
DeleteBySourceIDList(ctx context.Context, sourceIDList []string, dimension int) error
// DeleteByKnowledgeIDList deletes the index info by knowledge id list
DeleteByKnowledgeIDList(ctx context.Context, knowledgeIDList []string, dimension int) error