{"record":{"id":"32ecee576d8428c4","repo":"chroma-core/chroma","slug":"invalid-task-task-32ecee","errorCode":null,"errorMessage":"Invalid task: {task}","messagePattern":"Invalid task: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/fastembed_sparse_embedding_function.py","lineNumber":129,"sourceCode":"        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.query_config is not None:\n            task = self.query_config.get(\"task\")\n            if task == \"document\":\n                embeddings = model.embed(\n                    list(input),\n                )\n            elif task == \"query\":\n                embeddings = model.query_embed(\n                    list(input),\n                )\n            else:\n                raise ValueError(f\"Invalid task: {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        else:\n            return self.__call__(input)\n\n    @staticmethod\n    def name() -> str:\n        return \"fastembed_sparse\"","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/fastembed_sparse_embedding_function.py#L111-L147","documentation":"Thrown by FastembedSparseEmbeddingFunction.embed_query() when query_config was provided but its 'task' value is neither 'document' nor 'query'. The function must map the task to a fastembed SparseTextEmbedding method (model.embed vs model.query_embed); an unknown value, or a missing 'task' key (dict.get returns None), cannot be mapped so the call aborts before any embedding is produced. Only the query path checks query_config; __call__() uses the separately validated self.task.","triggerScenarios":"Calling ef.embed_query(texts) on an instance built with query_config={'tasks': 'query'} (misspelled key, so task is None), query_config={'task': 'queries'}, {'task': 'QUERY'}, or any value outside the Literal['document','query'] allowed by FastembedSparseEmbeddingFunctionQueryConfig.","commonSituations":"Typos in the query_config dict key or value; config round-tripped through JSON/YAML that uppercased or renamed 'task'; copying an example config written for a different embedding function; treating the TypedDict task field as free-form text instead of the two allowed literals.","solutions":["Set query_config={'task': 'query'} (or 'document') using the exact lowercase literal and the correctly spelled 'task' key","Omit query_config entirely if you do not need asymmetric query behavior - embed_query() then falls back to __call__() driven by the constructor's task argument","Annotate the dict as FastembedSparseEmbeddingFunctionQueryConfig so a type checker rejects bad keys/values before runtime","Log repr(query_config) before calling embed_query to see the exact value that failed"],"exampleFix":"# before\nef = FastembedSparseEmbeddingFunction(\n    model_name=\"Qdrant/bm25\",\n    task=\"document\",\n    query_config={\"tasks\": \"query\"},  # misspelled key -> task=None -> Invalid task: None\n)\nef.embed_query([\"what is chroma?\"])\n\n# after\nfrom chromadb.utils.embedding_functions.fastembed_sparse_embedding_function import (\n    FastembedSparseEmbeddingFunctionQueryConfig,\n)\nquery_config: FastembedSparseEmbeddingFunctionQueryConfig = {\"task\": \"query\"}\nef = FastembedSparseEmbeddingFunction(\n    model_name=\"Qdrant/bm25\",\n    task=\"document\",\n    query_config=query_config,\n)\nef.embed_query([\"what is chroma?\"])","handlingStrategy":"validation","validationCode":"from chromadb.utils.embedding_functions import FastembedSparseEmbeddingFunction\n\nVALID_SPARSE_TASKS = {\"document\", \"query\"}\n\ndef query_config_is_valid(ef: FastembedSparseEmbeddingFunction) -> bool:\n    qc = ef.query_config\n    return qc is None or qc.get(\"task\") in VALID_SPARSE_TASKS\n\nassert query_config_is_valid(ef), (\n    f\"query_config.task must be 'document' or 'query', got {ef.query_config!r}\"\n)","typeGuard":"from typing import TypeGuard\nfrom chromadb.utils.embedding_functions.fastembed_sparse_embedding_function import (\n    FastembedSparseEmbeddingFunctionQueryConfig,\n)\n\ndef is_valid_query_config(\n    cfg: object,\n) -> TypeGuard[FastembedSparseEmbeddingFunctionQueryConfig]:\n    return (\n        isinstance(cfg, dict)\n        and set(cfg) == {\"task\"}\n        and cfg[\"task\"] in (\"document\", \"query\")\n    )","tryCatchPattern":null,"preventionTips":["Always build query_config with the FastembedSparseEmbeddingFunctionQueryConfig TypedDict annotation so type checkers catch bad keys/values","Use only the lowercase literals 'document' and 'query'","Unit-test the config dict round-trip (JSON serialize/deserialize) before passing it to the constructor"],"tags":["fastembed","sparse-embeddings","chroma","query-config","invalid-parameter"],"backgroundTag":"invalid-config-value","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}