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
+12 -5
View File
@@ -519,22 +519,29 @@ func (h *Handler) SearchKnowledge(c *gin.Context) {
}
}
if len(knowledgeBaseIDs) == 0 && len(request.KnowledgeIDs) == 0 {
logger.Error(ctx, "No knowledge base IDs or knowledge IDs provided")
c.Error(errors.NewBadRequestError("At least one knowledge_base_id, knowledge_base_ids or knowledge_ids must be provided"))
tagScopes := mergeTagScopesFromRequestIDs(
tagScopesFromMentionedItems(request.MentionedItems),
dedupRequestStrings(request.TagIDs),
secutils.SanitizeForLogArray(knowledgeBaseIDs),
)
if len(knowledgeBaseIDs) == 0 && len(request.KnowledgeIDs) == 0 && len(tagScopes) == 0 {
logger.Error(ctx, "No knowledge base IDs, knowledge IDs, or tag scopes provided")
c.Error(errors.NewBadRequestError("At least one knowledge_base_id, knowledge_base_ids, knowledge_ids, or scoped tag must be provided"))
return
}
logger.Infof(
ctx,
"Knowledge search request, knowledge base IDs: %v, knowledge IDs: %v, query: %s",
"Knowledge search request, knowledge base IDs: %v, knowledge IDs: %v, tag scopes: %d, query: %s",
secutils.SanitizeForLogArray(knowledgeBaseIDs),
secutils.SanitizeForLogArray(request.KnowledgeIDs),
len(tagScopes),
secutils.SanitizeForLog(request.Query),
)
// Directly call knowledge retrieval service without LLM summarization
searchResults, err := h.sessionService.SearchKnowledge(ctx, knowledgeBaseIDs, request.KnowledgeIDs, request.Query)
searchResults, err := h.sessionService.SearchKnowledge(ctx, knowledgeBaseIDs, request.KnowledgeIDs, tagScopes, request.Query)
if err != nil {
logger.ErrorWithFields(ctx, err, nil)
c.Error(errors.NewInternalServerError(err.Error()))
+6 -4
View File
@@ -80,10 +80,12 @@ type AttachmentUpload struct {
// SearchKnowledgeRequest defines the request structure for searching knowledge without LLM summarization
type SearchKnowledgeRequest struct {
Query string `json:"query" binding:"required"` // Query text to search for
KnowledgeBaseID string `json:"knowledge_base_id"` // Single knowledge base ID (for backward compatibility)
KnowledgeBaseIDs []string `json:"knowledge_base_ids"` // IDs of knowledge bases to search (multi-KB support)
KnowledgeIDs []string `json:"knowledge_ids"` // IDs of specific knowledge (files) to search
Query string `json:"query" binding:"required"` // Query text to search for
KnowledgeBaseID string `json:"knowledge_base_id"` // Single knowledge base ID (for backward compatibility)
KnowledgeBaseIDs []string `json:"knowledge_base_ids"` // IDs of knowledge bases to search (multi-KB support)
KnowledgeIDs []string `json:"knowledge_ids"` // IDs of specific knowledge (files) to search
TagIDs []string `json:"tag_ids"` // Tag IDs for filtering within a single KB
MentionedItems []MentionedItemRequest `json:"mentioned_items"` // Optional scoped tag mentions
}
// StopSessionRequest represents the stop session request