{"record":{"id":"89791422ba3c8c5c","repo":"Mintplex-Labs/anything-llm","slug":"invalid-request-to-performsimilaritysearch","errorCode":null,"errorMessage":"Invalid request to performSimilaritySearch.","messagePattern":"Invalid request to performSimilaritySearch\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/vectorDbProviders/chroma/index.js","lineNumber":379,"sourceCode":"\n    const vectorIds = knownDocuments.map((doc) => doc.vectorId);\n    await this.smartDelete(collection, vectorIds);\n\n    const indexes = knownDocuments.map((doc) => doc.id);\n    await DocumentVectors.deleteIds(indexes);\n    return true;\n  }\n\n  async performSimilaritySearch({\n    namespace = null,\n    input = \"\",\n    LLMConnector = null,\n    similarityThreshold = 0.25,\n    topN = 4,\n    filterIdentifiers = [],\n  }) {\n    if (!namespace || !input || !LLMConnector)\n      throw new Error(\"Invalid request to performSimilaritySearch.\");\n\n    const { client } = await this.connect();\n    if (!(await this.namespaceExists(client, this.normalize(namespace)))) {\n      return {\n        contextTexts: [],\n        sources: [],\n        message: \"Invalid query - no documents found for workspace!\",\n      };\n    }\n\n    const queryVector = await LLMConnector.embedTextInput(input);\n    const { contextTexts, sourceDocuments, scores } =\n      await this.similarityResponse({\n        client,\n        namespace,\n        queryVector,\n        similarityThreshold,\n        topN,","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/vectorDbProviders/chroma/index.js#L361-L397","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass all three required params: a non-empty namespace (workspace slug), non-empty input, and the LLMConnector (from getLLMProvider) that embeds the query.","In custom code, fetch the workspace first and bail early if it (or its slug) is missing.","Trim/validate user input before invoking retrieval so empty queries short-circuit in your handler."],"exampleFix":"// before\nconst results = await VectorDb.performSimilaritySearch({\n  namespace: workspace?.slug,\n  input,\n});\n\n// after\nif (!workspace?.slug || !input?.trim()) return { contextTexts: [], sources: [] };\nconst LLMConnector = getLLMProvider({ model });\nconst results = await VectorDb.performSimilaritySearch({\n  namespace: workspace.slug,\n  input: input.trim(),\n  LLMConnector,\n});","handlingStrategy":"validation","validationCode":"function assertSimilaritySearchArgs({ namespace, input, LLMConnector }) {\n  if (!namespace) throw new Error('namespace is required');\n  if (!input?.trim()) throw new Error('input is required');\n  if (!LLMConnector || typeof LLMConnector.embedTextInput !== 'function') {\n    throw new Error('LLMConnector with embedTextInput() is required');\n  }\n}","typeGuard":"function isValidSearchRequest(req) {\n  return !!req?.namespace && typeof req.input === 'string' && req.input.trim().length > 0\n    && !!req.LLMConnector && typeof req.LLMConnector.embedTextInput === 'function';\n}","tryCatchPattern":null,"preventionTips":["In custom retrieval code, always build args from a loaded workspace record and early-return on missing slugs.","Trim and reject empty queries in the handler before calling retrieval.","Reuse getLLMProvider() for the connector instead of hand-constructing one."],"tags":["chroma","vector-db","similarity-search","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}