chroma-core/chroma · error · ValueError
Keyword argument {key} is not a primitive type
Error message
Keyword argument {key} is not a primitive type What it means
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.
Source
Thrown at chromadb/utils/embedding_functions/amazon_bedrock_embedding_function.py:39
Args:
session (boto3.Session): The boto3 session to use. You need to have boto3
installed, `pip install boto3`. Access & secret key are not supported.
model_name (str, optional): Identifier of the model, defaults to "amazon.titan-embed-text-v1"
**kwargs: Additional arguments to pass to the boto3 client.
Example:
>>> import boto3
>>> session = boto3.Session(profile_name="profile", region_name="us-east-1")
>>> bedrock = AmazonBedrockEmbeddingFunction(session=session)
>>> texts = ["Hello, world!", "How are you?"]
>>> embeddings = bedrock(texts)
"""
self.model_name = model_name
# check kwargs are primitives only
for key, value in kwargs.items():
if not isinstance(value, (str, int, float, bool, list, dict, tuple)):
raise ValueError(f"Keyword argument {key} is not a primitive type")
self.kwargs = kwargs
# Store the session for serialization
self._session_args = {}
if hasattr(session, "region_name") and session.region_name:
self._session_args["region_name"] = session.region_name
if hasattr(session, "profile_name") and session.profile_name:
self._session_args["profile_name"] = session.profile_name
self._client = session.client(
service_name="bedrock-runtime",
**kwargs,
)
def __call__(self, input: Documents) -> Embeddings:
"""
Generate embeddings for the given documents.
View on GitHub (pinned to aecdd12c8a)
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.
Example fix
# before: ValueError "Keyword argument config is not a primitive type"
import botocore.config
ef = AmazonBedrockEmbeddingFunction(
session=boto3.Session(),
config=botocore.config.Config(retries={"max_attempts": 5}),
)
# after
import botocore.config
session = boto3.Session(region_name="us-east-1")
session.client("bedrock-runtime", config=botocore.config.Config(retries={"max_attempts": 5}))
ef = AmazonBedrockEmbeddingFunction(session=session) # or pass primitives-only kwargs Defensive patterns
Strategy: type-guard
Validate before calling
PRIMITIVES = (str, int, float, bool, list, dict, tuple)
def check_kwargs_primitive(kwargs: dict) -> None:
bad = [k for k, v in kwargs.items() if not isinstance(v, PRIMITIVES) or isinstance(v, type)]
if bad:
raise TypeError(f"Non-primitive kwargs will be rejected: {bad}")
check_kwargs_primitive(bedrock_kwargs)
ef = AmazonBedrockEmbeddingFunction(session=session, **bedrock_kwargs) Type guard
def is_primitive_kwarg(value: object) -> bool:
if isinstance(value, type): # a class, not an instance
return False
if isinstance(value, (str, int, float, bool)):
return True
if isinstance(value, (list, tuple)):
return all(is_primitive_kwarg(v) for v in value)
if isinstance(value, dict):
return all(isinstance(k, str) and is_primitive_kwarg(v) for k, v in value.items())
return False Try / catch
try:
ef = AmazonBedrockEmbeddingFunction(session=session, **kwargs)
except ValueError as e:
if "not a primitive type" in str(e):
kwargs = {k: v for k, v in kwargs.items() if is_primitive_kwarg(v)} # or convert objects to dicts
ef = AmazonBedrockEmbeddingFunction(session=session, **kwargs)
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The model name cannot be changed after the embedding functio
- The boto3 python package is not installed. Please install it
- Keyword argument {key} is not a primitive type
- Failed to register embedding function: {e}
- Failed to register sparse embedding function: {e}
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/76206d0285198465.
Report an issue: GitHub.