Create and store embeddings
Neo4j’s vector indexes and vector functions allow you to calculate the similarity between node and relationship properties in a graph. A prerequisite for using these features is that vector embeddings have been set as properties of these entities. This page shows how these embeddings can be created and stored as properties on nodes and relationships in a Neo4j database using the GenAI plugin.
| For a hands-on guide on how to use the GenAI plugin on a Neo4j database, see Embeddings & Vector Indexes Tutorial → Create embeddings with cloud AI providers. |
Example graph
The examples on this page use the Neo4j movie recommendations dataset, focusing on the plot and title properties of Movie nodes.
There are 9083 Movie nodes with a plot and title property.
To recreate the graph, download and import this dump file into an empty Neo4j database. Dump files can be imported for both Aura and self-managed instances.
The embeddings on this page are generated using the OpenAI model text-embedding-3-small.
|
Generate and store a single embedding
Use the ai.text.embed() function to generate a vector embedding for a single value.
Syntax |
|
||
Description |
Encode a resource as a vector using the named provider. |
||
Inputs |
Name |
Type |
Description |
|
|
The string to transform into an embedding. |
|
|
|
Case-insensitive identifier of the AI provider to use. See Providers for supported options. |
|
|
|
Provider-specific options. See Providers for details of each supported provider. Note that because this argument may contain sensitive data, it is obfuscated in the query.log. However, if the function call is misspelled or the query is otherwise malformed, it will be logged without obfuscation. |
|
Returns |
Generated text based on the provided prompt. |
||
| This function sends one API request every time it is called, which may result in a lot of overhead in terms of both network traffic and latency. If you want to generate many embeddings at once, use Generate and store a batch of embeddings. |
Generate and store a batch of embeddings
Use the ai.text.embedBatch procedure to generate many vector embeddings with a single API request.
This procedure takes a list of resources as an input, and returns the same number of result rows.
Syntax |
|
||
Description |
Encode a given batch of resources as vectors using the named provider. |
||
Inputs |
Name |
Type |
Description |
|
|
The strings to transform into an embedding. |
|
|
|
Case-insensitive identifier of the AI provider to use. See Providers for supported options. |
|
|
|
Provider-specific options. See Providers for details of each supported provider. Note that because this argument may contain sensitive data, it is obfuscated in the query.log. However, if the function call is misspelled or the query is otherwise malformed, it will be logged without obfuscation. |
|
Returns |
Name |
Type |
Description |
|
|
The index of the corresponding element in the input list, to correlate results back to inputs. |
|
|
|
The given input resource. |
|
|
|
The generated vector embedding for this resource. |
|
|
This procedure attempts to generate embeddings for all supplied resources in a single API request. Providing too many resources may cause the AI provider to time out or to reject the request. |
Providers
You can crate vector embeddings via the following providers:
-
OpenAI (
openai) -
Azure OpenAI (
azure-openai) -
Google Vertex AI (
vertexai) -
Amazon Bedrock Titan Models (
bedrock-titan)
The query CALL ai.text.embed.providers() (see reference) shows the list of supported providers in the installed version of the plugin.
OpenAI
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model ID (see OpenAI → Models). |
|
|
- |
OpenAI API key (see OpenAI → API Keys). |
|
|
|
Optional vendor options that will be passed on as-is in the request to Open AI (see OpenAI → Create embeddings). |
Hello World!WITH
{
token: $openaiToken,
model: 'text-embedding-3-small',
vendorOptions: {
dimensions: 1024
}
} AS conf
RETURN ai.text.embed('Hello World!', 'openai', conf) AS result
Azure OpenAI
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model id (see Azure → Azure OpenAI in Foundry Models). |
|
|
- |
Azure resource name. |
|
|
- |
Azure OAuth2 bearer token. |
|
|
|
Optional vendor options that will be passed on as-is in the request to Azure. |
Hello World!WITH
{
token: $azureToken,
resource: 'my-azure-openai-resource',
model: 'text-embedding-3-small',
vendorOptions: {
dimensions: 1024
}
} AS conf
RETURN ai.text.embed('Hello World!', 'azure-openai', conf) AS result
Google VertexAI
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model resource name (see Vertex AI → Model Garden). |
|
|
- |
Google Cloud project ID. |
|
|
- |
Google cloud region (see Vertex AI → Locations). |
|
|
|
Model publisher. |
|
|
- |
Vertex API access token. |
|
|
|
Optional vendor options that will be passed on as-is in the request to Vertex (see Vertex AI → Method: models.predict). |
Hello World!WITH
{
token: $vertexaiApiAccessKey,
model: 'gemini-embedding-001',
publisher: 'google',
project: 'my-google-cloud-project',
region: 'asia-northeast1',
vendorOptions: {
outputDimensionality: 1024
}
} AS conf
RETURN ai.text.embed('Hello World!', 'vertexai', conf) AS result
Amazon Bedrock Titan Models
This provider supports all models that use the same request parameters and response fields as the Titan text models.
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model ID or its ARN. |
|
|
- |
Amazon region (see Amazon Bedrock → Model Support). |
|
|
- |
Amazon access key ID. |
|
|
- |
Amazon secret access key. |
|
|
|
Optional vendor options that will be passed on as-is in the request to Bedrock (see Amazon Bedrock → Inference request parameters and response fields). |
Hello World!WITH
{
accessKeyId: $awsAccessKeyId,
secretAccessKey: $secretAccessKey,
model: 'amazon.titan-embed-text-v1',
region: 'eu-west-2',
vendorOptions: {
dimensions: 1024
}
} AS conf
RETURN ai.text.embed('Hello World!', 'bedrock-titan', conf) AS result
(Legacy) ProvidersDeprecated in 2025.11
The following provider configurations are for the genai.vector.encode function and the genai.vector.encodeBatch procedure.
Both callables have been deprecated in 2025.11 and superseded by ai.text.embed and ai.text.embedBatch.
For more information on the old callables, see documentation for the previous version.
OpenAI
-
Identifier (
providerargument):"OpenAI"
| Key | Type | Description | Default |
|---|---|---|---|
|
|
API access token. |
Required |
|
|
The name of the model to invoke. |
|
|
|
The number of dimensions to reduce the vector to. Only supported for certain models. |
Model-dependent. |
Vertex AI
-
Identifier (
providerargument):"VertexAI"
| Key | Type | Description | Default |
|---|---|---|---|
|
|
API access token. |
Required |
|
|
GCP project ID. |
Required |
|
|
The name of the model to invoke. |
|
|
|
GCP region where to send the API requests. Supported values
|
|
|
|
The intended downstream application (see provider documentation). The specified |
|
|
|
The title of the document that is being encoded (see provider documentation). The specified |
Azure OpenAI
-
Identifier (
providerargument):"AzureOpenAI"
| Unlike the other providers, the model is configured when creating the deployment on Azure, and is thus not part of the configuration map. |
| Key | Type | Description | Default |
|---|---|---|---|
|
|
API access token. |
Required |
|
|
The name of the resource to which the model has been deployed. |
Required |
|
|
The name of the model deployment. |
Required |
|
|
The number of dimensions to reduce the vector to. Only supported for certain models. |
Model-dependent. |
Amazon Bedrock
-
Identifier (
providerargument):"Bedrock"
| Key | Type | Description | Default |
|---|---|---|---|
|
|
AWS access key ID. |
Required |
|
|
AWS secret key. |
Required |
|
|
The name of the model to invoke.
|
|
|
|
AWS region where to send the API requests.
|
|