{"record":{"id":"0ee75328bfb0f14a","repo":"apache/cassandra","slug":"cannot-specify-more-than-one-ann-ordering","errorCode":null,"errorMessage":"Cannot specify more than one ANN ordering","messagePattern":"Cannot specify more than one ANN ordering","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java","lineNumber":549,"sourceCode":"    public boolean usesSecondaryIndexing()\n    {\n        return this.usesSecondaryIndexing;\n    }\n\n    /**\n     * This is a hack to push ordering down to indexes.\n     * Indexes are selected based on RowFilter only, so we need to turn orderings into restrictions\n     * so they end up in the row filter.\n     *\n     * @param orderings orderings from the select statement\n     * @return the {@link RestrictionSet} with the added orderings\n     */\n    private RestrictionSet addOrderingRestrictions(List<Ordering> orderings, RestrictionSet restrictionSet)\n    {\n        List<Ordering> annOrderings = orderings.stream().filter(o -> o.expression.hasNonClusteredOrdering()).collect(Collectors.toList());\n\n        if (annOrderings.size() > 1)\n            throw new InvalidRequestException(\"Cannot specify more than one ANN ordering\");\n        else if (annOrderings.size() == 1)\n        {\n            if (orderings.size() > 1)\n                throw new InvalidRequestException(\"ANN ordering does not support any other ordering\");\n            Ordering annOrdering = annOrderings.get(0);\n            if (annOrdering.direction != Ordering.Direction.ASC)\n                throw new InvalidRequestException(\"Descending ANN ordering is not supported\");\n            SingleRestriction restriction = annOrdering.expression.toRestriction();\n            return restrictionSet.addRestriction(restriction);\n        }\n        return restrictionSet;\n    }\n\n    private void processPartitionKeyRestrictions(ClientState state, boolean hasQueriableIndex, boolean allowFiltering, boolean forView)\n    {\n        if (!type.allowPartitionKeyRanges())\n        {\n            checkFalse(partitionKeyRestrictions.isOnToken(),","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java#L531-L567","documentation":"ANN (approximate nearest neighbor) vector similarity ordering is restricted to a single ORDER BY clause: at most one ANN ordering may appear per query. addOrderingRestrictions rejects queries with more than one vector-similarity ordering expression.","triggerScenarios":"A SELECT ... ORDER BY ann_of(v) : [0.1,0.2], ... with two or more ANN ordering expressions on vector columns in one statement.","commonSituations":"Attempting multi-vector similarity search (e.g. order by similarity to two different query vectors) directly in one CQL query on a vector-enabled (SAI/vector search) table.","solutions":["Keep only one ANN ordering clause in the ORDER BY.","Run separate queries per vector and merge/rank the results client-side.","Combine vectors into a single embedding if a joint similarity is really intended."],"exampleFix":"// before\nSELECT * FROM items ORDER BY ann_of(vec1) : [0.1,0.2], ann_of(vec2) : [0.3,0.4];\n// after\nSELECT * FROM items ORDER BY ann_of(vec1) : [0.1,0.2]; // run a second query for vec2","handlingStrategy":"validation","validationCode":"long annCount = orderings.stream().filter(o -> o.hasNonClusteredOrdering()).count();\nif (annCount > 1) throw new IllegalArgumentException(\"only one ANN ordering allowed\");","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); }\ncatch (InvalidRequestException e) {\n    if (e.getMessage().equals(\"Cannot specify more than one ANN ordering\")) { /* split into multiple queries */ }\n    else throw e;\n}","preventionTips":["Document that vector search supports one ANN ordering per query.","Do multi-vector ranking in application code.","Validate ORDER BY construction helpers to emit at most one ANN term."],"tags":["cassandra","cql","ann","vector-search","ordering"],"backgroundTag":"conflicting-config-options","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}