chroma-core/chroma · error · ValueError
Invalid task: {self.task}
Error message
Invalid task: {self.task} What it means
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').
Source
Thrown at chromadb/utils/embedding_functions/fastembed_sparse_embedding_function.py:97
Embeddings for the documents.
"""
try:
from fastembed import SparseTextEmbedding
except ImportError:
raise ValueError(
"The fastembed python package is not installed. Please install it with `pip install fastembed`"
)
model = cast(SparseTextEmbedding, self._model)
if self.task == "document":
embeddings = model.embed(
list(input),
)
elif self.task == "query":
embeddings = model.query_embed(
list(input),
)
else:
raise ValueError(f"Invalid task: {self.task}")
sparse_vectors: SparseVectors = []
for vec in embeddings:
sparse_vectors.append(
normalize_sparse_vector(
indices=vec.indices.tolist(), values=vec.values.tolist()
)
)
return sparse_vectors
def embed_query(self, input: Documents) -> SparseVectors:
try:
from fastembed import SparseTextEmbedding
except ImportError:
raise ValueError(
"The fastembed python package is not installed. Please install it with `pip install fastembed`"View on GitHub (pinned to aecdd12c8a)
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.
Example fix
# before ef = FastembedSparseEmbeddingFunction(model_name='Qdrant/bm25', task='documents') ef(['hello']) # ValueError: Invalid task: documents # after ef = FastembedSparseEmbeddingFunction(model_name='Qdrant/bm25', task='document') ef(['hello']) # for query-side text: ef.embed_query(['hello'])
Defensive patterns
Strategy: validation
Validate before calling
task = 'document' if mode == 'index' else 'query'
assert task in ('document', 'query'), f'invalid task: {task}' Type guard
def is_valid_task(task) -> bool:
return task in ('document', 'query') Prevention
- 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.
When it happens
Trigger: Constructing FastembedSparseEmbeddingFunction(..., task='documents'), task='Document', task=None, or any value outside {'document', 'query'} and then calling ef(texts).
Common situations: 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).
Related errors
- The fastembed python package is not installed. Please instal
- Invalid task: {task}
- Embedding function provided when already defined in the coll
- Embedding function name not found in config: {ef_config}
- Embedding function {ef_name} not found. Add @register_embedd
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/e21d6550ca1771e8.
Report an issue: GitHub.