Understanding vectors and embeddings in graph databases.
Vectors (or embeddings) are arrays of numbers that represent the semantic meaning of data. They enable:
How they work:
GQL// Example: Vector representation // "Introduction to Graph Databases" might become: // [0.12, -0.45, 0.78, 0.23, -0.89, 0.56, ...] // (typically 384 to 1536 dimensions)
Common use cases for vectors in graph databases:
Semantic Search
Find documents by meaning, not just keywords
Recommendation Systems
"Users who liked X also liked Y"
Knowledge Graph Enhancement
Connect entities based on semantic similarity
Duplicate Detection
Find near-duplicate content
Multi-modal Search
Search across text, images, and other media
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
Two ways to create vectors in GQL:
| Function | Syntax | Description |
|---|---|---|
| AI.VECTOR() | AI.VECTOR([n1, n2, ...]) | Create vector from array of numbers |
| AI.embed() | AI.embed(text, model?) | Generate embedding from text using AI |
Create vector from array:
GQLLET v = AI.VECTOR([0.1, 0.2, 0.3, 0.4, 0.5]) RETURN AI.DIMENSION(v) AS dimensions
| dimensions |
|---|
| 5 |
Generate embedding from text:
GQLLET embedding = AI.embed('Introduction to graph databases') RETURN AI.DIMENSION(embedding) AS dimensions
| dimensions |
|---|
| 1536 |
Store document with embedding:
GQLINSERT (:Document { title: 'Graph Database Tutorial', content: 'Graphs are powerful data structures...', embedding: AI.embed('Graph Database Tutorial: Graphs are powerful data structures...') })
Batch generate embeddings for existing documents:
GQLMATCH (d:Document) WHERE d.embedding IS NULL SET d.embedding = AI.embed(d.title + ' ' + d.content)
Use specific embedding model:
GQLMATCH (d:Document) SET d.embedding = AI.embed(d.content, 'text-embedding-3-small')