{"record":{"id":"8dace0a15719c50a","repo":"chroma-core/chroma","slug":"invalid-task-task","errorCode":null,"errorMessage":"Invalid task: {task}","messagePattern":"Invalid task: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/bm25_embedding_function.py","lineNumber":151,"sourceCode":"        try:\n            from fastembed.sparse.bm25 import Bm25\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(Bm25, 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 \"bm25\"","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/bm25_embedding_function.py#L133-L169","documentation":"When query_config is provided, embed_query ignores self.task and dispatches on query_config[\"task\"], again accepting only \"document\" or \"query\". Any other value raises this ValueError — including None, which is what you get when the dict simply lacks the \"task\" key, since it is read with .get(). So passing an empty query_config={} fails with \"Invalid task: None\" rather than falling back to a default.","triggerScenarios":"Bm25EmbeddingFunction(task=\"query\", query_config={\"task\": \"passage\"}) then embed_query(...); or query_config={} / {\"k\": 1.5} without a \"task\" key — .get(\"task\") returns None and the error reads \"Invalid task: None\".","commonSituations":"Porting sentence-transformers query configs that use \"passage\"; storing extra BM25 parameters (k, b) in query_config and forgetting the required task key; assuming query_config={} means \"use self.task\".","solutions":["Include a valid task: query_config={\"task\": \"query\"} (or \"document\").","If you do not need per-query overrides, pass query_config=None — embed_query then reuses self.task.","Validate query_config at construction: task must be present and one of the two literals."],"exampleFix":"# before: ValueError \"Invalid task: passage\" (or \"Invalid task: None\" for missing key)\nef = Bm25EmbeddingFunction(task=\"query\", query_config={\"task\": \"passage\"})\nqv = ef.embed_query([\"search term\"])\n\n# after\nef = Bm25EmbeddingFunction(task=\"query\", query_config={\"task\": \"query\"})\nqv = ef.embed_query([\"search term\"])","handlingStrategy":"validation","validationCode":"VALID_TASKS = {\"document\", \"query\"}\n\ndef make_query_config(query_config: dict | None) -> dict | None:\n    if query_config is None:\n        return None\n    task = query_config.get(\"task\")\n    if task not in VALID_TASKS:\n        raise ValueError(f\"query_config['task'] must be one of {sorted(VALID_TASKS)}, got {task!r}\")\n    return query_config\n\nef = Bm25EmbeddingFunction(task=\"query\", query_config=make_query_config(raw_qcfg))","typeGuard":"def is_valid_query_config(qcfg: object) -> bool:\n    return (\n        qcfg is None\n        or (isinstance(qcfg, dict) and qcfg.get(\"task\") in (\"document\", \"query\"))\n    )","tryCatchPattern":"try:\n    qv = ef.embed_query(queries)\nexcept ValueError as e:\n    if \"Invalid task\" in str(e):\n        ef.query_config = {**ef.query_config, \"task\": \"query\"}  # repair or re-construct with a valid task\n        qv = ef.embed_query(queries)\n    else:\n        raise","preventionTips":["Remember query_config={} fails with 'Invalid task: None' — always include the 'task' key.","Pass query_config=None when you want embed_query to reuse self.task.","Translate 'passage' → 'document' when porting query configs from other retrieval stacks."],"tags":["python","bm25","sparse-embedding","enum-validation","query-config","chromadb"],"backgroundTag":"invalid-enum-value","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}