{"record":{"id":"54d3be8cc4d615c5","repo":"spring-projects/spring-ai","slug":"index-s-does-not-exist-in-table-s","errorCode":null,"errorMessage":"Index %s does not exist in table %s","messagePattern":"Index (.+?) does not exist in table (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java","lineNumber":397,"sourceCode":"\t\t\t\t.metadata(docFields)\n\t\t\t\t.score((double) score)\n\t\t\t\t.build();\n\n\t\t\tdocuments.add(doc);\n\t\t}\n\t\treturn documents;\n\t}\n\n\tvoid checkSchemaValid() {\n\t\tthis.checkSchemaValid(this.embeddingModel.dimensions());\n\t}\n\n\tprivate Similarity getIndexSimilarity(TableMetadata metadata) {\n\n\t\tOptional<IndexMetadata> indexMetadata = metadata.getIndex(this.schema.index());\n\n\t\tif (indexMetadata.isEmpty()) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\tString.format(\"Index %s does not exist in table %s\", this.schema.index(), this.schema.table));\n\t\t}\n\n\t\treturn Similarity.valueOf(indexMetadata.get()\n\t\t\t.getOptions()\n\t\t\t.getOrDefault(\"similarity_function\", \"COSINE\")\n\t\t\t.toUpperCase(Locale.ROOT));\n\n\t}\n\n\tprivate PreparedStatement prepareDeleteStatement() {\n\t\tDelete stmt = null;\n\t\tDeleteSelection stmtStart = QueryBuilder.deleteFrom(this.schema.keyspace(), this.schema.table());\n\n\t\tfor (var c : this.schema.partitionKeys()) {\n\t\t\tstmt = (null != stmt ? stmt : stmtStart).whereColumn(c.name()).isEqualTo(QueryBuilder.bindMarker(c.name()));\n\t\t}\n\t\tAssert.state(stmt != null, \"stmt should not be null by now\");","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java#L379-L415","documentation":"During initialization CassandraVectorStore reads the table metadata to determine the index similarity function (cosine/euclidean/inner_product). If the configured schema index name is not found on the table it throws IllegalStateException. The store requires a pre-existing SAI index on the vector column unless it created the schema itself.","triggerScenarios":"Constructing CassandraVectorStore with a schema whose index() name does not exist on the configured table — typo in index name, index created on a different table, or initializeSchema=false while the index was never created manually.","commonSituations":"Deploying against an existing Cassandra keyspace where a DBA created the SAI index with a different name; switching tables but reusing an old schema config; forgetting CREATE CUSTOM INDEX ... USING 'StorageAttachedIndex' before starting the app.","solutions":["Verify the index name in your CassandraVectorStore schema config matches an actual SAI index: run DESC TABLE / SELECT from system_schema.indexes.","Create the index manually if initializeSchema is false: CREATE CUSTOM INDEX IF NOT EXISTS <name> ON <ks>.<tbl>(<vector_col>) USING 'StorageAttachedIndex' WITH OPTIONS = {'similarity_function': 'COSINE'}.","Set initializeSchema=true to let the store create the table and index itself.","Align schema.table with the table that actually carries the index."],"exampleFix":"// before\nCassandraVectorStoreConfig.builder().keyspace(\"ai\").table(\"vectors\").index(\"vector_idx_wrong\")...\n// after (match the real SAI index name)\nCREATE CUSTOM INDEX IF NOT EXISTS vector_idx ON ai.vectors(content_vector) USING 'StorageAttachedIndex';\nCassandraVectorStoreConfig.builder().keyspace(\"ai\").table(\"vectors\").index(\"vector_idx\")...","handlingStrategy":"validation","validationCode":"Optional<IndexMetadata> idx = session.getMetadata()\n    .getKeyspace(schema.keyspace()).flatMap(k -> k.getTable(schema.table()))\n    .flatMap(t -> t.getIndex(schema.index()));\nif (idx.isEmpty()) throw new IllegalStateException(\"SAI index missing: \" + schema.index());","typeGuard":"boolean indexExists(CqlSession s, String ks, String tbl, String idxName) {\n  return s.getMetadata().getKeyspace(ks).flatMap(k -> k.getTable(tbl))\n          .map(t -> t.getIndex(idxName).isPresent()).orElse(false);\n}","tryCatchPattern":"try {\n  new CassandraVectorStore.Builder(session, embeddingModel)\n      .schemaColumnFilters(\"vectors\", \"vector_idx\").build();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"does not exist\")) createSaiIndex();\n}","preventionTips":["Create the SAI index with the exact configured name before starting the app.","Keep index/table names in one config source shared with your schema migration scripts.","Run DESC TABLE in the target environment to verify names when deploying to a new keyspace."],"tags":["cassandra","index","resource-not-found","vector-store","initialization"],"backgroundTag":"resource-not-found","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}