{"record":{"id":"a26a2156de17feef","repo":"chroma-core/chroma","slug":"sparse-embedding-function-returned-unexpected-numb","errorCode":null,"errorMessage":"Sparse embedding function returned unexpected number of embeddings.","messagePattern":"Sparse embedding function returned unexpected number of embeddings\\.","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/collection.ts","lineNumber":575,"sourceCode":"          if (index < documentsList.length) {\n            const doc = documentsList[index];\n            inputs.push(doc);\n            positions.push(index);\n          }\n        });\n\n        // Generate embeddings for all collected documents\n        if (inputs.length === 0) {\n          continue;\n        }\n\n        const sparseEmbeddings = await this.sparseEmbed(\n          embeddingFunction,\n          inputs,\n          false,\n        );\n        if (sparseEmbeddings.length !== positions.length) {\n          throw new ChromaValueError(\n            \"Sparse embedding function returned unexpected number of embeddings.\",\n          );\n        }\n\n        positions.forEach((position, idx) => {\n          updatedMetadatas[position][targetKey] = sparseEmbeddings[idx];\n        });\n\n        continue; // Skip the metadata-based logic below\n      }\n\n      // Handle normal case: source_key is a metadata field\n      updatedMetadatas.forEach((metadata, index) => {\n        if (targetKey in metadata) {\n          return;\n        }\n\n        const sourceValue = metadata[sourceKey];","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/collection.ts#L557-L593","documentation":"Error \"Sparse embedding function returned unexpected number of embeddings.\" thrown in chroma-core/chroma.","triggerScenarios":"Thrown at clients/new-js/packages/chromadb/src/collection.ts:575 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}