{"record":{"id":"821b032d92268152","repo":"chroma-core/chroma","slug":"keyword-argument-key-is-not-a-primitive-type-821b03","errorCode":null,"errorMessage":"Keyword argument {key} is not a primitive type","messagePattern":"Keyword argument (.+?) is not a primitive type","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/fastembed_sparse_embedding_function.py","lineNumber":66,"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\n        self.task = task\n        self.query_config = query_config\n        self.model_name = model_name\n        self.cache_dir = cache_dir\n        self.threads = threads\n        self.cuda = cuda\n        self.device_ids = device_ids\n        self.lazy_load = lazy_load\n        validate_embedding_function_kwargs_are_safe(kwargs)\n        for key, value in kwargs.items():\n            if not isinstance(value, (str, int, float, bool, list, dict, tuple)):\n                raise ValueError(f\"Keyword argument {key} is not a primitive type\")\n        self.kwargs = kwargs\n        self._model = SparseTextEmbedding(\n            model_name, cache_dir, threads, cuda, device_ids, lazy_load, **kwargs\n        )\n\n    def __call__(self, input: Documents) -> SparseVectors:\n        \"\"\"Generate embeddings for the given documents.\n\n        Args:\n            input: Documents to generate embeddings for.\n\n        Returns:\n            Embeddings for the documents.\n        \"\"\"\n        try:\n            from fastembed import SparseTextEmbedding\n        except ImportError:\n            raise ValueError(","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/fastembed_sparse_embedding_function.py#L48-L84","documentation":"The kwargs are validated to be JSON-friendly primitives (str, int, float, bool, list, dict, tuple) because they are persisted in the function's config and must round-trip through serialization. Any non-primitive value - None, model objects, callables, numpy scalars - is rejected by key name before SparseTextEmbedding is constructed. Note that None is not in the allowed set, so optional kwargs cannot be nulled out, only omitted.","triggerScenarios":"Passing kwargs like {'cache_dir': None}, {'threads': None}, a custom object, or a lambda to FastembedSparseEmbeddingFunction; the message names the offending key.","commonSituations":"Building kwargs programmatically from YAML/env config where absent values default to None; forwarding **options dicts that include callables; copy-pasting fastembed examples that pass objects.","solutions":["Omit optional kwargs entirely instead of passing None.","Pass only serializable values; keep objects and callables out of anything that goes into EF config.","Filter kwargs before construction: {k: v for k, v in kwargs.items() if v is not None}."],"exampleFix":"# before\nef = FastembedSparseEmbeddingFunction(model_name='Qdrant/bm25', cache_dir=None, threads=None)\n# ValueError: Keyword argument cache_dir is not a primitive type\n\n# after\nclean = {k: v for k, v in kwargs.items() if v is not None}\nef = FastembedSparseEmbeddingFunction(model_name='Qdrant/bm25', **clean)","handlingStrategy":"validation","validationCode":"PRIMITIVES = (str, int, float, bool, list, dict, tuple)\nclean = {k: v for k, v in kwargs.items()\n         if v is not None and isinstance(v, PRIMITIVES)}","typeGuard":"PRIMITIVES = (str, int, float, bool, list, dict, tuple)\n\ndef kwargs_are_primitive(kwargs: dict) -> bool:\n    return all(isinstance(v, PRIMITIVES) for v in kwargs.values())","tryCatchPattern":null,"preventionTips":["Omit optional kwargs instead of passing None.","Keep callables and objects out of EF kwargs - configs must serialize to JSON.","Filter config-derived kwargs for None and non-primitives before construction."],"tags":["chroma","fastembed","kwargs","serialization","input-validation"],"backgroundTag":"config-validation-failed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}