spring-projects/spring-ai · error · RuntimeException

Not supported expression type:

Error message

Not supported expression type: 

What it means

getOperationSymbol maps only comparison operator types (EQ, NE, LT, LTE, GT, GTE) to SQL symbols; any other ExpressionType reaching doExpression (e.g. AND/OR groups, IN operators) hits the default branch and throws a RuntimeException. The PGVector converter handles IN via convertToConditions and boolean groups elsewhere, so this indicates an expression was dispatched to the wrong handler.

Source

Thrown at vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorFilterExpressionConverter.java:112

	}

	private void handleNotIn(Expression expression, StringBuilder context) {
		context.append("!(");
		convertToConditions(expression, context);
		context.append(")");
	}

	private String getOperationSymbol(Expression exp) {
		return switch (exp.type()) {
			case AND -> " && ";
			case OR -> " || ";
			case EQ -> " == ";
			case NE -> " != ";
			case LT -> " < ";
			case LTE -> " <= ";
			case GT -> " > ";
			case GTE -> " >= ";
			default -> throw new RuntimeException("Not supported expression type: " + exp.type());
		};
	}

	@Override
	public String convertExpression(Expression expression) {
		String jsonPath = super.convertExpression(expression);
		return quoteIdentifier(this.metadataColumn) + "::jsonb @@ '" + jsonPath + "'::jsonpath";
	}

	/**
	 * Quote a SQL identifier using double quotes (PostgreSQL/SQL standard) only if
	 * needed. Simple identifiers (alphanumeric starting with letter/underscore) are
	 * returned unquoted to preserve PostgreSQL's case-insensitive behavior. Identifiers
	 * containing special characters are quoted with internal double quotes escaped by
	 * doubling.
	 */
	private static String quoteIdentifier(String identifier) {
		if (identifier.matches("^[A-Za-z_][A-Za-z0-9_]*$")) {

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Ensure only EQ/NE/LT/LTE/GT/GTE expressions reach the comparison path; route IN/NOTIN through convertToConditions and AND/OR through the group handler.
  2. Inspect exp.type() in the message and rebuild the filter with a supported operator.
  3. Upgrade spring-ai to a version where the converter supports the expression type you use.

Example fix

// before
new Expression(ExpressionType.AND, left, right) routed into doExpression comparison path
// after
new Group(new Expression(ExpressionType.AND, left, right)) so it is handled by the group branch
Defensive patterns

Strategy: type-guard

Validate before calling

Set<ExpressionType> supported = Set.of(EQ, NE, LT, LTE, GT, GTE);
if (expr instanceof Filter.Expression fe && !supported.contains(fe.type())) {
    throw new IllegalArgumentException("Unsupported type for comparison path: " + fe.type());
}

Type guard

static boolean isSimpleComparison(Expression e) {
    return e instanceof Filter.Expression fe
        && EnumSet.of(EQ, NE, LT, LTE, GT, GTE).contains(fe.type());
}

Try / catch

try {
    return converter.convertExpression(expr);
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Not supported expression type")) {
        throw new UnsupportedOperationException(e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling convertExpression on a Filter.Expression whose type is not one of EQ/NE/LT/LTE/GT/GTE — e.g. passing an IN/AND/OR node into the single-comparison code path, or a newly added enum type not yet supported by this converter.

Common situations: Custom filter-building code that mislabels expression types; using a filter DSL feature (e.g. nested groups) routed through doExpression after a library upgrade changed enum dispatch; copy-pasted converter code missing new enum cases.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/5aed7cc9935829ae. Report an issue: GitHub.