{"record":{"id":"3b54b053bd43021c","repo":"spring-projects/spring-ai","slug":"failed-to-ensure-neo4j-indexes-for-chat-memory","errorCode":null,"errorMessage":"Failed to ensure Neo4j indexes for chat memory: + e.getMessage()","messagePattern":"Failed to ensure Neo4j indexes for chat memory: \\+ e\\.getMessage\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"memory-repositories/spring-ai-model-chat-memory-repository-neo4j/src/main/java/org/springframework/ai/chat/memory/repository/neo4j/Neo4jChatMemoryRepositoryConfig.java","lineNumber":138,"sourceCode":"\t * Ensures that indexes exist on conversationId for Session nodes and index for\n\t * Message nodes. This improves query performance for lookups and ordering.\n\t */\n\tprivate void ensureIndexes() {\n\t\ttry (var session = this.driver.session()) {\n\t\t\t// Index for conversationId on Session nodes\n\t\t\tString sessionIndexCypher = String.format(\n\t\t\t\t\t\"CREATE INDEX session_conversation_id_index IF NOT EXISTS FOR (n:%s) ON (n.conversationId)\",\n\t\t\t\t\tthis.sessionLabel);\n\t\t\t// Index for index on Message nodes\n\t\t\tString messageIndexCypher = String\n\t\t\t\t.format(\"CREATE INDEX message_index_index IF NOT EXISTS FOR (n:%s) ON (n.index)\", this.messageLabel);\n\t\t\tsession.run(sessionIndexCypher);\n\t\t\tsession.run(messageIndexCypher);\n\t\t\tlogger.info(\"Ensured Neo4j indexes for conversationId and message index.\");\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\tlogger.warn(\"Failed to ensure Neo4j indexes for chat memory: \" + e.getMessage());\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static Builder builder() {\n\t\treturn new Builder();\n\t}\n\n\tpublic static final class Builder {\n\n\t\tprivate @Nullable Driver driver;\n\n\t\tprivate String sessionLabel = DEFAULT_SESSION_LABEL;\n\n\t\tprivate String toolCallLabel = DEFAULT_TOOL_CALL_LABEL;\n\n\t\tprivate String metadataLabel = DEFAULT_METADATA_LABEL;\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/memory-repositories/spring-ai-model-chat-memory-repository-neo4j/src/main/java/org/springframework/ai/chat/memory/repository/neo4j/Neo4jChatMemoryRepositoryConfig.java#L120-L156","documentation":"This is a warning logged by Neo4jChatMemoryRepositoryConfig.ensureIndexes() when it fails to create the conversationId and messageId indexes used for chat memory lookups. It wraps any Exception thrown while executing the index Cypher statements; the library deliberately swallows the exception (warn only) so application startup is not blocked, but indexes may be missing and queries will scan.","triggerScenarios":"Any exception from session.run(sessionIndexCypher) or session.run(messageIndexCypher) during repository init: Neo4j is unreachable, credentials wrong, the database is down/renamed, or the connected user lacks index-creation privileges.","commonSituations":"Dev environments where Neo4j isn't started yet or Docker container not up; wrong spring.neo4j.uri/password; connecting to an Aura or clustered instance with a restricted role lacking schema privileges; database name configured other than neo4j.","solutions":["Verify Neo4j connectivity and credentials (spring.neo4j.uri, authentication username/password) and confirm the database is up before app start","Check the full stack trace / underlying Neo4j exception; this log only carries e.getMessage()","Grant the connected role schema/index privileges (e.g. GRANT CREATE INDEX ON DBMS) or use an admin user","Create the indexes manually with CREATE INDEX ... IF NOT EXISTS so ensureIndexes becomes a no-op","Retry after fixing; the check runs on repository initialization"],"exampleFix":"// before\nNeo4jChatMemoryRepositoryConfig.builder().build(); // fails silently if Neo4j down\n// after\n// ensure Neo4j is reachable first\ntry (Driver driver = GraphDatabase.driver(uri, AuthTokens.basic(user, pass))) {\n    driver.verifyConnectivity();\n}\nNeo4jChatMemoryRepositoryConfig.builder().build();","handlingStrategy":"try-catch","validationCode":"try (Driver d = GraphDatabase.driver(neo4jUri, AuthTokens.basic(user, pass))) { d.verifyConnectivity(); } // also verify role: SHOW CURRENT USER PRIVILEGES includes 'CREATE INDEX'","typeGuard":"boolean neo4jReady = driver != null && session != null && session.isOpen();","tryCatchPattern":"// the library already catches; guard at startup:\ntry { repository = Neo4jChatMemoryRepositoryConfig.builder().build(); }\ncatch (Exception e) { throw new IllegalStateException(\"Neo4j chat memory index setup failed; check connectivity/privileges\", e); }","preventionTips":["Run a connectivity check (driver.verifyConnectivity()) before app startup","Use Neo4j credentials with index/schema privileges","Watch for this warning in startup logs; indexes silently missing degrade query performance","Keep index Cypher in idempotent form (IF NOT EXISTS) and run DB migrations explicitly"],"tags":["neo4j","index-creation","chat-memory","startup"],"backgroundTag":"database-query-failed","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"}