Mintplex-Labs/anything-llm · warning

Query parameter cannot be empty.

Error message

Query parameter cannot be empty.

What it means

HTTP 400 from POST /api/v1/workspace/:slug/vector-search when the body's query is falsy or an empty string (!query?.length). The query is the text that will be embedded for similarity search, so an empty value has nothing to embed. topN and scoreThreshold are optional and unrelated to this error.

Source

Thrown at server/endpoints/api/workspace/index.js:966

              ]
            }
          }
        }
      }
    }
    */
      try {
        const { slug } = request.params;
        const { query, topN, scoreThreshold } = reqBody(request);
        const workspace = await Workspace.get({ slug: String(slug) });

        if (!workspace)
          return response.status(400).json({
            message: `Workspace ${slug} is not a valid workspace.`,
          });

        if (!query?.length)
          return response.status(400).json({
            message: "Query parameter cannot be empty.",
          });

        const VectorDb = getVectorDbClass();
        const hasVectorizedSpace = await VectorDb.hasNamespace(workspace.slug);
        const embeddingsCount = await VectorDb.namespaceCount(workspace.slug);

        if (!hasVectorizedSpace || embeddingsCount === 0)
          return response.status(200).json({
            results: [],
            message: "No embeddings found for this workspace.",
          });

        const parseSimilarityThreshold = () => {
          let input = parseFloat(scoreThreshold);
          if (isNaN(input) || input < 0 || input > 1)
            return workspace?.similarityThreshold ?? 0.25;
          return input;

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Include a non-empty query string in the JSON body
  2. Set Content-Type: application/json on the request
  3. Guard client-side: skip the call when the search box is empty
  4. Trim the query and reject empty results of the trim

Example fix

// before
body: JSON.stringify({ topN: 4 }) // forgot query
// after
body: JSON.stringify({ query: q.trim(), topN: 4 })
Defensive patterns

Strategy: validation

Validate before calling

const q = String(query ?? '').trim();
if (!q) throw new Error('query required');
body = JSON.stringify({ query: q, topN, scoreThreshold });

Type guard

const hasQuery = (b) => typeof b?.query === 'string' && b.query.length > 0;

Prevention

When it happens

Trigger: POSTing {query:''} or omitting query entirely; sending {query:null}; a malformed JSON body (wrong Content-Type) so reqBody returns an empty object with no query key.

Common situations: Search input submitted without text; templated query strings that render to empty; client sends form-encoded body that the JSON parser ignores.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/def6b006cc79cb63. Report an issue: GitHub.