Tencent/WeKnora · error

knowledge service is unavailable

Error message

knowledge service is unavailable

What it means

authorizeKnowledgeInSearchTargets throws this when the injected interfaces.KnowledgeService dependency is nil. Without a configured knowledge service the tool cannot fetch or authorize the requested knowledge item, so it fails fast instead of nil-pointer panicking.

Source

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

		len(knowledgeIDs) == 0 && len(tagIDs) == 0
}

// authorizeKnowledgeInSearchTargets is the shared authorization boundary for
// every Agent tool that accepts a model-visible dN/knowledge_id. Handle
// decoding is necessary but never sufficient: the durable document must also
// belong to the server-owned search scope for this Agent execution.
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 {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Initialize and inject a KnowledgeService implementation when constructing the tool/agent.
  2. Enable the knowledge feature in configuration so the service is registered with the DI container.
  3. Guard callers with a nil check on the service and return a clear configuration error at startup rather than at call time.

Example fix

// before
tool := NewSearchTool(logger) // KnowledgeService never wired
// after
tool := NewSearchTool(logger, WithKnowledgeService(knowledgeService))
Defensive patterns

Strategy: validation

Validate before calling

if knowledgeService == nil {
    return fmt.Errorf("knowledge service not configured; check DI wiring/config")
}

Try / catch

knowledge, err := authorizeKnowledgeInSearchTargets(ctx, targets, kbID, svc)
if err != nil && strings.Contains(err.Error(), "knowledge service is unavailable") {
    return nil, fmt.Errorf("knowledge feature disabled or misconfigured: %w", err)
}

Prevention

When it happens

Trigger: Constructing the tool (or the agent toolset) without wiring a KnowledgeService implementation — knowledgeService parameter is nil when Execute / resolveAuthorizedSourceRefs reaches authorizeKnowledgeInSearchTargets.

Common situations: Knowledge feature not enabled in config so the service was never registered in DI; running in an environment/deployment mode where the knowledge store isn't initialized; a refactor changed the constructor and the dependency was dropped.

Related errors


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