Skip to content

Commit f7f0032

Browse files
sobychackomarkpollack
authored andcommitted
Migrate Cassandra chat memory implementation to its own module
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
1 parent d45ff8e commit f7f0032

File tree

14 files changed

+185
-12
lines changed

14 files changed

+185
-12
lines changed

auto-configurations/models/chat/memory/spring-ai-autoconfigure-model-chat-memory-cassandra/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<dependency>
3434
<groupId>org.springframework.ai</groupId>
35-
<artifactId>spring-ai-cassandra-store</artifactId>
35+
<artifactId>spring-ai-model-chat-memory-cassandra</artifactId>
3636
<version>${project.parent.version}</version>
3737
</dependency>
3838

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.springframework.ai</groupId>
24+
<artifactId>spring-ai</artifactId>
25+
<version>1.0.0-SNAPSHOT</version>
26+
<relativePath>../../pom.xml</relativePath>
27+
</parent>
28+
29+
<artifactId>spring-ai-model-chat-memory-cassandra</artifactId>
30+
<name>Spring AI Cassandra Chat Memory</name>
31+
<description>Spring AI Cassandra Chat Memory implementation</description>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.springframework.ai</groupId>
36+
<artifactId>spring-ai-client-chat</artifactId>
37+
<version>${project.version}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.apache.cassandra</groupId>
42+
<artifactId>java-driver-query-builder</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.springframework.ai</groupId>
53+
<artifactId>spring-ai-test</artifactId>
54+
<version>${project.version}</version>
55+
<scope>test</scope>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-testcontainers</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.testcontainers</groupId>
66+
<artifactId>cassandra</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>org.testcontainers</groupId>
72+
<artifactId>junit-jupiter</artifactId>
73+
<scope>test</scope>
74+
</dependency>
75+
76+
</dependencies>
77+
78+
</project>
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import org.slf4j.Logger;
4444
import org.slf4j.LoggerFactory;
4545

46-
import org.springframework.ai.cassandra.SchemaUtil;
47-
4846
/**
4947
* Configuration for the Cassandra Chat Memory store.
5048
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2025-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.chat.memory.cassandra;
18+
19+
import java.time.Duration;
20+
21+
import com.datastax.oss.driver.api.core.CqlSession;
22+
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
23+
import com.datastax.oss.driver.api.querybuilder.SchemaBuilder;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
/**
28+
* Utility class for working with Cassandra schema.
29+
*
30+
* @author Mick Semb Wever
31+
* @since 1.0.0
32+
*/
33+
public final class SchemaUtil {
34+
35+
private static final Logger logger = LoggerFactory.getLogger(SchemaUtil.class);
36+
37+
private SchemaUtil() {
38+
39+
}
40+
41+
public static void checkSchemaAgreement(CqlSession session) throws IllegalStateException {
42+
if (!session.checkSchemaAgreement()) {
43+
logger.warn("Waiting for cluster schema agreement, sleeping 10s…");
44+
try {
45+
Thread.sleep(Duration.ofSeconds(10).toMillis());
46+
}
47+
catch (InterruptedException ex) {
48+
Thread.currentThread().interrupt();
49+
throw new IllegalStateException(ex);
50+
}
51+
if (!session.checkSchemaAgreement()) {
52+
logger.error("no cluster schema agreement still, continuing, let's hope this works…");
53+
}
54+
}
55+
}
56+
57+
public static void ensureKeyspaceExists(CqlSession session, String keyspaceName) {
58+
if (session.getMetadata().getKeyspace(keyspaceName).isEmpty()) {
59+
SimpleStatement keyspaceStmt = SchemaBuilder.createKeyspace(keyspaceName)
60+
.ifNotExists()
61+
.withSimpleStrategy(1)
62+
.build();
63+
64+
logger.debug("Executing {}", keyspaceStmt.getQuery());
65+
session.execute(keyspaceStmt);
66+
}
67+
}
68+
69+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.testcontainers.junit.jupiter.Container;
2727
import org.testcontainers.junit.jupiter.Testcontainers;
2828

29-
import org.springframework.ai.cassandra.CassandraImage;
3029
import org.springframework.boot.SpringBootConfiguration;
3130
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3231
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

vector-stores/spring-ai-cassandra-store/src/test/java/org/springframework/ai/cassandra/CassandraImage.java renamed to memory/spring-ai-model-chat-memory-cassandra/src/test/java/org/springframework/ai/chat/memory/cassandra/CassandraImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.cassandra;
17+
package org.springframework.ai.chat.memory.cassandra;
1818

1919
import org.testcontainers.utility.DockerImageName;
2020

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<module>spring-ai-rag</module>
4141
<module>advisors/spring-ai-advisors-vector-store</module>
4242

43+
<module>memory/spring-ai-model-chat-memory-neo4j</module>
44+
<module>memory/spring-ai-model-chat-memory-cassandra</module>
45+
4346
<module>auto-configurations/common/spring-ai-autoconfigure-retry</module>
4447

4548
<module>auto-configurations/models/tool/spring-ai-autoconfigure-model-tool</module>
@@ -49,8 +52,6 @@
4952
<module>auto-configurations/models/chat/memory/spring-ai-autoconfigure-model-chat-memory-cassandra</module>
5053
<module>auto-configurations/models/chat/memory/spring-ai-autoconfigure-model-chat-memory-neo4j</module>
5154

52-
<module>memory/spring-ai-model-chat-memory-neo4j</module>
53-
5455
<module>auto-configurations/models/chat/observation/spring-ai-autoconfigure-model-chat-observation</module>
5556

5657
<module>auto-configurations/models/embedding/observation/spring-ai-autoconfigure-model-embedding-observation</module>

vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import org.slf4j.Logger;
6565
import org.slf4j.LoggerFactory;
6666

67-
import org.springframework.ai.cassandra.SchemaUtil;
6867
import org.springframework.ai.document.Document;
6968
import org.springframework.ai.document.DocumentMetadata;
7069
import org.springframework.ai.embedding.EmbeddingModel;

vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/cassandra/SchemaUtil.java renamed to vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/SchemaUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ai.cassandra;
17+
package org.springframework.ai.vectorstore.cassandra;
1818

1919
import java.time.Duration;
2020

0 commit comments

Comments
 (0)