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
.
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 .
A different model may require a different 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 .
A different model may require a different 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.