tomasonjo / blogs

Jupyter notebooks that support my graph data science blog posts at https://bratanic-tomaz.medium.com/
1.25k stars 332 forks source link

"Node_Label" in the Neo4jVector couldn't be modified #37

Closed ramkumarsync closed 1 day ago

ramkumarsync commented 1 month ago

@tomasonjo I am trying to initialize the vector store from the existing graph to perform for vector similarity search. But whatever the value assigned for the "node_label" property wasn't considered.

In the below code example, I assign the "Codeexample" value to the "node_label". However, after the vector store initialization I printed the value of "node_label" and it simply return "Document" every time. This makes my vector similarity search to return empty results.

`from neo4j import GraphDatabase from langchain_openai import OpenAIEmbeddings from langchain.vectorstores import Neo4jVector

driver = GraphDatabase.driver(url, auth=(username, password))

Initialize LangChain components

embedding = OpenAIEmbeddings() vector_store = Neo4jVector.from_existing_graph( embedding=embedding, url=url, username=username, password=password, node_label="Codeexample", text_node_properties=["id", "name", "description", "code"], embedding_node_property="embedding", )

Print Debug Information

print("Node Label:", vector_store.node_label) ----- Node Label: Document ------

Process natural language query

query = "My code example query" query_embedding = embedding.embed_query(query)

Search in the knowledge graph

results = vector_store.similarity_search(query, k=1) results`

Please check this and let me know if I am missing anything here. Thanks in advance :)

tomasonjo commented 1 month ago

Thats because there is an existing vector index, use a different index_name

V pet., 9. avg. 2024, 18:26 je oseba ramkumarsync @.***> napisala:

@tomasonjo https://github.com/tomasonjo I am trying to initialize the vector store from the existing graph to perform for vector similarity search. But whatever the value assigned for the "node_label" property wasn't considered.

In the below code example, I assign the "Codeexample" value to the "node_label". However, after the vector store initialization I printed the value of "node_label" and it simply return "Document" every time. This makes my vector similarity search to return empty results.

`from neo4j import GraphDatabase from langchain_openai import OpenAIEmbeddings from langchain.vectorstores import Neo4jVector

driver = GraphDatabase.driver(url, auth=(username, password)) Initialize LangChain components

embedding = OpenAIEmbeddings() vector_store = Neo4jVector.from_existing_graph( embedding=embedding, url=url, username=username, password=password,

node_label="Document",

text_node_properties=["id", "name", "title"],

node_label="Codeexample", text_node_properties=["id", "name", "description", "code"], embedding_node_property="embedding", ) Print Debug Information

print("Node Label:", vector_store.node_label) ----- Node Label: Document ------ Process natural language query

query = "My code example query" query_embedding = embedding.embed_query(query) Search in the knowledge graph

results = vector_store.similarity_search(query, k=1) results`

Please check this and let me know if I am missing anything here. Thanks in advance :)

— Reply to this email directly, view it on GitHub https://github.com/tomasonjo/blogs/issues/37, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYGGTLFDN5HWN6PX7RK7ILZQTUUJAVCNFSM6AAAAABMIYR3U6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ2TQMRXGE4TMMQ . You are receiving this because you were mentioned.Message ID: @.***>