Create vector index
Vector indexes allow Neo4j to run similarity queries across the whole database.
The example below shows how to create a vector index for movie embeddings, under the name of moviePlots.
| Provide a dimension when creating a vector index as shown in the examples below, as it ensures that only vectors of that size are indexed and makes dimension mismatches fail explicitly at query time. |
CREATE VECTOR INDEX moviePlots
FOR (m:Movie)
ON m.embedding
OPTIONS {indexConfig: {
`vector.dimensions`: 384, (1)
`vector.similarity_function`: 'cosine' (2)
}}
| 1 | For embeddings generated with the SentenceTransformers model all-MiniLM-L6-v2.
If you use a different model, update this value to match its embedding dimension. |
| 2 | The cosine similarity function is the most common choice. For more details and other options, see Vector indexes → Cosine and Euclidean similarity functions. |
CREATE VECTOR INDEX moviePlots
FOR (m:Movie)
ON m.embedding
OPTIONS {indexConfig: {
`vector.dimensions`: 1536, (1)
`vector.similarity_function`: 'cosine' (2)
}}
| 1 | For embeddings generated with the OpenAI model text-embedding-ada-002.
If you use a different model, update this value to match its embedding dimension. |
| 2 | The cosine similarity function is the most common choice. For more details and other options, see Vector indexes → Cosine and Euclidean similarity functions. |
For more information on vector indexes, see Cypher → Indexes → Vector indexes.