UltipaDocs
Try Playground
  • Vector Fundamentals
  • Similarity & Search
  • Utilities & Configuration
  1. Docs
  2. /
  3. AI Functions

Utilities & Configuration

Overview

Vector utilities and AI provider configuration for embedding generation.

Vector Utilities

Functions for working with vectors:

FunctionDescription
AI.DIMENSION(v)Get number of dimensions
AI.NORMALIZE(v)Normalize to unit vector
AI.MAGNITUDE(v)Get vector length
AI.ADD(v1, v2)Add two vectors
AI.TOLIST(v)Convert to list

Get vector properties:

GQL
LET v = AI.VECTOR([3.0, 4.0])
RETURN
  AI.DIMENSION(v) AS dims,
  AI.MAGNITUDE(v) AS magnitude
dimsmagnitude
25.0

Normalize embeddings:

GQL
MATCH (d:Document)
SET d.normalized_embedding = AI.NORMALIZE(d.embedding)

Combine and normalize vectors:

GQL
MATCH (p:Product)
LET combined = AI.ADD(p.text_embedding, p.image_embedding)
SET p.combined_embedding = AI.NORMALIZE(combined)

Convert vector to list:

GQL
MATCH (d:Document {id: 'DOC-1'})
RETURN d.title, AI.TOLIST(d.embedding) AS embedding_array

Provider Configuration

Configure AI providers for embedding generation.

Supported Providers:

  • OpenAI (text-embedding-3-small, text-embedding-3-large)
  • Anthropic (Claude)
  • Cohere (embed-english-v3.0)
  • Ollama (local models)
  • Google (Gemini)
  • Custom HTTP endpoints

Configure OpenAI API key:

GQL
CALL AI.SETAPIKEY('openai', $OPENAI_API_KEY)

Set default embedding provider:

GQL
CALL AI.SETPROVIDER('openai')

Get current provider:

GQL
RETURN AI.PROVIDER() AS current_provider
current_provider
openai

Configure local Ollama model:

GQL
CALL AI.SETPROVIDER('ollama', {
  endpoint: 'http://localhost:11434',
  model: 'nomic-embed-text'
})

Configure custom HTTP endpoint:

GQL
CALL AI.SETPROVIDER('custom', {
  endpoint: 'https://my-embeddings.example.com/embed',
  headers: {'Authorization': 'Bearer ' + $API_KEY},
  model: 'my-custom-model'
})

Embedding Models

Different models produce different dimension vectors:

ProviderModelDimensionsBest For
OpenAItext-embedding-3-small1536General purpose
OpenAItext-embedding-3-large3072High accuracy
Cohereembed-english-v3.01024English text
Ollamanomic-embed-text768Local/private

Specify embedding model:

GQL
LET embedding = AI.embed('text to embed', 'text-embedding-3-large')
RETURN AI.DIMENSION(embedding) AS dimensions
dimensions
3072

Verify dimension compatibility:

GQL
LET embedding = AI.embed('test text')
LET dims = AI.DIMENSION(embedding)

// Ensure consistency with existing embeddings
MATCH (d:Document)
WHERE d.embedding IS NOT NULL
LET existing_dims = AI.DIMENSION(d.embedding)
RETURN dims = existing_dims AS compatible
NOTE

Warning: All vectors in the same index must have the same dimensions. Choose your model carefully before creating embeddings.