Skip to main content
Relyt ONE integrates Apache AGE as a built-in extension, supporting efficient graph data queries and operations using the Cypher query language.

Prerequisites

Before you begin, ensure you have:
  • Created a Relyt ONE instance
  • Connected to the database
For details on instance creation, user management, and connection methods, refer to the relevant documentation.

Overview

This guide covers:
  1. Creating and Using Graphs - Basic AGE usage
  2. Bulk Data Import - Importing existing table data into graphs

Example: Product Catalog Graph

Let’s model a basic product catalog using AGE. We’ll create a catalog containing collections (e.g., Spring/Summer and Fall/Winter), with each collection containing items. Items can have sub-items, and each item has its own properties, images, and attachments. Product Catalog Graph Model In this model:
  • Each entity (blue rectangle) converts to a Vertex (node)
  • Each relationship converts to an Edge
Naming Conventions:
  • Node labels: PascalCase (e.g., Catalog)
  • Relationships: UPPER_SNAKE_CASE (e.g., HAS_ATTRIBUTE)

Setup

Set Search Path

Add ag_catalog to your search path to simplify queries:

Create a Graph

Creating Graph Structure

You have two approaches:
  1. Dynamic Creation: Insert vertices and edges directly; the engine auto-creates definitions
  2. Pre-defined Structure: Create all vertex and edge definitions before inserting data
The first approach is faster but requires caution: you cannot query entities that don’t exist yet. The graph engine converts each vertex and edge to database tables. Querying a non-existent label will return an error.
For production use with a known structure, pre-define all vertices and edges before inserting data.

Create Vertex and Edge Labels

For our example graph:
Edge labels don’t specify which vertices they connect. Actual connections are determined by the data.

Writing Data

Create a Catalog Node

This creates a node with:
  • Label: Catalog
  • Property: code = "C001"
  • Additional property: name = "Apparel Catalog"

Using MERGE (UPSERT)

AGE doesn’t support custom indexes. Running the same CREATE query twice creates duplicate nodes. Use MERGE for upsert behavior:
This finds or creates a Catalog with code = "C001".
With MERGE, you cannot use SET in the same statement. Split into two commands:
Only include key properties in MERGE to avoid duplicates. Use MATCH + SET for additional properties.

Add a Collection

Create a Collection and connect it to the Catalog:
Notice the visual representation: (co)-[:BELONGS_TO]->(c) clearly shows a directed relationship.

Add Items

Add multiple items to the SS22 collection:

Update Items with Attributes

Add attributes as connected nodes:
Add another attribute:
Edges can have properties, making them first-class citizens in the graph.

Querying Graphs

Pattern Matching

Retrieve all items in catalog C001:

Variable-Length Paths

A more compact and powerful representation:
This returns all items connected to catalog C001 through any relationship path.
Use unconstrained path matching carefully. On large graphs, complexity can explode, impacting performance.

Retrieve Specific Properties

Get attributes for item ISS001:

Custom Return Values

Return a JSON object list:

Deleting Data

Remove Labels

Delete Edges

Delete Vertices

Delete Vertices with Edges

Deleting a vertex with edges will fail:
This will produce an error:
Use DETACH DELETE to remove both vertex and edges:

Drop a Graph

If the graph contains data, you’ll get an error. Use cascade to force deletion:

Bulk Data Import

For large datasets, inserting data one by one is inefficient. Instead, import data into relational tables first, then load into the graph.

Step 1: Create and Populate Tables

Catalog Table:
Collection Table:
Item Table:
Relationship Tables:

Step 2: Create Helper Functions

Step 3: Create Graph and Labels

Step 4: Import Vertex Data

Step 5: Import Edge Data

Step 6: Verify Data

Next Steps

This guide covers the basics of using Apache AGE with Relyt ONE. For in-depth Cypher concepts and detailed query syntax, visit the official Cypher Query Language documentation. You can also explore:
  • Advanced Cypher patterns and techniques
  • Graph algorithms and analytics
  • Performance optimization strategies
  • Building production graph applications