Get startedGet started for free

Creating a vector index

The 'text' properties on our Line nodes are perfect for generating embeddings that answer open-ended questions about the play.

Use the vector store provided by langchain-neo4j to create a vector index by embedding the 'text' property of the Line nodes.

This exercise is part of the course

Graph RAG with LangChain and Neo4j

View Course

Exercise instructions

  • Use the correct class to create a vector index from an existing graph of nodes and relationships.
  • Instruct the class to store the embeddings in the 'embedding' node property.
  • Instruct the class to create embeddings in the 'text' node property.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from langchain_neo4j import Neo4jVector

# Create a vector store from the existing graph
line_retriever = ____.from_existing_graph(
    embedding=embeddings,
    url=NEO4J_URL, username=NEO4J_USERNAME, password=NEO4J_PASSWORD,
    index_name="lines_index",
    node_label="Line",
    # Set the embedding and text node properties
    ____="embedding",
    ____=["text"],
)

results = line_retriever.similarity_search_with_score("Biting a finger", k=3)

for result in results:
    print(result[0].page_content)
Edit and Run Code