neo4j-genai-plugin-skill
Use Neo4j GenAI Plugin ai.text.* functions and procedures for in-Cypher embedding generation, text completion, structured output, chat, tokenization, and batch ingestion. Covers ai.text.embed(), ai.text.embedBatch(), ai.text.completion(), ai.text.structuredCompletion(), ai.text.aggregateCompletion(), ai.text.chat(), ai.text.tokenCount(), ai.text.chunkByTokenLimit(), and provider configuration for OpenAI, Azure OpenAI, VertexAI, and Amazon Bedrock. Requires CYPHER 25. Replaces deprecated genai.vector.encode(). Use when writing pure-Cypher GraphRAG, embedding nodes in-graph, generating structured maps from prompts, or calling LLMs inside Cypher queries. Does NOT handle neo4j-graphrag Python library pipelines — use neo4j-graphrag-skill. Does NOT handle vector index creation/search — use neo4j-vector-index-skill.
NPX Install
npx skill4agent add neo4j-contrib/neo4j-skills neo4j-genai-plugin-skillTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →When to Use
- Generating embeddings inside Cypher without external Python ()
ai.text.embed() - Batch-embedding nodes/chunks during ingestion ()
ai.text.embedBatch() - Calling LLMs directly in Cypher for completions or GraphRAG ()
ai.text.completion() - Extracting structured JSON maps from LLM inside Cypher ()
ai.text.structuredCompletion() - Aggregating LLM summaries over grouped rows ()
ai.text.aggregateCompletion() - Stateful chat sessions in Cypher ()
ai.text.chat() - Counting tokens or chunking text by token limit (,
ai.text.tokenCount())ai.text.chunkByTokenLimit()
When NOT to Use
- Python-based GraphRAG pipelines (VectorCypherRetriever, HybridCypherRetriever) →
neo4j-graphrag-skill - Vector index CREATE / kNN search / SEARCH clause →
neo4j-vector-index-skill - GDS embeddings (FastRP, Node2Vec) →
neo4j-gds-skill - Fulltext / keyword search →
neo4j-cypher-skill
Prerequisites
ai.*// Per-query prefix (self-managed, no admin rights needed):
CYPHER 25 MATCH (n:Chunk) ...
// Per-database default (admin; applies to all sessions):
ALTER DATABASE neo4j SET DEFAULT LANGUAGE CYPHER 25- Aura: GenAI plugin enabled by default — no action needed
- Self-managed JAR: copy plugin JAR to directory
plugins/ - Docker:
--env NEO4J_PLUGINS='["genai"]'
Provider Config Quick Reference
ai.text.*configuration :: MAP| Provider string | Required keys | Notes |
|---|---|---|
| | |
| | |
| | |
| | Embedding only |
| | Completion only |
vendorOptions :: MAP{ dimensions: 1024 }$paramEmbedding
Single embed [2025.12]
CYPHER 25
MATCH (c:Chunk)
WHERE c.embedding IS NULL
WITH c
CALL {
WITH c
SET c.embedding = ai.text.embed(c.text, 'openai', {
token: $openaiKey,
model: 'text-embedding-3-small'
})
} IN TRANSACTIONS OF 500 ROWSai.text.embed()VECTORBatch embed procedure [2025.12]
CYPHER 25
MATCH (c:Chunk) WHERE c.embedding IS NULL
WITH collect(c) AS chunks
UNWIND chunks AS c
WITH c.text AS text, c AS node
CALL ai.text.embedBatch(text, 'openai', { token: $openaiKey, model: 'text-embedding-3-small' })
YIELD index, resource, vector
MATCH (c:Chunk {text: resource})
SET c.embedding = vectorCALL ai.text.embedBatch(resource, provider, config) YIELD index, resource, vectorList configured embed providers
CYPHER 25
CALL ai.text.embed.providers()
YIELD name, requiredConfigType, optionalConfigType, defaultConfig
RETURN name, requiredConfigTypeText Completion [2025.12]
CYPHER 25
RETURN ai.text.completion(
'Summarize: ' + $text,
'openai',
{ token: $openaiKey, model: 'gpt-4o-mini' }
) AS summarySTRINGAggregate completion — summarize across rows
CYPHER 25
MATCH (c:Chunk)-[:PART_OF]->(a:Article {id: $articleId})
RETURN ai.text.aggregateCompletion(
c.text,
'Summarize the following article chunks in 3 sentences',
'openai',
{ token: $openaiKey, model: 'gpt-4o-mini' }
) AS summaryvaluetoString()Pure-Cypher GraphRAG Pattern [2025.12]
CYPHER 25
WITH ai.text.embed($question, 'openai', { token: $openaiKey, model: 'text-embedding-3-small' }) AS qEmbedding
CALL db.index.vector.queryNodes('chunk_embedding', 10, qEmbedding) YIELD node AS chunk, score
MATCH (chunk)<-[:HAS_CHUNK]-(article:Article)
OPTIONAL MATCH path = shortestPath((article)-[*..3]-(other:Article))
WITH chunk, article, collect(DISTINCT other.title) AS related, score
ORDER BY score DESC LIMIT 5
WITH collect(chunk.text + '\n[Source: ' + article.title + ']') AS context, $question AS question
RETURN ai.text.completion(
'Answer based on context:\n' + reduce(s='', c IN context | s + c + '\n') + '\nQuestion: ' + question,
'openai',
{ token: $openaiKey, model: 'gpt-4o-mini' }
) AS answerStructured Output [2025.12]
MAPCYPHER 25
MATCH (p:Product {id: $productId})
WITH p,
ai.text.structuredCompletion(
'Extract key attributes from: ' + p.description,
{
type: 'object',
properties: {
category: { type: 'string' },
tags: { type: 'array', items: { type: 'string' } },
priceRange: { type: 'string', enum: ['budget', 'mid', 'premium'] }
},
required: ['category', 'tags', 'priceRange'],
additionalProperties: false
},
'openai',
{ token: $openaiKey, model: 'gpt-4o-mini' }
) AS extracted
SET p.category = extracted.category,
p.priceRange = extracted.priceRange
WITH p, extracted.tags AS tags
UNWIND tags AS tag
MERGE (t:Tag {name: tag})
MERGE (p)-[:TAGGED]->(t)Aggregate structured completion — extract across multiple rows
CYPHER 25
MATCH (:User {id: $userId})-[:ORDERED]->(o:Order)-[:CONTAINS]->(p:Product)
RETURN ai.text.aggregateStructuredCompletion(
p.name + ': ' + p.category,
'Build a shopping profile for this user',
{
type: 'object',
properties: {
preferredCategories: { type: 'array', items: { type: 'string' } },
spendingTier: { type: 'string', enum: ['economy', 'standard', 'premium'] }
},
required: ['preferredCategories', 'spendingTier']
},
'openai',
{ token: $openaiKey, model: 'gpt-4o-mini' }
) AS profileChat [2025.12]
// Start new conversation (chatId = null → new session)
CYPHER 25
WITH ai.text.chat(
'Hello, who are you?',
null,
'openai',
{ token: $openaiKey, model: 'gpt-4o-mini' }
) AS result
RETURN result.message AS reply, result.chatId AS sessionId
// Continue conversation (pass returned chatId)
CYPHER 25
WITH ai.text.chat(
'What did I just ask you?',
$chatId,
'openai',
{ token: $openaiKey, model: 'gpt-4o-mini' }
) AS result
RETURN result.message AS reply, result.chatId AS sessionIdMAP { message: STRING, chatId: STRING }chatIdTokenization & Chunking [2025.12]
// Count tokens before sending to LLM
CYPHER 25
RETURN ai.text.tokenCount($text, 'openai', { token: $openaiKey, model: 'gpt-4o-mini' }) AS tokenCount
// Chunk text by token limit (no external dependencies)
CYPHER 25
UNWIND ai.text.chunkByTokenLimit($longText, 512, 'gpt-4', 50) AS chunk
MERGE (c:Chunk { text: chunk })ai.text.chunkByTokenLimit(input, limit, model='gpt-4', overlap=0)modeloverlapWrite Gate
SET node.embedding = ai.text.embed(...)SET node.* = ai.text.structuredCompletion(...)- Count nodes first:
MATCH (c:Chunk) WHERE c.embedding IS NULL RETURN count(c) - Verify config with one test node before batch
- Use for batches > 1000 nodes
CALL { ... } IN TRANSACTIONS OF 500 ROWS - Require explicit confirmation before executing
Deprecated — Do NOT Use
| Old function | Replacement |
|---|---|
| |
| |
| |
Common Errors
| Error | Cause | Fix |
|---|---|---|
| Missing CYPHER 25 prefix OR plugin not installed | Add |
| Using | Upgrade Neo4j; ensure GenAI plugin loaded |
| Provider config map incomplete | Check required keys for provider (see table above) |
| Wrong model name or provider auth failed | Test with |
| Provider string typo (case-sensitive, lowercase) | Use |
| Chat only supported on openai/azure-openai | Switch to openai/azure-openai for chat |
Checklist
- prefix present on every ai.text.* query
CYPHER 25 - GenAI plugin installed (Aura: automatic; self-managed: JAR in plugins/)
- API key passed as , never as literal string
$param - key explicit in config (no silent defaults)
model - Provider string lowercase (,
'openai','vertexai')'bedrock-titan' - Bulk writes use ; count target nodes first
IN TRANSACTIONS OF 500 ROWS - replaced with
genai.vector.encode()[2025.12]ai.text.embed() - Chat sessions: store returned for continuation; only openai/azure-openai supported
chatId - Structured output schema uses to prevent hallucination keys
additionalProperties: false
References
- Full provider config — all required/optional keys per provider
- Official docs
- API reference