feat: support multi-tag for document knowledge (#1790)
* feat: support multi-tag for document knowledge - Add knowledge_tag_relations join table for many-to-many tag-knowledge mapping - Migrate existing single tag_id data to the new table - Update Knowledge struct, filter, payload types (TagID -> Tags/TagIDs) - Rewrite repository layer: SetKnowledgeTags, GetKnowledgeTags, ListIDsByTagIDs - Update tag count references to query knowledge_tag_relations - Update service/handler layers for multi-tag create/list/batch-update - Frontend: multi-select tag sidebar, multi-tag chip display, tag toggle in popup - FAQ tags remain single-tag model (unchanged) * feat(knowledge): tag edit dialog with dynamic overflow and inline creation - Add TagEditDialog component with search, multi-select, and confirm - Replace inline t-popup tag selector with dialog-based editing - Tags overflow with +N badge, visible count adapts to container width via ResizeObserver - Date/card layout: fixed date width, tags flex to fill remaining space - Add persistent new-tag input bar in dialog (Enter to create, auto-select) - Tag creation emits callback to refresh parent tag list immediately - Apply same overflow + dialog trigger to both card view and list view - Add i18n keys: tagEditDialogTitle, tagEditSearch, tagSelectedCount, tagOverflowTip, tagNewPlaceholder * fix: exclude soft-deleted knowledge from tag reference counts CountReferences, BatchCountReferences, and DeleteUnusedTags now JOIN with knowledges table to filter out soft-deleted records when counting knowledge_tag_relations. Previously they queried knowledge_tag_relations directly without the deleted_at check, causing stale tag counts after knowledge deletion. * fix: refresh tag counts after async knowledge deletion completes Add a second delayed tag list refresh (2.5s) after tag deletion to capture updated reference counts for remaining tags. The original immediate refresh handles removing the deleted tag from the list, while this delayed refresh ensures other tags' counts are correct after the async deletion finishes. --------- Co-authored-by: lyingbug <xiayula2014@gmail.com>
This commit is contained in:
@@ -696,13 +696,13 @@ func (s *DataSourceService) ProcessSync(ctx context.Context, task *asynq.Task) e
|
||||
ctx = context.WithValue(ctx, types.TenantInfoContextKey, tenant)
|
||||
|
||||
// Auto-tag: find or create a tag for this data source so synced items are easily identifiable
|
||||
autoTagID := ""
|
||||
autoTagIDs := []string{}
|
||||
autoTagName := ds.Name
|
||||
if autoTag, tagErr := s.tagService.FindOrCreateTagByName(ctx, ds.KnowledgeBaseID, autoTagName); tagErr != nil {
|
||||
logger.Warnf(ctx, "failed to find/create auto-tag %q: %v (proceeding without tag)", autoTagName, tagErr)
|
||||
} else if autoTag != nil {
|
||||
autoTagID = autoTag.ID
|
||||
logger.Infof(ctx, "using auto-tag %q (id=%s) for data source sync", autoTagName, autoTagID)
|
||||
autoTagIDs = append(autoTagIDs, autoTag.ID)
|
||||
logger.Infof(ctx, "using auto-tag %q (id=%s) for data source sync", autoTagName, autoTag.ID)
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
@@ -729,7 +729,7 @@ func (s *DataSourceService) ProcessSync(ctx context.Context, task *asynq.Task) e
|
||||
continue
|
||||
}
|
||||
|
||||
isUpdate, err := s.ingestItem(ctx, ds, &item, autoTagID)
|
||||
isUpdate, err := s.ingestItem(ctx, ds, &item, autoTagIDs)
|
||||
if err != nil {
|
||||
// Duplicate file/URL is not a failure — count as skipped
|
||||
var dupErr *types.DuplicateKnowledgeError
|
||||
@@ -886,7 +886,7 @@ func (s *DataSourceService) validateDataSourceConfig(ctx context.Context, ds *ty
|
||||
// - Has URL only → CreateKnowledgeFromURL (让 WeKnora 下载并解析)
|
||||
//
|
||||
// Returns (isUpdate, error) — isUpdate is true when an existing item was replaced.
|
||||
func (s *DataSourceService) ingestItem(ctx context.Context, ds *types.DataSource, item *types.FetchedItem, tagID string) (bool, error) {
|
||||
func (s *DataSourceService) ingestItem(ctx context.Context, ds *types.DataSource, item *types.FetchedItem, tagIDs []string) (bool, error) {
|
||||
channel := ds.Type // e.g. "feishu", "notion"
|
||||
|
||||
metadata := map[string]string{
|
||||
@@ -929,7 +929,7 @@ func (s *DataSourceService) ingestItem(ctx context.Context, ds *types.DataSource
|
||||
metadata,
|
||||
nil, // use KB default for multimodal
|
||||
item.FileName, // customFileName — must include extension for file-type validation
|
||||
tagID, // auto-tag from data source
|
||||
tagIDs, // auto-tag from data source
|
||||
channel,
|
||||
nil,
|
||||
)
|
||||
@@ -946,7 +946,7 @@ func (s *DataSourceService) ingestItem(ctx context.Context, ds *types.DataSource
|
||||
"", // auto-detect file type
|
||||
nil, // use KB default for multimodal
|
||||
item.Title,
|
||||
tagID, // auto-tag from data source
|
||||
tagIDs, // auto-tag from data source
|
||||
channel,
|
||||
nil,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user