{"record":{"id":"dad6e80a0af90b17","repo":"apache/cassandra","slug":"vectorsbykey-is-not-initialized","errorCode":null,"errorMessage":"vectorsByKey is not initialized","messagePattern":"vectorsByKey is not initialized","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/index/sai/disk/v1/vector/OnHeapGraph.java","lineNumber":286,"sourceCode":"        {\n            for (int i = 0; i < vector.length; i++)\n            {\n                if (vector[i] != 0)\n                    return;\n            }\n            throw new InvalidRequestException(\"Zero vectors cannot be indexed or queried with cosine similarity\");\n        }\n    }\n\n    public Collection<T> keysFromOrdinal(int node)\n    {\n        return postingsByOrdinal.get(node).getPostings();\n    }\n\n    public float[] vectorForKey(T key)\n    {\n        if (vectorsByKey == null)\n            throw new IllegalStateException(\"vectorsByKey is not initialized\");\n        return vectorsByKey.get(key);\n    }\n\n    public long remove(ByteBuffer term, T key)\n    {\n        assert term != null && term.remaining() != 0;\n\n        float[] vector = vectorType.composeAsFloat(term);\n        VectorPostings<T> postings = postingsMap.get(vector);\n        if (postings == null)\n        {\n            // it's possible for this to be called against a different memtable than the one\n            // the value was originally added to, in which case we do not expect to find\n            // the key among the postings for this vector\n            return 0;\n        }\n\n        hasDeletions = true;","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/sai/disk/v1/vector/OnHeapGraph.java#L268-L304","documentation":"OnHeapGraph.vectorForKey looks up a vector by key in a lazily-built map (vectorsByKey). If the map was never initialized (the structure was built in postings-only mode or not yet built), the method throws IllegalStateException instead of returning null. This is an internal lifecycle guard, not a data problem.","triggerScenarios":"Calling vectorForKey before the graph's vectors map has been built/initialized — typically during a search that requests source vectors when the on-heap graph was constructed without them.","commonSituations":"Querying vector data while the index is mid-build or after a partial/failed index build; internal bug where search path accesses vectors on a postings-only graph; upgrades where per-sstable vector components are missing.","solutions":["Ensure the vector index is fully built before querying (check index build status)","Rebuild the SAI vector index (DROP and re-CREATE the index) if it was created by an older/partial build","If seen in a recent query path, file/upgrade — this usually indicates an internal state bug"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// check index build status before querying:\n// SELECT * FROM system_views.sstable_indexes WHERE index_name = '...'; // ensure built","typeGuard":null,"tryCatchPattern":"try {\n    float[] v = graph.vectorForKey(key);\n} catch (IllegalStateException e) {\n    // index not fully built; fall back to full scan or rebuild index\n}","preventionTips":["Only query vector indexes after build completion","Rebuild indexes after failed builds or version upgrades","Monitor index build progress before serving ANN queries"],"tags":["vector-search","sai","illegal-state","internal"],"backgroundTag":"internal-invariant-violation","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"}