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: Update with non-deprecated cypher methods, and new method to associate relationship embeddings #23725

Conversation

RafaelXokito
Copy link
Contributor

@RafaelXokito RafaelXokito commented Jul 1, 2024

Description: At the moment neo4j wrapper is using setVectorProperty, which is deprecated (link). I replaced with the non-deprecated version.

Neo4j recently introduced a new cypher method to associate embeddings into relations using "setRelationshipVectorProperty" method. In this PR I also implemented a new method to perform this association maintaining the same format used in the "add_embeddings" method which is used to associate embeddings into Nodes.
I also included a test case for this new method.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 1, 2024
Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Jul 17, 2024 9:05am

@RafaelXokito RafaelXokito changed the title Neo4j: Update with non-deprecated cypher methods, and new method to create relationship embeddings Neo4j: Update with non-deprecated cypher methods, and new method to associate relationship embeddings Jul 1, 2024
@dosubot dosubot bot added community Related to langchain-community Ɑ: vector store Related to vector store module 🔌: neo4j Primarily related to Neo4j integrations 🤖:improvement Medium size change to existing code to handle new use-cases labels Jul 1, 2024
@RafaelXokito
Copy link
Contributor Author

@ccurme Please review this PR.

@tomasonjo
Copy link
Contributor

What's the reason for adding relationship embedding method if it isn't used anywhere? We also dont plan it

@RafaelXokito
Copy link
Contributor Author

Thank you for your feedback, @tomasonjo.

The introduction of the new method for creating relationship embeddings in langchain is essential to keep pace with Neo4j's latest features. This enhancement ensures that the langchain library remains up-to-date and useful for the community. Given that we already have a method to create embeddings for nodes, it is logical and beneficial to include a corresponding method for relationships.

Please let me know your thoughts on this.

@tomasonjo
Copy link
Contributor

If it isn't used in any methods, and we don't really plan any support either, then there is no need for the method

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 10, 2024
@RafaelXokito
Copy link
Contributor Author

@tomasonjo I reverted the changes regarding the relationship embeddings method.
I will open an issue to discuss it's inclusion.

@RafaelXokito
Copy link
Contributor Author

@ccurme please review this PR.

@tomasonjo
Copy link
Contributor

tomasonjo commented Jul 17, 2024

Why do we need return in subquery?

@RafaelXokito
Copy link
Contributor Author

@tomasonjo thank you for your feedback. Could you please clarify your concern? Neither RETURN statement can be removed without causing an error.

I believe you are referring to the following code:

        import_query = (
            "UNWIND $data AS row "
            "CALL { WITH row "
            f"MERGE (c:`{self.node_label}` {{id: row.id}}) "
            "WITH c, row "
            f"CALL db.create.setNodeVectorProperty(c, "
            f"'{self.embedding_node_property}', row.embedding) "
            f"SET c.`{self.text_node_property}` = row.text "
            "SET c += row.metadata "
            "RETURN c "
            "} IN TRANSACTIONS OF 1000 ROWS "
            "RETURN c "
        )

If the first RETURN statement inside the subquery is removed, an error occurs because the variable c must be returned to be accessible in the outer context.

If the second RETURN statement is removed, an error occurs indicating that the outer query cannot end with a CALL statement; it must have a RETURN clause to conclude properly.

Therefore, both RETURN statements are necessary to ensure the query is valid and functions correctly.

Give me your feedback on this.

@tomasonjo
Copy link
Contributor

We definitely dont want to return so much information as it isnt needed. Ideally we would get rid of both return statements

@RafaelXokito
Copy link
Contributor Author

@tomasonjo Thank you for your feedback. I believe I have found a solution. Please leave your feedback on the changes that I made.

@tomasonjo
Copy link
Contributor

tomasonjo commented Jul 17, 2024 via email

Copy link
Contributor

@jexp jexp left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Jul 17, 2024
@ccurme ccurme merged commit cf28708 into langchain-ai:master Jul 17, 2024
43 checks passed
@RafaelXokito RafaelXokito deleted the feature/replace-deprecated-neo4j-attribute branch July 17, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community 🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. 🔌: neo4j Primarily related to Neo4j integrations size:S This PR changes 10-29 lines, ignoring generated files. Ɑ: vector store Related to vector store module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants