Skip to content

fix(memory): Replace the outdated manual way of creating the ChatMemoryRepository #3532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Neo4jChatMemoryRepository neo4jChatMemoryRepository(Neo4jChatMemoryReposi
.withToolResponseLabel(properties.getToolResponseLabel())
.withDriver(driver);

return new Neo4jChatMemoryRepository(builder.build());
return Neo4jChatMemoryRepository.create(builder.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public Neo4jChatMemoryRepository(Neo4jChatMemoryRepositoryConfig config) {
this.config = config;
}

public static Neo4jChatMemoryRepository create(Neo4jChatMemoryRepositoryConfig conf) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, wouldn't it be better to use Builder.builder()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let me modify that

return new Neo4jChatMemoryRepository(conf);
}

@Override
public List<String> findConversationIds() {
return this.config.getDriver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Neo4jChatMemoryRepositoryIT {
void setUp() {
this.driver = Neo4jDriverFactory.create(neo4jContainer.getBoltUrl());
this.config = Neo4jChatMemoryRepositoryConfig.builder().withDriver(this.driver).build();
this.chatMemoryRepository = new Neo4jChatMemoryRepository(this.config);
this.chatMemoryRepository = Neo4jChatMemoryRepository.create(this.config);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ If you'd rather create the `CassandraChatMemoryRepository` manually, you can do
[source,java]
----
ChatMemoryRepository chatMemoryRepository = CassandraChatMemoryRepository
.create(CassandraChatMemoryConfig.builder().withCqlSession(cqlSession));
.create(CassandraChatMemoryRepositoryConfig.builder().withCqlSession(cqlSession).build());

ChatMemory chatMemory = MessageWindowChatMemory.builder()
.chatMemoryRepository(chatMemoryRepository)
Expand Down Expand Up @@ -296,9 +296,8 @@ If you'd rather create the `Neo4jChatMemoryRepository` manually, you can do so b

[source,java]
----
ChatMemoryRepository chatMemoryRepository = Neo4jChatMemoryRepository.builder()
.driver(driver)
.build();
ChatMemoryRepository chatMemoryRepository = Neo4jChatMemoryRepository
.create(Neo4jChatMemoryRepositoryConfig.builder().withDriver(driver).build());

ChatMemory chatMemory = MessageWindowChatMemory.builder()
.chatMemoryRepository(chatMemoryRepository)
Expand Down