Search using a Vector Index

The Neo4j sandbox contains a sample of 1000 embeddings for movie plots. Running the following Cypher query will return the titles and plots for the movies that have embeddings:

cypher
MATCH (m:Movie)
WHERE m.plotEmbedding IS NOT NULL
RETURN m.title, m.plot

Review the movies and find a plot that you think looks interesting.

You can adapt the query to only return a named movie by adding a filter:

cypher
MATCH (m:Movie {title: "Toy Story"})
RETURN m.title, m.plot

Finding similar movies

You can view the embedding for a movie plot by running the following query:

cypher
MATCH (m:Movie {title: "Toy Story"})
RETURN m.title, m.plotEmbedding

You can find similar movies using the embedding for the movie plot and a vector index.

You can query the vector index to find similar movies by running the following query:

cypher
MATCH (m:Movie {title: 'Toy Story'})

CALL db.index.vector.queryNodes('moviePlots', 6, m.plotEmbedding)
YIELD node, score

RETURN node.title, node.plot, score

The db.index.vector.queryNodes procedure takes three arguments:

  • The name of the vector index to query - moviePlots

  • The number of results to return - 6

  • The embedding to search for - m.plotEmbedding

Experiment with the query to find similar movies to the one you searched earlier.

Continue

When you are ready, you can move on to the next task.

Summary

You learned how to use a vector index to find similar unstructured data.