pg-graph — Apache AGE Graph Skills (Routing Table)
Use references as supplemental context, combined with your Apache AGE and openCypher knowledge. If reference guidance is incomplete, answer with appropriate caveats rather than inventing syntax.
This skill is the single home for graph work on PostgreSQL, covering the full lifecycle. The generic PostgreSQL skill (postgresql-best-practices) points here for anything involving Apache AGE, openCypher, ag_catalog, knowledge graphs, or ontology. Keep AGE specific guidance in this skill rather than duplicating it in the generic skill.
Lifecycle: construct then consume
- Derive an ontology from the user's structured or unstructured data, and run a human feedback loop before finalizing. See ontology-derivation.
- Build the graph by extracting, deduplicating, and MERGE loading into AGE using the finalized ontology. See extract-to-graph.
- Consume the graph with openCypher, natural language to Cypher, schema introspection, and graph augmented retrieval.
Construction uses only capabilities available today: agent driven extraction over the MCP query tools (works on any PostgreSQL with AGE), or the azure_ai extension for in-database work at scale on Azure. It does NOT depend on unreleased ai.* pipeline primitives. Never finalize an ontology without explicit user approval.
Prerequisites (verify before graph work)
- Apache AGE is an extension. Confirm it is installed and load it once per session before any Cypher call.
- On managed Azure Database for PostgreSQL (Flexible Server and Azure HorizonDB),
agemust be allowlisted inazure.extensionsand added toshared_preload_libraries, then created withCREATE EXTENSION IF NOT EXISTS age CASCADE;. Set both on Flexible Server via server parameters; on Azure HorizonDB via a parameter group connected to the cluster. Both auto-restart to apply. It cannot be enabled withALTER SYSTEM. AGE is preloaded on both, so do NOT runLOAD 'age';there (a non-superuser getsaccess to library "age" is not allowed). - Non superuser sessions must set
search_pathsoag_catalogis available but NOT first. UseSET search_path = public, ag_catalog;. Puttingag_catalogfirst makes ordinaryCREATE TABLEfail with permission denied for schemaag_catalog.
Key Constraints (what models get wrong)
| Fact | Detail |
|---|---|
| Cypher is wrapped in a function | Every query runs as SELECT * FROM ag_catalog.cypher('graph_name', $$ ... $$) AS (col agtype). It is not a bare statement. |
| Column definition list is required | The AS (col agtype) list must match the RETURN arity, and every returned column is typed agtype. |
| agtype casting | Scalars come back as agtype. Cast for SQL use rather than assuming a raw text or int is returned. State uncertainty about exact cast helpers instead of inventing function names. |
| search_path ordering | SET search_path = public, ag_catalog; (never ag_catalog first) for non superuser roles. |
| Graph must exist | Create the graph once with create_graph('graph_name') before MERGE or MATCH. |
| MERGE for idempotent load | Use MERGE on a stable business key to avoid duplicate vertices during repeated extraction. |
| Parameters | AGE Cypher does not accept host bind parameters inside $$...$$ the way SQL does. Interpolate safely on the server side or wrap the cypher call in SQL. Never string concatenate untrusted input. |
Routing Table
| Keyword triggers | Reference | When to use |
|---|---|---|
| derive ontology, suggest ontology, generate ontology, ontology from data, ontology from documents, propose ontology | ontology-derivation | Analyze structured or unstructured data, propose an ontology, and run a human feedback loop before finalizing |
| extract to graph, build graph from data, build knowledge graph, populate graph, extract entities to graph | extract-to-graph | Apply a finalized ontology: extract, deduplicate, and MERGE into the AGE graph |
| entity resolution, context dedup, deduplicate entities, canonicalize entities, merge duplicate entities | context-dedup | Resolve entity aliases using type, graph neighborhood, and source snippet, with scalable blocking and a persistent canonical map |
| apache age, opencypher, cypher(), create_graph, property graph, vertices and edges, MERGE node | opencypher-age-patterns | AGE setup, Cypher wrapping, MATCH/MERGE/CREATE patterns, indexing vertices and edges |
| text to cypher, natural language to cypher, english to cypher, generate cypher, nl to cypher | text-to-cypher | Turning a user question into a validated openCypher query and running it |
| graph schema, list vertex labels, edge labels, ag_label, describe graph | graph-schema-introspection | Discovering labels, edge types, and properties so generated Cypher is grounded |
| visualize graph, vs code graph, render the graph, graph explorer, see the graph, plot the graph, ms-ossdata.vscode-pgsql | text-to-cypher | Generate visualization-ready Cypher (full vertex/edge objects, disp_label, matched AS columns) for the PostgreSQL extension for VS Code graph explorer |
| graph rag, graph augmented, graph augmented retrieval, hybrid graph retrieval | graph-augmented-rag | Retrieval that combines vector similarity with graph traversal and reranking |
| explainability, traceability, provenance, why this recommendation, reasoning path, audit graph answer | graph-explainability | Make facts traceable to sources and recommendations explainable: provenance on vertices and edges, returned reasoning path, weakest link path confidence, and a reproducible reasoning trace log |
| graph semantic search, graph azure_ai embeddings, graph azure openai embeddings, enable azure_ai for graph, configure azure openai for graph | azure-ai-semantic-search | Enable and configure the azure_ai extension, prompt the user for endpoint/key/deployment, and generate embeddings for semantic search |
| cypher example, graph query example, worked graph example | examples | End to end worked examples spanning schema, query, and results |
Anti-Hallucination Rules
- Do NOT present a Cypher query as a bare statement. Always wrap it in
ag_catalog.cypher(...)with a column definition list. - Do NOT claim host bind parameters work inside the
$$...$$body. - Do NOT put
ag_catalogfirst insearch_path. - Do NOT enable
agewithALTER SYSTEMon managed Azure. Use theazure.extensions+shared_preload_librariesallowlist, set via server parameters (Flexible Server) or a parameter group connected to the cluster (Azure HorizonDB). - Verify labels and properties with schema introspection before generating Cypher against an unknown graph.
- State uncertainty about exact
agtypecast helpers rather than inventing function names. - Do NOT finalize a derived ontology without explicit user approval. Treat it as a proposal and run the feedback loop.
- Do NOT rely on unreleased
ai.*pipeline primitives. Use agent-driven extraction or theazure_aiextension over Apache AGE, both available today. - For semantic search, do NOT invent an Azure OpenAI endpoint, key, or embedding deployment name. Read current
azure_aisettings and ask the user for anything missing. See azure-ai-semantic-search. - Do NOT present a graph recommendation without its reasoning path, supporting evidence, and a confidence bounded by the weakest edge on the path. See graph-explainability.