Mintplex-Labs/anything-llm · error · Error

Invalid request to performSimilaritySearch.

Error message

Invalid request to performSimilaritySearch.

What it means

ChromaVectorDb.performSimilaritySearch destructures { namespace, input, LLMConnector } and immediately throws if any of the three is falsy. This is an internal API used by chat flows (chats/stream.js, embed.js, apiChatHandler) and by the workspace /api endpoint for RAG retrieval; the guard prevents querying with an unscoped namespace, empty query, or missing embedder connector.

Source

Thrown at server/utils/vectorDbProviders/chroma/index.js:379

    const vectorIds = knownDocuments.map((doc) => doc.vectorId);
    await this.smartDelete(collection, vectorIds);

    const indexes = knownDocuments.map((doc) => doc.id);
    await DocumentVectors.deleteIds(indexes);
    return true;
  }

  async performSimilaritySearch({
    namespace = null,
    input = "",
    LLMConnector = null,
    similarityThreshold = 0.25,
    topN = 4,
    filterIdentifiers = [],
  }) {
    if (!namespace || !input || !LLMConnector)
      throw new Error("Invalid request to performSimilaritySearch.");

    const { client } = await this.connect();
    if (!(await this.namespaceExists(client, this.normalize(namespace)))) {
      return {
        contextTexts: [],
        sources: [],
        message: "Invalid query - no documents found for workspace!",
      };
    }

    const queryVector = await LLMConnector.embedTextInput(input);
    const { contextTexts, sourceDocuments, scores } =
      await this.similarityResponse({
        client,
        namespace,
        queryVector,
        similarityThreshold,
        topN,

View on GitHub (pinned to 20f6d3546c)

Solutions

  1. Pass all three required params: a non-empty namespace (workspace slug), non-empty input, and the LLMConnector (from getLLMProvider) that embeds the query.
  2. In custom code, fetch the workspace first and bail early if it (or its slug) is missing.
  3. Trim/validate user input before invoking retrieval so empty queries short-circuit in your handler.

Example fix

// before
const results = await VectorDb.performSimilaritySearch({
  namespace: workspace?.slug,
  input,
});

// after
if (!workspace?.slug || !input?.trim()) return { contextTexts: [], sources: [] };
const LLMConnector = getLLMProvider({ model });
const results = await VectorDb.performSimilaritySearch({
  namespace: workspace.slug,
  input: input.trim(),
  LLMConnector,
});
Defensive patterns

Strategy: validation

Validate before calling

function assertSimilaritySearchArgs({ namespace, input, LLMConnector }) {
  if (!namespace) throw new Error('namespace is required');
  if (!input?.trim()) throw new Error('input is required');
  if (!LLMConnector || typeof LLMConnector.embedTextInput !== 'function') {
    throw new Error('LLMConnector with embedTextInput() is required');
  }
}

Type guard

function isValidSearchRequest(req) {
  return !!req?.namespace && typeof req.input === 'string' && req.input.trim().length > 0
    && !!req.LLMConnector && typeof req.LLMConnector.embedTextInput === 'function';
}

Prevention

When it happens

Trigger: Calling performSimilaritySearch({ namespace: null, ... }) from custom code, a workspace whose slug is undefined, an empty query string reaching the retrieval layer, or forgetting to pass the LLM connector that provides embedTextInput() for the query vector.

Common situations: Custom integrations/middleware calling VectorDb.performSimilaritySearch directly; race where the workspace record is gone before the chat executes; tests invoking the method with placeholder args.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/89791422ba3c8c5c. Report an issue: GitHub.