Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/jbarrasa/goingmeta/llms.txt

Use this file to discover all available pages before exploring further.

Session 17 of Going Meta, broadcast on June 1, 2023, demonstrates a live loop between OpenAI’s Completions and Chat APIs and a Neo4j knowledge graph. Jesus Barrasa shows how to ask an LLM a factual question, receive the answer serialised as RDF Turtle (using schema.org and Wikidata URIs), and immediately import that RDF back into Neo4j using neosemantics — all from within a single Cypher statement powered by APOC.

What You’ll Learn

  • How to call OpenAI directly from Cypher using apoc.ml.openai.chat and apoc.ml.openai.completion
  • How to initialise a Neo4j database for RDF ingestion with neosemantics (n10s)
  • How to chain an OpenAI call with an n10s.rdf.preview.inline or import call in one query
  • How RDF-ified LLM output produces a queryable, linkable knowledge graph

Prerequisites

APOC Library

APOC must be installed and apoc.ml.openai.* procedures must be enabled in your Neo4j instance.

neosemantics (n10s)

Install the n10s plugin to enable RDF import/export procedures in Neo4j.

Step-by-Step Walkthrough

1

Initialise the database for RDF

Before importing any RDF you must create the uniqueness constraint and initialise the graph configuration:
CREATE CONSTRAINT n10s_unique_uri FOR (r:Resource) REQUIRE r.uri IS UNIQUE;

CALL n10s.graphconfig.init();
Without this step, any subsequent RDF import call will fail with "A Graph Config is required for RDF importing procedures to run".
2

Prompt ChatGPT interactively

The session starts with a sequence of manual ChatGPT prompts to explore what the LLM knows about Rafa Nadal’s commercial endorsements:
what commercial products are associated with Rafa Nadal?

provide the answer in JSON

produce a cypher statement to read that json and create a graph in neo4j

can you describe the same thing in cypher statements so I can populate my knowledge graph with them?

provide the list of commercial products associated with Rafa Nadal as RDF

now using schema.org as vocabulary

produce a cypher statement to import the previous rdf into neo4j using neosemantics (n10s)

when running that i'm getting this error "A Graph Config is required for RDF importing procedures to run" can you help?

regenerate the RDF using wikidata identifiers (uris)

add the wikidata id also for Rafa Nadal

provide some facts about Banco Sabadell as RDF using wikidata ids and schema.org vocabulary
This iterative prompting shows how the LLM can be guided to produce graph-ready RDF output.
3

Call OpenAI from Cypher with apoc.ml.openai.chat

Set your API key and message array as Cypher parameters, then invoke the chat procedure:
:param apiKey: "your-open-ai-key-..."

:param prompt: [
  {role:"system", content:"Provide answers in RDF serialised as Turtle. Use schema.org and wikidata ids for resources"},
  {role:"user", content:"What brands are associated with Rafa Nadal?"}
]

CALL apoc.ml.openai.chat($prompt, $apiKey) YIELD value
The value map contains the full API response including the generated RDF in the choices array.
4

Chain completion + RDF import in one statement

The most powerful pattern combines an OpenAI completion call with an inline RDF preview — all in a single Cypher pipeline:
CALL apoc.ml.openai.completion(
  'What are the top 3 most populated cities in the UK. Answer in RDF Turtle and use schema.org and wikidata uris',
  $apiKey,
  { max_tokens: 300 }
) YIELD value
WITH value.choices[0].text AS rdf
CALL n10s.rdf.preview.inline(rdf, "Turtle") YIELD nodes, relationships
RETURN *
Replace n10s.rdf.preview.inline with n10s.rdf.import.inline to persist the triples into the graph rather than just previewing them.

Key Concepts

APOC ML Procedures

apoc.ml.openai.chat and apoc.ml.openai.completion expose OpenAI’s API directly inside Cypher queries, eliminating the need for external Python glue code.

RDF as the Bridge

Asking the LLM to respond in RDF Turtle (with schema.org and Wikidata URIs) means the output is immediately importable into any n10s-enabled Neo4j database.

Wikidata URIs

Using Wikidata identifiers ensures that entities created by the LLM can be linked to the broader Linked Data web and to existing nodes in your graph.

Iterative Prompting

The session demonstrates how successive prompt refinements — adding JSON format, RDF format, specific vocabularies — improve the graph-readiness of LLM output.

Resources

Watch the Recording

Full session recording on YouTube — June 1, 2023.

Session Code

All queries and prompts from this session on GitHub.

Build docs developers (and LLMs) love