{"record":{"id":"ff548902a7ae1381","repo":"apache/cassandra","slug":"top-k-queries-can-only-be-run-with-consistency-lev","errorCode":null,"errorMessage":"Top-K queries can only be run with consistency level ONE / LOCAL_ONE / NODE_LOCAL. Consistency level %s was requested. Downgrading the consistency level to %s.","messagePattern":"Top-K queries can only be run with consistency level ONE / LOCAL_ONE / NODE_LOCAL\\. Consistency level (.+?) was requested\\. Downgrading the consistency level to (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/cql3/statements/SelectStatement.java","lineNumber":405,"sourceCode":"\n        // Handle additional validation for topK queries\n        if (restrictions.isTopK())\n        {\n            checkFalse(aggregationSpec != null, TOPK_AGGREGATION_ERROR);\n\n            // We aren't going to allow SERIAL at all, so we can error out on those.\n            checkFalse(options.getConsistency() == ConsistencyLevel.LOCAL_SERIAL ||\n                       options.getConsistency() == ConsistencyLevel.SERIAL,\n                       String.format(TOPK_CONSISTENCY_LEVEL_ERROR, options.getConsistency()));\n\n            if (options.getConsistency().needsReconciliation())\n            {\n                ConsistencyLevel supplied = options.getConsistency();\n                ConsistencyLevel downgrade = supplied.isDatacenterLocal() ? ConsistencyLevel.LOCAL_ONE : ConsistencyLevel.ONE;\n\n                options = QueryOptions.withConsistencyLevel(options, downgrade);\n\n                ClientWarn.instance.warn(String.format(TOPK_CONSISTENCY_LEVEL_WARNING, supplied, downgrade));\n            }\n\n            checkFalse(limit.isUnlimited(), TOPK_LIMIT_ERROR);\n\n            checkFalse(limit.perPartitionCount() != DataLimits.NO_LIMIT, TOPK_PARTITION_LIMIT_ERROR);\n\n            if (pageSize > 0 && pageSize < limit.count())\n            {\n                int oldPageSize = pageSize;\n                pageSize = limit.count();\n                limit = getDataLimits(userLimit, userPerPartitionLimit, pageSize, aggregationSpec);\n                options = QueryOptions.withPageSize(options, pageSize);\n                ClientWarn.instance.warn(String.format(TOPK_PAGE_SIZE_WARNING, oldPageSize, limit.count(), pageSize));\n            }\n        }\n\n        ReadQuery query = getQuery(options, state.getClientState(), selectors.getColumnFilter(), nowInSec, limit, PotentialTxnConflicts.DISALLOW);\n","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java#L387-L423","documentation":"Top-K (vector ANN) queries only support consistency levels ONE / LOCAL_ONE / NODE_LOCAL. When a higher consistency level is requested, SelectStatement.execute silently downgrades it to LOCAL_ONE (if the requested level was datacenter-local) or ONE and warns the client.","triggerScenarios":"Executing an ANN/Top-K SELECT (ORDER BY ... ANN OF vector) with consistency level QUORUM, LOCAL_QUORUM, THREE, EACH_QUORUM, ALL, etc.; the coordinator rewrites QueryOptions and warns via ClientWarn.","commonSituations":"Application sets a driver default consistency level of QUORUM/LOCAL_QUORUM and issues vector searches; code shared between normal reads and ANN reads; porting queries from non-vector workloads.","solutions":["Set consistency level ONE or LOCAL_ONE explicitly on ANN queries (e.g. driver withDefaultConsistencyLevel or per-query setConsistencyLevel)","Use LOCAL_ONE for cross-DC deployments to keep reads local","Separate ANN queries into a dedicated session/profile with the correct consistency profile"],"exampleFix":"// before\nSimpleStatement q = SimpleStatement.builder(\"SELECT ... ORDER BY embedding ANN OF [0.1,0.2] LIMIT 5\").build(); // default QUORUM\n// after\nSimpleStatement q = SimpleStatement.builder(\"SELECT ... ORDER BY embedding ANN OF [0.1,0.2] LIMIT 5\")\n    .setConsistencyLevel(ConsistencyLevel.LOCAL_ONE).build();","handlingStrategy":"validation","validationCode":"if (isAnnQuery && cl != ConsistencyLevel.ONE && cl != ConsistencyLevel.LOCAL_ONE) {\n    throw new IllegalArgumentException(\"ANN query requires ONE/LOCAL_ONE, got \" + cl);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Dedicated driver execution profile for vector queries with LOCAL_ONE","Never rely on global default consistency for ANN queries","Log client warnings (driver setWarningHandler) to catch silent downgrades"],"tags":["cassandra","consistency-level","vector-search","client-warning"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}