Tencent/WeKnora · error

query is empty

Error message

query is empty

What it means

Returned by ZhipuProvider.Search when normalizeZhipuQuery reduces the query to empty — the caller passed a blank/whitespace-only query that Zhipu's Web Search API would reject, so it fails fast before the network call.

Source

Thrown at internal/infrastructure/web_search/zhipu.go:111

	}
	return searchEngine, contentSize
}

// Name returns the provider name.
func (p *ZhipuProvider) Name() string {
	return "zhipu"
}

// Search performs a web search using Zhipu AI's standalone Web Search API.
func (p *ZhipuProvider) Search(
	ctx context.Context,
	query string,
	maxResults int,
	includeDate bool,
) ([]*types.WebSearchResult, error) {
	preparedQuery := normalizeZhipuQuery(query)
	if preparedQuery == "" {
		return nil, fmt.Errorf("query is empty")
	}
	if utf8.RuneCountInString(strings.TrimSpace(query)) > maxZhipuQueryRunes {
		logger.Infof(ctx, "[WebSearch][Zhipu] truncated query to %d characters", maxZhipuQueryRunes)
	}
	if maxResults <= 0 {
		maxResults = defaultZhipuResults
	}
	if maxResults > maxZhipuResults {
		maxResults = maxZhipuResults
	}

	requestBody := zhipuSearchRequest{
		SearchQuery:  preparedQuery,
		SearchEngine: p.searchEngine,
		SearchIntent: false,
		Count:        maxResults,
		ContentSize:  p.contentSize,
	}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Ensure callers pass a non-empty query
  2. Skip the search when the extracted query is blank

Example fix

// before
results, err := provider.Search(ctx, userInput, 5, false)
// after
if strings.TrimSpace(userInput) == "" {
    return nil, errors.New("search query must not be empty")
}
results, err := provider.Search(ctx, userInput, 5, false)
Defensive patterns

Strategy: validation

Validate before calling

func ensureNonEmptyQuery(q string) error {
    if strings.TrimSpace(q) == "" {
        return errors.New("search query must not be empty")
    }
    return nil
}
// call before provider.Search

Try / catch

results, err := provider.Search(ctx, q, 5, false)
if err != nil {
    if strings.Contains(err.Error(), "query is empty") {
        return fmt.Errorf("refusing empty search: provide a non-empty query (%w)", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling provider.Search with an empty string, whitespace-only string, or a string that normalizes to empty (e.g. stripped whitespace/control chars) as the query.

Common situations: Upstream pipeline producing empty user messages, variables not interpolated in templates ("" template result), over-aggressive input sanitization stripping the query, or empty search boxes in UIs submitted without validation.

Related errors


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