feat: 优化标签ID处理逻辑,新增批量更新TagID功能

This commit is contained in:
wizardchen
2025-12-25 17:16:35 +08:00
committed by lyingbug
parent 4c0846f9c7
commit a025ebe7fb
4 changed files with 22 additions and 7 deletions
+4 -1
View File
@@ -228,6 +228,9 @@ type FAQSearchRequest struct {
MatchCount int `json:"match_count"`
}
// UntaggedTagID is the special tag ID representing uncategorized entries
const UntaggedTagID = "__untagged__"
// FAQEntryFieldsUpdate 单个FAQ条目的字段更新
type FAQEntryFieldsUpdate struct {
IsEnabled *bool `json:"is_enabled,omitempty"`
@@ -243,7 +246,7 @@ type FAQEntryFieldsUpdate struct {
type FAQEntryFieldsBatchUpdate struct {
// ByID 按条目ID更新,key为条目ID
ByID map[string]FAQEntryFieldsUpdate `json:"by_id,omitempty"`
// ByTag 按Tag批量更新,key为TagID(空字符串表示未分类)
// ByTag 按Tag批量更新,key为TagID(__untagged__表示未分类)
ByTag map[string]FAQEntryFieldsUpdate `json:"by_tag,omitempty"`
// ExcludeIDs 在ByTag操作中需要排除的ID列表
ExcludeIDs []string `json:"exclude_ids,omitempty"`
+3 -2
View File
@@ -64,8 +64,9 @@ type ChunkRepository interface {
// clearFlags: map of chunk ID to flags to clear (AND NOT operation)
UpdateChunkFlagsBatch(ctx context.Context, tenantID uint64, kbID string, setFlags map[string]types.ChunkFlags, clearFlags map[string]types.ChunkFlags) error
// 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, excludeIDs []string) ([]string, error)
// Supports updating is_enabled, flags, and tag_id fields.
// newTagID: if not nil, updates tag_id to this value (empty string means uncategorized)
UpdateChunkFieldsByTagID(ctx context.Context, tenantID uint64, kbID string, tagID string, isEnabled *bool, setFlags types.ChunkFlags, clearFlags types.ChunkFlags, newTagID *string, excludeIDs []string) ([]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)