{"record":{"id":"e21d6550ca1771e8","repo":"chroma-core/chroma","slug":"invalid-task-self-task-e21d65","errorCode":null,"errorMessage":"Invalid task: {self.task}","messagePattern":"Invalid task: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/fastembed_sparse_embedding_function.py","lineNumber":97,"sourceCode":"            Embeddings for the documents.\n        \"\"\"\n        try:\n            from fastembed import SparseTextEmbedding\n        except ImportError:\n            raise ValueError(\n                \"The fastembed python package is not installed. Please install it with `pip install fastembed`\"\n            )\n        model = cast(SparseTextEmbedding, self._model)\n        if self.task == \"document\":\n            embeddings = model.embed(\n                list(input),\n            )\n        elif self.task == \"query\":\n            embeddings = model.query_embed(\n                list(input),\n            )\n        else:\n            raise ValueError(f\"Invalid task: {self.task}\")\n\n        sparse_vectors: SparseVectors = []\n\n        for vec in embeddings:\n            sparse_vectors.append(\n                normalize_sparse_vector(\n                    indices=vec.indices.tolist(), values=vec.values.tolist()\n                )\n            )\n\n        return sparse_vectors\n\n    def embed_query(self, input: Documents) -> SparseVectors:\n        try:\n            from fastembed import SparseTextEmbedding\n        except ImportError:\n            raise ValueError(\n                \"The fastembed python package is not installed. Please install it with `pip install fastembed`\"","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/fastembed_sparse_embedding_function.py#L79-L115","documentation":"The task attribute routes __call__ to model.embed (task='document') or model.query_embed (task='query'); every other value falls through to this ValueError after the per-call fastembed import. The comparison is exact and case-sensitive - 'documents', 'Document', or None all fail (the constructor default is 'document').","triggerScenarios":"Constructing FastembedSparseEmbeddingFunction(..., task='documents'), task='Document', task=None, or any value outside {'document', 'query'} and then calling ef(texts).","commonSituations":"Typos and plurals from hand-written config; task sourced from YAML/user input without validation; assuming None selects a default (it does not at call time).","solutions":["Use task='document' when embedding corpus documents and task='query' for query-side text.","Or call ef.embed_query(texts) directly for queries instead of switching task.","If task comes from config or user input, validate it against {'document', 'query'} before constructing."],"exampleFix":"# before\nef = FastembedSparseEmbeddingFunction(model_name='Qdrant/bm25', task='documents')\nef(['hello'])  # ValueError: Invalid task: documents\n\n# after\nef = FastembedSparseEmbeddingFunction(model_name='Qdrant/bm25', task='document')\nef(['hello'])  # for query-side text: ef.embed_query(['hello'])","handlingStrategy":"validation","validationCode":"task = 'document' if mode == 'index' else 'query'\nassert task in ('document', 'query'), f'invalid task: {task}'","typeGuard":"def is_valid_task(task) -> bool:\n    return task in ('document', 'query')","tryCatchPattern":null,"preventionTips":["Use exactly 'document' or 'query' (lowercase, singular).","Prefer ef.embed_query() for queries so task switching is unnecessary.","Validate config-sourced task values against the allowed set before constructing the EF."],"tags":["chroma","fastembed","invalid-parameter","sparse-embeddings","embedding-function"],"backgroundTag":"invalid-parameter-value","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}