Tencent/WeKnora · error

query is empty

Error message

query is empty

What it means

Search() rejects an empty query (len(query) == 0) before contacting Tavily. Note it does not trim whitespace, unlike the SearXNG provider, so a space-only string passes here and is sent to the API. Tavily cannot execute a meaningful search for an empty query, so the provider fails fast client-side.

Source

Thrown at internal/infrastructure/web_search/tavily.go:63

		baseURL: defaultTavilySearchURL,
		apiKey:  params.APIKey,
	}, nil
}

// Name returns the provider name
func (p *TavilyProvider) Name() string {
	return "tavily"
}

// Search performs a web search using Tavily Search API
func (p *TavilyProvider) Search(
	ctx context.Context,
	query string,
	maxResults int,
	includeDate bool,
) ([]*types.WebSearchResult, error) {
	if len(query) == 0 {
		return nil, fmt.Errorf("query is empty")
	}
	logger.Infof(ctx, "[WebSearch][Tavily] query=%q maxResults=%d url=%s", query, maxResults, p.baseURL)

	reqBody := tavilySearchRequest{
		APIKey:     p.apiKey,
		Query:      query,
		MaxResults: maxResults,
	}

	bodyBytes, err := json.Marshal(reqBody)
	if err != nil {
		return nil, fmt.Errorf("failed to marshal request: %w", err)
	}

	req, err := http.NewRequestWithContext(ctx, "POST", p.baseURL, bytes.NewReader(bodyBytes))
	if err != nil {
		return nil, fmt.Errorf("failed to create request: %w", err)
	}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Trim and check the query before calling Search; skip the search step for blank input
  2. Use strings.TrimSpace to also catch whitespace-only queries (this provider only checks length)
  3. Fix the upstream query-producing code so it never yields empty strings
  4. Return a benign empty result set rather than surfacing an error for blank queries

Example fix

// before
results, err := provider.Search(ctx, query, 5, false)
// after
query = strings.TrimSpace(query)
if query == "" {
    return nil, nil // skip search for blank query
}
results, err := provider.Search(ctx, query, 5, false)
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(query) == "" {
    return nil, nil // skip search
}

Prevention

When it happens

Trigger: Calling Search(ctx, "", n, false) on a TavilyProvider; empty string produced by upstream keyword extraction or an unfilled template variable.

Common situations: Empty user input flowing through a RAG pipeline; optional search step invoked unconditionally with a possibly-blank query string.

Related errors


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