{"record":{"id":"bec4c09e61206fd7","repo":"Mintplex-Labs/anything-llm","slug":"error-embedding-into-chromadb-error-message","errorCode":null,"errorMessage":"Error embedding into ChromaDB: ${error.message}","messagePattern":"Error embedding into ChromaDB: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/vectorDbProviders/chroma/index.js","lineNumber":337,"sourceCode":"      const { client } = await this.connect();\n      const collection = await client.getOrCreateCollection({\n        name: this.normalize(namespace),\n        metadata: { \"hnsw:space\": \"cosine\" },\n      });\n\n      if (vectors.length > 0) {\n        const chunks = [];\n        this.logger(\"Inserting vectorized chunks into Chroma collection.\");\n        for (const chunk of toChunks(vectors, 500)) chunks.push(chunk);\n\n        try {\n          await this.smartAdd(collection, submission);\n          this.logger(\n            `Successfully added ${submission.ids.length} vectors to collection ${this.normalize(namespace)}`\n          );\n        } catch (error) {\n          this.logger(\"Error adding to ChromaDB:\", error);\n          throw new Error(`Error embedding into ChromaDB: ${error.message}`);\n        }\n\n        await storeVectorResult(chunks, fullFilePath);\n      }\n\n      await DocumentVectors.bulkInsert(documentVectors);\n      return { vectorized: true, error: null };\n    } catch (e) {\n      this.logger(\"addDocumentToNamespace\", e.message);\n      return { vectorized: false, error: e.message };\n    }\n  }\n\n  async deleteDocumentFromNamespace(namespace, docId) {\n    const { DocumentVectors } = require(\"../../../models/vectors\");\n    const { client } = await this.connect();\n    if (!(await this.namespaceExists(client, namespace))) return;\n    const collection = await client.getCollection({","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/vectorDbProviders/chroma/index.js#L319-L355","documentation":"Thrown by ChromaVectorDb.addDocumentToNamespace when smartAdd(collection, submission) rejects during the actual upsert; the original SDK error message is wrapped as 'Error embedding into ChromaDB: <message>'. The outer catch converts it to { vectorized: false, error } so the API does not crash, but the document is not stored.","triggerScenarios":"Upsert failures such as embedding-dimension mismatch between existing collection and new vectors, invalid metadata types (Chroma rejects nested/None-scalar values), batch rejected due to size limits, or connection reset mid-write.","commonSituations":"Switching EMBEDDING_ENGINE after the workspace collection was created (dimension conflict); Chroma upgraded with stricter metadata validation; network blips to a remote Chroma; sending metadata containing null or nested objects.","solutions":["Read the wrapped message - it carries the underlying Chroma error; dimension mismatches usually say 'Expected X-dimensional vector, got Y'.","If dimensions conflict, delete the workspace's collection (or the whole namespace) so it is recreated with the current embedder's dimension.","Sanitize metadata to scalar values (string/number/bool) before embedding documents.","For transient network errors, re-run the embed; vector-cache makes retries cheap."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const r = await vectorDb.addDocumentToNamespace(namespace, buffer, filePath, metadata);\nif (!r.vectorized) {\n  if (/dimension/i.test(r.error)) {\n    await vectorDb['delete-namespace']({ namespace }); // recreate with current dimension\n    return vectorDb.addDocumentToNamespace(namespace, buffer, filePath, metadata);\n  }\n  if (/ECONNRESET|fetch failed/i.test(r.error)) return retryLater(); // transient\n  throw new Error(r.error);\n}","preventionTips":["Never switch EMBEDDING_ENGINE mid-workspace without resetting the namespace collection.","Keep metadata flat (string/number/bool) - Chroma rejects nested/null values.","Read the wrapped message first; it names the real cause (dimension, metadata, quota, network)."],"tags":["chroma","vector-db","upsert","dimension-mismatch","metadata"],"backgroundTag":"vector-upsert-failed","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}