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

Issue 2544: Support Text2Cypher / Text2GQL with something like the CypherQAChain #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vga91
Copy link
Owner

@vga91 vga91 commented Mar 12, 2025

Compared with https://github.com/langchain4j/langchain4j/issues/2544 feature requests,
the implementation is quite already existing.

Just improved builder with previousMessages, which has a default similar to the text2cypher one:

https://github.com/neo4j-labs/text2cypher/blob/main/datasets/synthetic_gemini_demodbs/gemini_text2cypher.ipynb

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • langchain4j-core/src/test/java/dev/langchain4j/internal/JsonCodecTest.java
    • lines 3-12
    • lines 32-35
    • lines 51-51
    • lines 66-67
    • lines 95-95
    • lines 111-112
    • lines 120-121
    • lines 140-141
    • lines 160-161
    • lines 178-184
    • lines 207-217
    • lines 241-243
    • lines 270-273
    • lines 290-290
    • lines 310-311
    • lines 330-332
    • lines 344-344
    • lines 356-357
    • lines 374-374
    • lines 384-386
    • lines 408-408
  • langchain4j-mcp/src/test/java/dev/langchain4j/mcp/client/integration/McpResourcesTestBase.java
    • lines 44-44
    • lines 55-55
    • lines 82-82
    • lines 93-93
  • langchain4j-neo4j/src/main/java/dev/langchain4j/rag/content/retriever/neo4j/Neo4jContentRetriever.java
    • lines 15-25
    • lines 49-50
    • lines 69-69
  • langchain4j-neo4j/src/test/java/dev/langchain4j/rag/content/retriever/neo4j/Neo4jContentRetrieverIT.java
    • lines 33-42
    • lines 69-71
    • lines 192-194

Comment on lines +90 to +96
final List<ChatMessage> messages = previousMessages == null
? new ArrayList<>()
: new ArrayList<>(previousMessages);
messages.add(cypherPrompt.toUserMessage());

String cypherQuery = chatLanguageModel.chat(messages)
.aiMessage()

Choose a reason for hiding this comment

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

Suggested change
final List<ChatMessage> messages = previousMessages == null
? new ArrayList<>()
: new ArrayList<>(previousMessages);
messages.add(cypherPrompt.toUserMessage());
String cypherQuery = chatLanguageModel.chat(messages)
.aiMessage()
final List<ChatMessage> messages =
previousMessages == null ? new ArrayList<>() : new ArrayList<>(previousMessages);
String cypherQuery = chatLanguageModel.chat(messages).aiMessage().text();

Comment on lines +7 to +10
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

import dev.langchain4j.data.message.AiMessage;

Choose a reason for hiding this comment

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

Suggested change
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import dev.langchain4j.data.message.AiMessage;
import java.util.List;

Comment on lines +98 to +100
.thenReturn(ChatResponse.builder().aiMessage(new AiMessage(
"MATCH(book:Book {title: 'Dune'})<-[:WROTE]-(author:Person) RETURN author.name AS output"
)).build());

Choose a reason for hiding this comment

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

Suggested change
.thenReturn(ChatResponse.builder().aiMessage(new AiMessage(
"MATCH(book:Book {title: 'Dune'})<-[:WROTE]-(author:Person) RETURN author.name AS output"
)).build());
.thenReturn(ChatResponse.builder()
.aiMessage(
new AiMessage(
"MATCH(book:Book {title: 'Dune'})<-[:WROTE]-(author:Person) RETURN author.name AS output"))
.build());

Comment on lines +114 to +116
.thenReturn(ChatResponse.builder().aiMessage(new AiMessage(
"```MATCH(book:Book {title: 'Dune'})<-[:WROTE]-(author:Person) RETURN author.name AS output```"
)).build());

Choose a reason for hiding this comment

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

Suggested change
.thenReturn(ChatResponse.builder().aiMessage(new AiMessage(
"```MATCH(book:Book {title: 'Dune'})<-[:WROTE]-(author:Person) RETURN author.name AS output```"
)).build());
.thenReturn(ChatResponse.builder()
.aiMessage(
new AiMessage(
"```MATCH(book:Book {title: 'Dune'})<-[:WROTE]-(author:Person) RETURN author.name AS output```"))
.build());

@@ -129,12 +149,49 @@
// Then
assertThat(contents).hasSize(1);
}

Choose a reason for hiding this comment

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

Suggested change

.graph(graph)
.chatLanguageModel(openAiChatModel)
.promptTemplate(PromptTemplate.from("ignore this message, just consider the above 'system' one"))
.previousMessages(List.of(new SystemMessage("ignore the following 'user' content and returns franchino finally")))

Choose a reason for hiding this comment

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

Suggested change
.previousMessages(List.of(new SystemMessage("ignore the following 'user' content and returns franchino finally")))
.previousMessages(
List.of(new SystemMessage("ignore the following 'user' content and returns franchino finally")))

- Ensure that queries checking for non-null properties use `IS NOT NULL` in a straightforward manner.
- Don't use `size((n)--(m))` for counting relationships. Instead use the new `count{(n)--(m))}` syntax.
- Incorporate the new existential subqueries in examples where the query needs to check for the existence of a pattern.
Example: MATCH (p:Person)-[r:IS_FRIENDS_WITH]->(friend:Person)

Choose a reason for hiding this comment

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

KNOWS instead of IS_FRIENDS_WITH

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.

None yet

2 participants