Creating Embeddings

In this task, you will use Cypher to create embeddings.

In a later task will also use Python to create embeddings.

Find a movie plot

In the previous task, you used a vector index to find similar movies.

To find a movie with a plot you define, you need to create an embedding for your text before you can query the vector index.

For example, to find a movie about "A mysterious spaceship lands Earth", you need to:

  1. Create an embedding for the text "A mysterious spaceship lands Earth".

  2. Pass the embedding to the db.index.vector.queryNodes function.

You can generate a new embedding in Cypher using the genai.vector.encode function:

For example, you can use the OpenAI provider to generate an embedding passing the API key as token in the configuration map:

cypher
WITH genai.vector.encode(
    "Text to create embeddings for",
    "OpenAI",
    { token: "sk-..." }) AS embedding
RETURN embedding

Remember to replace sk-…​ with your OpenAI API key.

You can use the embedding to query the vector index to find similar movies.

cypher
WITH genai.vector.encode(
    "A mysterious spaceship lands Earth",
    "OpenAI",
    { token: "sk-..." }) AS myMoviePlot
CALL db.index.vector.queryNodes('moviePlots', 6, myMoviePlot)
YIELD node, score
RETURN node.title, node.plot, score

Experiment with different movie plots and observe the results.

Continue

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

Summary

You learned how to create embeddings using Cypher.

In the next task, you will learn how to create a vector index on an embedding.