fix(search): apply tag filters to knowledge search

This commit is contained in:
langcaiye
2026-07-03 10:42:54 +08:00
committed by lyingbug
parent b16cb0bb56
commit 1708d6895a
13 changed files with 363 additions and 87 deletions
+6 -5
View File
@@ -168,11 +168,12 @@ func (c *ChatManage) Clone() *ChatManage {
tagIDsCopy := make([]string, len(t.TagIDs))
copy(tagIDsCopy, t.TagIDs)
searchTargets[i] = &SearchTarget{
Type: t.Type,
KnowledgeBaseID: t.KnowledgeBaseID,
TenantID: t.TenantID,
KnowledgeIDs: kidsCopy,
TagIDs: tagIDsCopy,
Type: t.Type,
KnowledgeBaseID: t.KnowledgeBaseID,
TenantID: t.TenantID,
KnowledgeIDs: kidsCopy,
TagIDs: tagIDsCopy,
DisableDirectLoad: t.DisableDirectLoad,
}
}
}
+3
View File
@@ -69,6 +69,9 @@ type KnowledgeService interface {
GetKnowledgeBatch(ctx context.Context, tenantID uint64, ids []string) ([]*types.Knowledge, error)
// GetKnowledgeBatchWithSharedAccess retrieves knowledge by IDs including items from shared KBs the user has access to.
GetKnowledgeBatchWithSharedAccess(ctx context.Context, tenantID uint64, ids []string) ([]*types.Knowledge, error)
// ListKnowledgeIDsByTagIDs returns document knowledge IDs carrying any of
// the specified KB-local tags.
ListKnowledgeIDsByTagIDs(ctx context.Context, tenantID uint64, kbID string, tagIDs []string) ([]string, error)
// ListKnowledgeByKnowledgeBaseID lists all knowledge under a knowledge base.
ListKnowledgeByKnowledgeBaseID(ctx context.Context, kbID string) ([]*types.Knowledge, error)
// ListPagedKnowledgeByKnowledgeBaseID lists all knowledge under a knowledge base
+1 -1
View File
@@ -54,7 +54,7 @@ type SessionService interface {
// SearchKnowledge performs knowledge-based search, without summarization
// knowledgeBaseIDs: list of knowledge base IDs to search (supports multi-KB)
// knowledgeIDs: list of specific knowledge (file) IDs to search
SearchKnowledge(ctx context.Context, knowledgeBaseIDs []string, knowledgeIDs []string, query string) ([]*types.SearchResult, error)
SearchKnowledge(ctx context.Context, knowledgeBaseIDs []string, knowledgeIDs []string, tagScopes []types.TagScope, query string) ([]*types.SearchResult, error)
// AgentQA performs agent-based question answering with conversation history and streaming support.
AgentQA(ctx context.Context, req *types.QARequest, eventBus *event.EventBus) error
}
+5
View File
@@ -36,6 +36,11 @@ type SearchTarget struct {
KnowledgeIDs []string `json:"knowledge_ids,omitempty"`
// TagIDs limits retrieval to chunks/documents carrying any of these KB-local tags.
TagIDs []string `json:"tag_ids,omitempty"`
// DisableDirectLoad forces the target through retrieval even when it is
// represented as specific knowledge IDs. Tag-derived document scopes need
// this so tag filtering limits the candidate documents without loading every
// matching document chunk as context.
DisableDirectLoad bool `json:"disable_direct_load,omitempty"`
}
// SearchTargets is a list of search targets, pre-computed at request entry point