Vectors

What is a Vector?

Vectors are simply a list of numbers.

The vector [1, 2, 3] is a list of three numbers and could represent a point in three-dimensional space.

You can use vectors to represent many different types of data, including text, images, and audio.

A diagram showing a 3d representation of the x,y,z coordinates 1,1,1 and 1,2,3

Vectors in the Real World

  • 3D space

  • Navigation

  • Calculations with external forces

  • And many other uses!

a diagram showing an airplane in 3D space, with vectors representing its position and direction

What are embeddings?

An embedding is a vector that represents the data in a useful way for a specific task.

  • A type of data compression

  • Transform messy data into compact format

  • Numeric vectors with 100s or 1000s of elements

"apple"

You can use an embedding model to turn words and phrases into vectors:

`0.0077788467, -0.02306925, -0.007360777, -0.027743412, -0.0045747845, 0.01289164, -0.021863015, -0.008587573, 0.01892967, -0.029854324, -0.0027962727, 0.020108491, -0.004530236, 0.009129008, -0.021451797, 0.002030382, 0.030813828, 9.744976e-05, 0.0019172973, -0.02568733, -0.020985752, -0.008066699, 0.02134214, -0.01222684, 0.0009980568, 0.005105939, 0.009999417, -0.000107408916, 0.015845545, -0.012980737, 0.020574536, -0.016160812, -0.018518453, 0.005263572, -0.019286057, -0.009293495, -0.012096621, -0.008854863, -0.005753605, -0.006157968, 0.010540851, 0.007724018, -0.0065554776, 0.00052944134, -0.023453051, 0.011089141, -0.021671113, -0.00061425474, -0.012754567, 0.015489157, -0.0054520466, -0.0020355221, -0.015050527, -0.0052944133, -0.0028082666, 0.0027431573, -0.019450543, 0.0063807103, -0.010725899, 0.0049243183, 0.005266999, 0.01513277, -0.027921606, 0.0055754115, -0.009183837, 0.00380718, -0.013624975, -0.0084710615, 0.012905347, 0.015667351, 0.033363372, 0.013268588, 0.014036193, 0.0063464423, 0.004454846, 0.0014820931, -0.03396649, -0.0062779062, -0.00314238, 0.01818948, 0.0075389706, -0.02637269, 0.009574492, 0.024974553, 0.024823774, 0.009882905, -0.021657405, 0.010109074, -0.007970748, 0.0028887964, 0.011849891, 0.0054726074, 0.0078336755, 0.016448664, -0.026975807, 0.016599443, -0.012713445, 0.026345275, 0.004667308, -0.03736588, 0.0009834929, 0.006089432, -0.028730331, -0.011198798, -0.020396343, 0.0019738395, 0.012459862, -0.003738644, 0.015448036, -0.019902883, 0.0064389664, 0.00926608, 0.021945259, -0.051648803, -0.016448664, -0.01744929, -0.009499103, 0.0021743076, -0.022795105, -0.035556525, 0.034021318, 0.025892938, 0.038407627, -0.008752059, 0.013446782, -0.0032640316, -0.01779197, -0.009567639, -0.0011205651, -0.013947096, 0.04707059, 0.008100967, 0.019491665, 0.016448664, -0.017846799, …​

Semantic search aims to understand search phrases' intent and contextual meaning.

Are you searching about the fruit, the tech company, or something else?

A diagram showing the different meanings for the word "apple"

Similarity Search

You can use the distance or angle between vectors to find similar data.

Words with similar meanings or contexts will have vectors that are close together, while unrelated words will be farther apart.

A 3 dimensional chart illustrating the distance between vectors. The vectors are for the words "apple" and "fruit"

Knowledge Graphs and Vectors

Vectors and embeddings can be used to facilitate similarity search in knowledge graphs.

A graph data model showing the relationship between chunks that have embeddings

Create embeddings

You can use Cypher to create an embedding for a chunk of text:

cypher
WITH genai.vector.encode(
    "Create an embedding for this text",
    "OpenAI",
    { token: "sk-..." }) AS embedding
RETURN embedding

OpenAI API Key

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

Search a vector index

You can search a vector index to find similar chunks of text.

cypher
WITH genai.vector.encode(
    "What is the latest with Apple Inc?",
    "OpenAI",
    { token: "sk-..." }) AS embedding
CALL db.index.vector.queryNodes('chunkEmbeddings', 6, embedding)
YIELD node, score
RETURN node.text, score

Traverse the graph

From the results of the vector search, you can traverse the graph to find related entities:

cypher
WITH genai.vector.encode(
    "Whats the latest with Apple Inc?",
    "OpenAI",
    { token: "sk-..." }) AS embedding
CALL db.index.vector.queryNodes('chunkEmbeddings', 6, embedding)
YIELD node, score
MATCH (node)<-[:FROM_CHUNK]-(e:__Entity__)
RETURN node.text, score, collect(e.name) AS entities

Summary

In this lesson, you learned about vectors and embeddings for semantic search:

Key Concepts:

  • Vectors are numerical representations that enable semantic similarity search

  • Embeddings transform text into high-dimensional vectors that capture meaning and context

  • Neo4j can store vectors alongside graph data for hybrid retrieval

  • Vector indexes enable fast similarity search across large document collections

Practical Applications:

  • Create embeddings for text chunks using OpenAI’s embedding API

  • Store embeddings in Neo4j with vector indexes for efficient search

  • Combine vector similarity with graph traversal for contextual retrieval

  • Use semantic search to find relevant content even when exact keywords don’t match

What You Can Do:

  • Search for similar content based on meaning, not just keywords

  • Find relevant document chunks that relate to your query semantically

  • Traverse from retrieved chunks to related entities in the knowledge graph

  • Enable more intelligent, context-aware search capabilities

In the next module, you will learn how to build different types of retrievers that combine vector search with graph traversal for powerful GraphRAG applications.

Chatbot

How can I help you today?