Create and manage vector embeddings for semantic search, recommendations, and AI-powered graph queries. Use ai.setprovider() to set the active embedding AI provider.
Vectors (or embeddings) are arrays of numbers that represent the semantic meaning of data. They enable:
How they work:
Common use cases for vectors in graph databases:
Semantic search example:
GQL// Find documents about graph databases // even if they don't contain those exact words LET query = ai.embed('how do nodes connect in a network') MATCH (d:Document) WHERE ai.cosine(d.embedding, query) > 0.8 RETURN d.title
Product recommendation:
GQLMATCH (p:Product {id: 'PROD-123'}) MATCH (similar:Product) WHERE similar <> p AND ai.cosine(p.embedding, similar.embedding) > 0.85 RETURN similar.name, similar.price LIMIT 5
Converts a list of numbers to a VECTOR type. Values are stored as 32-bit floats, so minor precision differences may occur (e.g., 0.1 becomes 0.10000000149011612). This is useful when you need to explicitly create a VECTOR value for storing in a VECTOR property or passing to similarity functions.
| Syntax | ai.vector(<list>) | ||
| Arguments | Name | Type | Description |
<list> | LIST | A list of numeric values | |
| Return Type | VECTOR | ||
GQLRETURN ai.vector([0.1, 0.2, 0.3])
Result:
JSON{ "values": [ 0.10000000149011612, 0.20000000298023224, 0.30000001192092896 ] }
Generates an embedding vector from text using the configured AI provider.
| Syntax | ai.embed(<text>) | ||
| Arguments | Name | Type | Description |
<text> | STRING | The text to generate an embedding for | |
| Return Type | VECTOR | ||
An AI provider must be configured with ai.setapikey() before using this function.
GQLLET embedding = ai.embed("Introduction to graph databases") RETURN embedding, ai.dimension(embedding) AS dimensions
Result:
JSON{ "embedding": { "values": [ -0.0258026123046875, -0.0126800537109375, … 0.0162200927734375, -0.017486572265625 ] }, "dimensions": 1536 }
Generates embedding vectors for multiple texts in a single batched call. Supports up to 2048 inputs, internally chunked for efficiency. Null or non-string elements produce null vectors at the same index.
| Syntax | ai.embed_batch(<texts>) | ||
| Arguments | Name | Type | Description |
<texts> | LIST | A list of strings to generate embeddings for | |
| Return Type | LIST<VECTOR> | ||
GQLLET texts = ["graph databases", "machine learning", "data science"] RETURN ai.embed_batch(texts)
Result:
JSON[ { "values": [ -0.000690460205078125, 0.034271240234375, … 0.033294677734375, -0.00782012939453125 ] }, { "values": [ -0.0121917724609375, -0.0113372802734375, … -0.01312255859375, -0.0019989013671875 ] }, { "values": [ 0.0034503936767578125, -0.010650634765625, … 0.00691986083984375, 0.02203369140625 ] } ]