Tencent/WeKnora · error

document not found

Error message

document %s not found: %w

What it means

Knowledge authorization lookup failed: GetKnowledgeByIDOnly returned an error or an empty result for the given knowledge ID, so the document cannot be verified against the Agent's search scope and access is denied with a not-found error (avoiding existence disclosure).

Solutions

  1. Confirm the knowledge ID exists
  2. Check storage connectivity if the inner error is not 'empty result'
  3. Return a stable not-found response regardless of missing vs unauthorized
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/agent/tools/scope_authorization.go:77 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/30727b58f427bb6c. Report an issue: GitHub.

Appendix: source

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

func authorizeKnowledgeInSearchTargets(
	ctx context.Context,
	searchTargets types.SearchTargets,
	knowledgeID string,
	knowledgeService interfaces.KnowledgeService,
) (*types.Knowledge, error) {
	knowledgeID = strings.TrimSpace(knowledgeID)
	if knowledgeID == "" {
		return nil, fmt.Errorf("knowledge_id is required")
	}
	if knowledgeService == nil {
		return nil, fmt.Errorf("knowledge service is unavailable")
	}
	knowledge, err := knowledgeService.GetKnowledgeByIDOnly(ctx, knowledgeID)
	if err != nil || knowledge == nil {
		if err == nil {
			err = fmt.Errorf("empty result")
		}
		return nil, fmt.Errorf("document %s not found: %w", knowledgeID, err)
	}
	if !searchTargets.ContainsKB(knowledge.KnowledgeBaseID) {
		return nil, fmt.Errorf("knowledge base %s is not within the current Agent scope", knowledge.KnowledgeBaseID)
	}
	allowed, err := searchTargetsAllowKnowledgeID(
		ctx, searchTargets, knowledge.ID, knowledge.KnowledgeBaseID, knowledgeService,
	)
	if err != nil {
		return nil, fmt.Errorf("failed to validate document scope: %w", err)
	}
	if !allowed {
		return nil, fmt.Errorf("document %s is not within the current @mention scope", knowledge.ID)
	}
	return knowledge, nil
}

// authorizeChunkInSearchTargets is the chunk/FAQ counterpart of
// authorizeKnowledgeInSearchTargets. A chunk ID is accepted only after the

View on GitHub (pinned to 988cbb0330)