{"record":{"id":"76206d0285198465","repo":"chroma-core/chroma","slug":"keyword-argument-key-is-not-a-primitive-type","errorCode":null,"errorMessage":"Keyword argument {key} is not a primitive type","messagePattern":"Keyword argument (.+?) is not a primitive type","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/amazon_bedrock_embedding_function.py","lineNumber":39,"sourceCode":"        Args:\n            session (boto3.Session): The boto3 session to use. You need to have boto3\n                installed, `pip install boto3`. Access & secret key are not supported.\n            model_name (str, optional): Identifier of the model, defaults to \"amazon.titan-embed-text-v1\"\n            **kwargs: Additional arguments to pass to the boto3 client.\n\n        Example:\n            >>> import boto3\n            >>> session = boto3.Session(profile_name=\"profile\", region_name=\"us-east-1\")\n            >>> bedrock = AmazonBedrockEmbeddingFunction(session=session)\n            >>> texts = [\"Hello, world!\", \"How are you?\"]\n            >>> embeddings = bedrock(texts)\n        \"\"\"\n\n        self.model_name = model_name\n        # check kwargs are primitives only\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\n        # Store the session for serialization\n        self._session_args = {}\n        if hasattr(session, \"region_name\") and session.region_name:\n            self._session_args[\"region_name\"] = session.region_name\n        if hasattr(session, \"profile_name\") and session.profile_name:\n            self._session_args[\"profile_name\"] = session.profile_name\n\n        self._client = session.client(\n            service_name=\"bedrock-runtime\",\n            **kwargs,\n        )\n\n    def __call__(self, input: Documents) -> Embeddings:\n        \"\"\"\n        Generate embeddings for the given documents.\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/amazon_bedrock_embedding_function.py#L21-L57","documentation":"AmazonBedrockEmbeddingFunction persists itself via get_config(), which stores arbitrary **kwargs, so the constructor enforces that every kwarg value is a JSON-friendly primitive (str, int, float, bool, list, dict, tuple). Any non-conforming value — a boto3 Session, botocore Config, client object, or custom class instance — fails this isinstance check and raises ValueError. The dedicated session= parameter is intentionally excluded from this check because it is serialized separately into session_args.","triggerScenarios":"AmazonBedrockEmbeddingFunction(session=s, some_param=<object>) — e.g. passing a botocore.config.Config instance, a boto3 Session, or any class instance through **kwargs instead of primitives like retries={\"max_attempts\": 5} or strings/numbers.","commonSituations":"Copying boto3 client setup code into the embedding function call; trying to hand the Session through kwargs instead of the session= argument; passing typed config objects that feel natural in boto3-land but are not serializable.","solutions":["Pass the boto3 Session through the session= parameter — it is handled and serialized separately (region_name/profile_name).","Convert typed objects to plain primitives before passing: botocore Config → {\"retries\": {\"max_attempts\": 5, \"mode\": \"standard\"}}, paths as strings, options as dicts/lists.","Drop the non-serializable kwarg entirely if Bedrock does not need it."],"exampleFix":"# before: ValueError \"Keyword argument config is not a primitive type\"\nimport botocore.config\nef = AmazonBedrockEmbeddingFunction(\n    session=boto3.Session(),\n    config=botocore.config.Config(retries={\"max_attempts\": 5}),\n)\n\n# after\nimport botocore.config\nsession = boto3.Session(region_name=\"us-east-1\")\nsession.client(\"bedrock-runtime\", config=botocore.config.Config(retries={\"max_attempts\": 5}))\nef = AmazonBedrockEmbeddingFunction(session=session)  # or pass primitives-only kwargs","handlingStrategy":"type-guard","validationCode":"PRIMITIVES = (str, int, float, bool, list, dict, tuple)\n\ndef check_kwargs_primitive(kwargs: dict) -> None:\n    bad = [k for k, v in kwargs.items() if not isinstance(v, PRIMITIVES) or isinstance(v, type)]\n    if bad:\n        raise TypeError(f\"Non-primitive kwargs will be rejected: {bad}\")\n\ncheck_kwargs_primitive(bedrock_kwargs)\nef = AmazonBedrockEmbeddingFunction(session=session, **bedrock_kwargs)","typeGuard":"def is_primitive_kwarg(value: object) -> bool:\n    if isinstance(value, type):  # a class, not an instance\n        return False\n    if isinstance(value, (str, int, float, bool)):\n        return True\n    if isinstance(value, (list, tuple)):\n        return all(is_primitive_kwarg(v) for v in value)\n    if isinstance(value, dict):\n        return all(isinstance(k, str) and is_primitive_kwarg(v) for k, v in value.items())\n    return False","tryCatchPattern":"try:\n    ef = AmazonBedrockEmbeddingFunction(session=session, **kwargs)\nexcept ValueError as e:\n    if \"not a primitive type\" in str(e):\n        kwargs = {k: v for k, v in kwargs.items() if is_primitive_kwarg(v)}  # or convert objects to dicts\n        ef = AmazonBedrockEmbeddingFunction(session=session, **kwargs)\n    else:\n        raise","preventionTips":["Pass the boto3 Session only via the session= parameter; it has its own serialization path.","Convert botocore Config objects to primitive dicts before handing options to the EF.","Keep an is_primitive_kwarg helper in your codebase and run it over config dicts before persistence."],"tags":["python","aws","bedrock","serialization","type-validation","embedding-functions","chromadb"],"backgroundTag":"non-serializable-config-value","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}