Skip to content
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

neo4j chatmemory implementation #2071

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

enricorampazzo
Copy link

This is the same as this PR, but with a signed-off commit

Enrico Rampazzo added 2 commits January 15, 2025 15:20
Signed-off-by: Enrico Rampazzo <[email protected]>
@enricorampazzo enricorampazzo changed the title chatmemory implementation neo4j chatmemory implementation Jan 17, 2025
@ilayaperumalg
Copy link
Member

@meistermeier Could you help reviewing this PR?

Copy link
Contributor

@meistermeier meistermeier left a comment

Choose a reason for hiding this comment

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

I have no deep insights how a chat memory should work and what the expected outcome is, besides from what I can read up in code here and compared to e.g. Cassandra store. Because of this I would be happy to get also your thoughts on the overall behaviour @ilayaperumalg (and team).
Some things I am missing here:

  • a dedicated integration test within the store module for the chat memory
  • spring formatter (build fails)

@@ -191,6 +193,7 @@ protected Neo4jVectorStore(Builder builder) {
this.idProperty = SchemaNames.sanitize(builder.idProperty).orElseThrow();
this.constraintName = SchemaNames.sanitize(builder.constraintName).orElseThrow();
this.initializeSchema = builder.initializeSchema;
this.batchingStrategy = new TokenCountBatchingStrategy();
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not take the batchingStrategy set in the Builder into account.
I cannot judge if this is needed at all in context of this PR.

@@ -511,6 +516,11 @@ public Builder initializeSchema(boolean initializeSchema) {
return this;
}

public Builder batchingStrategy(BatchingStrategy batchingStrategy){
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unnecessary because it's the same as the setter in the AbstractVectorStoreBuilder.

Map<String, Object> queryParameters = new HashMap<>();
queryParameters.put("conversationId", conversationId);
StringBuilder statementBuilder = new StringBuilder();
statementBuilder.append("""
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider using Neo4j CypherDSL here. There is already a bom declared in the pom but we only use it for proper name escaping yet.
There was no need for this before because we didn't do any string concatenation. Now I would say, that this would be a good idea to keep it maintainable.


private final String mediaLabel;

public String getSessionLabel() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Those getters are not needed.

Comment on lines +394 to +395
| `spring.ai.chat.memory.neo4j.toolCallLabel` | The label for nodes that store tool calls, for example
in Assistant Messages | `ToolCall`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| `spring.ai.chat.memory.neo4j.toolCallLabel` | The label for nodes that store tool calls, for example
in Assistant Messages | `ToolCall`
| `spring.ai.chat.memory.neo4j.toolCallLabel` | The label for nodes that store tool calls, for example in Assistant Messages | `ToolCall`

@@ -374,7 +374,7 @@ Refer to the xref:_retrieval_augmented_generation[Retrieval Augmented Generation

The interface `ChatMemory` represents a storage for chat conversation history. It provides methods to add messages to a conversation, retrieve messages from a conversation, and clear the conversation history.

There are currently two implementations, `InMemoryChatMemory` and `CassandraChatMemory`, that provide storage for chat conversation history, in-memory and persisted with `time-to-live`, correspondingly.
There are currently three implementations, `InMemoryChatMemory`, `CassandraChatMemory` and `Neo4jChatMemory`, that provide storage for chat conversation history, in-memory, persisted with `time-to-live` in Cassandra, and persisted without `time-to-live` in Neo4j correspondingly.

To create a `CassandraChatMemory` with `time-to-live`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a more general remark, but the sections for Cassandra and Neo4j as chat memory stores(?) should look the the same regarding parameters etc. (maybe this is also true for InMemoryChatMemory and this needs to be added).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants