Skip to content

Commit 1d4bde8

Browse files
Enrico Rampazzoilayaperumalg
Enrico Rampazzo
authored andcommitted
Neo4j chatmemory implementation
- Add chatmemory implementation for Neo4j - Add autoconfiguration for Neo4jChatMemory - Add tests Signed-off-by: Enrico Rampazzo <[email protected]>
1 parent c23647d commit 1d4bde8

File tree

15 files changed

+1119
-1
lines changed

15 files changed

+1119
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.springframework.ai</groupId>
8+
<artifactId>spring-ai</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<relativePath>../../../../../pom.xml</relativePath>
11+
</parent>
12+
<artifactId>spring-ai-autoconfigure-model-chat-memory-neo4j</artifactId>
13+
<packaging>jar</packaging>
14+
<name>Spring AI Neo4j Chat Memory Auto Configuration</name>
15+
<description>Spring Neo4j AI Chat Memory Auto Configuration</description>
16+
<url>https://github.com/spring-projects/spring-ai</url>
17+
18+
<scm>
19+
<url>https://github.com/spring-projects/spring-ai</url>
20+
<connection>git://github.com/spring-projects/spring-ai.git</connection>
21+
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
22+
</scm>
23+
24+
25+
<dependencies>
26+
27+
<dependency>
28+
<groupId>org.springframework.ai</groupId>
29+
<artifactId>spring-ai-core</artifactId>
30+
<version>${project.parent.version}</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.ai</groupId>
35+
<artifactId>spring-ai-neo4j-store</artifactId>
36+
<version>${project.parent.version}</version>
37+
</dependency>
38+
39+
<!-- Boot dependencies -->
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-configuration-processor</artifactId>
48+
<optional>true</optional>
49+
</dependency>
50+
51+
<!-- Test dependencies -->
52+
<dependency>
53+
<groupId>org.springframework.ai</groupId>
54+
<artifactId>spring-ai-test</artifactId>
55+
<version>${project.parent.version}</version>
56+
<scope>test</scope>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>org.springframework.ai</groupId>
61+
<artifactId>spring-ai-autoconfigure-model-chat-client</artifactId>
62+
<version>${project.parent.version}</version>
63+
<scope>test</scope>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>org.springframework.ai</groupId>
68+
<artifactId>spring-ai-openai</artifactId>
69+
<version>${project.parent.version}</version>
70+
<scope>test</scope>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-test</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>org.testcontainers</groupId>
81+
<artifactId>junit-jupiter</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>org.testcontainers</groupId>
87+
<artifactId>neo4j</artifactId>
88+
<scope>test</scope>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>org.mockito</groupId>
93+
<artifactId>mockito-core</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
</dependencies>
97+
98+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023-2024 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.model.chat.memory.neo4j.autoconfigure;
18+
19+
import org.neo4j.driver.Driver;
20+
import org.springframework.ai.chat.memory.neo4j.Neo4jChatMemory;
21+
import org.springframework.ai.chat.memory.neo4j.Neo4jChatMemoryConfig;
22+
import org.springframework.boot.autoconfigure.AutoConfiguration;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
25+
import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration;
26+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
27+
import org.springframework.context.annotation.Bean;
28+
29+
/**
30+
* {@link AutoConfiguration Auto-configuration} for {@link Neo4jChatMemory}.
31+
*
32+
* @author Enrico Rampazzo
33+
* @since 1.0.0
34+
*/
35+
@AutoConfiguration(after = Neo4jAutoConfiguration.class)
36+
@ConditionalOnClass({ Neo4jChatMemory.class, Driver.class })
37+
@EnableConfigurationProperties(Neo4jChatMemoryProperties.class)
38+
public class Neo4jChatMemoryAutoConfiguration {
39+
40+
@Bean
41+
@ConditionalOnMissingBean
42+
public Neo4jChatMemory chatMemory(Neo4jChatMemoryProperties properties, Driver driver) {
43+
44+
var builder = Neo4jChatMemoryConfig.builder()
45+
.withMediaLabel(properties.getMediaLabel())
46+
.withMessageLabel(properties.getMessageLabel())
47+
.withMetadataLabel(properties.getMetadataLabel())
48+
.withSessionLabel(properties.getSessionLabel())
49+
.withToolCallLabel(properties.getToolCallLabel())
50+
.withToolResponseLabel(properties.getToolResponseLabel())
51+
.withDriver(driver);
52+
53+
return Neo4jChatMemory.create(builder.build());
54+
}
55+
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.model.chat.memory.neo4j.autoconfigure;
18+
19+
import org.springframework.ai.chat.memory.neo4j.Neo4jChatMemoryConfig;
20+
import org.springframework.boot.context.properties.ConfigurationProperties;
21+
22+
/**
23+
* Configuration properties for Neo4j chat memory.
24+
*
25+
* @author Enrico Rampazzo
26+
*/
27+
@ConfigurationProperties(Neo4jChatMemoryProperties.CONFIG_PREFIX)
28+
public class Neo4jChatMemoryProperties {
29+
30+
public static final String CONFIG_PREFIX = "spring.ai.chat.memory.neo4j";
31+
32+
private String sessionLabel = Neo4jChatMemoryConfig.DEFAULT_SESSION_LABEL;
33+
34+
private String toolCallLabel = Neo4jChatMemoryConfig.DEFAULT_TOOL_CALL_LABEL;
35+
36+
private String metadataLabel = Neo4jChatMemoryConfig.DEFAULT_METADATA_LABEL;
37+
38+
private String messageLabel = Neo4jChatMemoryConfig.DEFAULT_MESSAGE_LABEL;
39+
40+
private String toolResponseLabel = Neo4jChatMemoryConfig.DEFAULT_TOOL_RESPONSE_LABEL;
41+
42+
private String mediaLabel = Neo4jChatMemoryConfig.DEFAULT_MEDIA_LABEL;
43+
44+
public String getSessionLabel() {
45+
return sessionLabel;
46+
}
47+
48+
public void setSessionLabel(String sessionLabel) {
49+
this.sessionLabel = sessionLabel;
50+
}
51+
52+
public String getToolCallLabel() {
53+
return toolCallLabel;
54+
}
55+
56+
public String getMetadataLabel() {
57+
return metadataLabel;
58+
}
59+
60+
public String getMessageLabel() {
61+
return messageLabel;
62+
}
63+
64+
public String getToolResponseLabel() {
65+
return toolResponseLabel;
66+
}
67+
68+
public String getMediaLabel() {
69+
return mediaLabel;
70+
}
71+
72+
public void setToolCallLabel(String toolCallLabel) {
73+
this.toolCallLabel = toolCallLabel;
74+
}
75+
76+
public void setMetadataLabel(String metadataLabel) {
77+
this.metadataLabel = metadataLabel;
78+
}
79+
80+
public void setMessageLabel(String messageLabel) {
81+
this.messageLabel = messageLabel;
82+
}
83+
84+
public void setToolResponseLabel(String toolResponseLabel) {
85+
this.toolResponseLabel = toolResponseLabel;
86+
}
87+
88+
public void setMediaLabel(String mediaLabel) {
89+
this.mediaLabel = mediaLabel;
90+
}
91+
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
org.springframework.ai.model.chat.memory.neo4j.autoconfigure.Neo4jChatMemoryAutoConfiguration

0 commit comments

Comments
 (0)