Tencent/WeKnora · error

graph result document %s belongs to knowledge base %s, expec

Error message

graph result document %s belongs to knowledge base %s, expected %s

What it means

Data-integrity guard while filtering graph search results: a returned graph result claims a knowledge base ID that differs from the KB the query was issued against, indicating cross-KB contamination or corrupted result metadata; the filter aborts rather than silently returning out-of-scope documents.

Source

Thrown at internal/agent/tools/scope_authorization.go:267

		targetKnowledgeIDs, targetTagIDs := searchTargetScope(target)
		explicitIDs = append(explicitIDs, targetKnowledgeIDs...)
		tagIDs = append(tagIDs, targetTagIDs...)
	}
	if !matchedKB {
		return nil, fmt.Errorf("knowledge base %s is not within the current Agent scope", kbID)
	}

	explicitSet := make(map[string]struct{}, len(explicitIDs))
	for _, id := range dedupNonEmptyStrings(explicitIDs) {
		explicitSet[id] = struct{}{}
	}
	remainingIDs := make([]string, 0, len(results))
	for _, result := range results {
		if result == nil || result.KnowledgeID == "" {
			continue
		}
		if result.KnowledgeBaseID != "" && result.KnowledgeBaseID != kbID {
			return nil, fmt.Errorf(
				"graph result document %s belongs to knowledge base %s, expected %s",
				result.KnowledgeID, result.KnowledgeBaseID, kbID,
			)
		}
		if _, ok := explicitSet[result.KnowledgeID]; !ok {
			remainingIDs = append(remainingIDs, result.KnowledgeID)
		}
	}
	var tagMatches map[string]bool
	if len(tagIDs) > 0 {
		if knowledgeService == nil {
			return nil, fmt.Errorf("knowledge service is unavailable for tag-scoped graph filtering")
		}
		var err error
		tagMatches, err = knowledgeIDsMatchingAnyTag(
			ctx, remainingIDs, tagIDs, knowledgeService.GetKnowledgeTags,
		)
		if err != nil {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Log the offending result and investigate index cross-contamination
  2. Drop the mismatched result instead of failing the whole filter if acceptable
  3. Verify the graph index isolates documents per knowledge base
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/agent/tools/scope_authorization.go:267 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/445c4ae13d03c420. Report an issue: GitHub.