spring-projects/spring-ai · error · IllegalArgumentException
Unsupported Number type:
Error message
Unsupported Number type:
What it means
toSdkNumber converts a java.lang.Number to an AWS SDK SdkNumber for filter values. It handles BigDecimal, Integer, Long, Double, Float, Short, and Byte; any other Number subtype (e.g. BigInteger, AtomicInteger, or a custom Number) throws IllegalArgumentException.
Source
Thrown at vector-stores/spring-ai-s3-vector-store/src/main/java/org/springframework/ai/vectorstore/s3/S3VectorFilterSearchExpressionConverter.java:151
if (num instanceof Integer i) {
return SdkNumber.fromInteger(i);
}
if (num instanceof Long l) {
return SdkNumber.fromLong(l);
}
if (num instanceof Double d) {
return SdkNumber.fromDouble(d);
}
if (num instanceof Float f) {
return SdkNumber.fromFloat(f);
}
if (num instanceof Short s) {
return SdkNumber.fromShort(s);
}
if (num instanceof Byte b) {
return SdkNumber.fromInteger(b.intValue());
}
throw new IllegalArgumentException("Unsupported Number type: " + num.getClass());
}
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Convert the value to a supported type before filtering, e.g. bigInteger.longValueExact() or intValue().
- Store the metadata value as a standard long/int/double so filter comparisons use supported types.
- Normalize filter values in one place: a helper that maps any Number to Long/Double before building the SearchRequest.
- Add a BigInteger branch to toSdkNumber (SdkNumber.fromBigDecimal(BigInteger to BigDecimal)) if you maintain a fork.
Example fix
// before Filter.Value value = new Filter.Value(bigIntegerId); // after Filter.Value value = new Filter.Value(bigIntegerId.longValueExact());
Defensive patterns
Strategy: type-guard
Validate before calling
static boolean isSdkConvertible(Number n) { return n instanceof BigDecimal || n instanceof Integer || n instanceof Long || n instanceof Double || n instanceof Float || n instanceof Short || n instanceof Byte; } Type guard
static Number toSafeNumber(Number n) { return (n instanceof BigInteger b) ? b.longValueExact() : n; } Try / catch
try { store.similaritySearch(req); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Unsupported Number type")) { /* rebuild filter with normalized numbers */ } } Prevention
- Normalize all numeric filter values to int/long/double before building filters.
- Configure JSON deserializers to map integral values to Long, not BigInteger.
- Avoid AtomicInteger/AtomicLong as filter literals.
When it happens
Trigger: Using IN/NIN/EQ/GT etc. filter values that are Number instances outside the supported set — most commonly java.math.BigInteger (e.g. from JSON parsers or ID generators) or AtomicInteger — in a SearchRequest filter passed to S3VectorStore.similaritySearch.
Common situations: Parsing metadata IDs with Jackson into BigInteger; using Atomic counters as filter values; framework deserializers that produce exotic Number subtypes; metadata values typed as Number that at runtime hold BigInteger.
Related errors
- Not supported expression type:
- Unsupported operator:
- Unsupported operand type:
- Expression of type %s requires a left operand
- Expression of type %s requires a right operand
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/d9da8c3c714fdbd4.
Report an issue: GitHub.