RuVector implements a Neo4j-compatible Cypher query language with extensions for hyperedges.
-- Create nodes
CREATE (p:Person {name: 'Alice', age: 30})
-- Create relationships
CREATE (a:Person {name: 'Alice'})-[:KNOWS]->(b:Person {name: 'Bob'})
-- Pattern matching
MATCH (p:Person)-[:KNOWS]->(friend)
WHERE p.name = 'Alice'
RETURN friend.name
-- Hyperedges (N-ary relationships)
CREATE (a:Person)-[:ATTENDED]->(meeting:Meeting, room:Room, company:Company)Find patterns in the graph.
-- Simple node
MATCH (n:Person)
RETURN n
-- With relationship
MATCH (a:Person)-[:KNOWS]->(b:Person)
RETURN a.name, b.name
-- Variable-length paths
MATCH (a)-[*1..3]->(b)
RETURN a, b
-- Optional matching
OPTIONAL MATCH (p:Person)-[:OWNS]->(c:Car)
RETURN p.name, c.modelCreate new nodes and relationships.
-- Single node
CREATE (n:Person {name: 'Alice'})
-- Multiple labels
CREATE (n:Person:Employee {name: 'Bob'})
-- With relationship
CREATE (a:Person {name: 'Alice'})-[:FRIEND]->(b:Person {name: 'Bob'})Create if not exists, match if exists.
MERGE (p:Person {email: 'alice@example.com'})
ON CREATE SET p.created = timestamp()
ON MATCH SET p.lastSeen = timestamp()Update properties.
MATCH (p:Person {name: 'Alice'})
SET p.age = 31, p.updated = timestamp()Remove nodes and relationships.
-- Delete node (must have no relationships)
MATCH (p:Person {name: 'Temp'})
DELETE p
-- Delete node and all relationships
MATCH (p:Person {name: 'Temp'})
DETACH DELETE pProject results.
MATCH (p:Person)
RETURN p.name AS name, p.age
ORDER BY p.age DESC
SKIP 10
LIMIT 5Intermediate projection (query chaining).
MATCH (p:Person)
WITH p.name AS name, COUNT(*) AS count
WHERE count > 1
RETURN name, countFilter results.
MATCH (p:Person)
WHERE p.age > 21 AND p.city = 'NYC'
RETURN p
-- Pattern predicates
WHERE (p)-[:KNOWS]->(:Expert)RuVector extends Cypher with hyperedge support for N-ary relationships:
-- Create hyperedge (3+ nodes)
CREATE (author:Person)-[:WROTE]->(paper:Paper, journal:Journal, year:Year)
-- Match hyperedge
MATCH (a:Person)-[r:ATTENDED]->(meeting, room, company)
RETURN a.name, meeting.topic, room.number| Type | Operators |
|---|---|
| Arithmetic | +, -, *, /, %, ^ |
| Comparison | =, <>, <, >, <=, >= |
| Logical | AND, OR, NOT, XOR |
| String | STARTS WITH, ENDS WITH, CONTAINS |
| Null | IS NULL, IS NOT NULL |
| List | IN, [] (indexing) |
-- String
RETURN toUpper(name), toLower(name), trim(name), substring(name, 0, 5)
-- Numeric
RETURN abs(x), ceil(x), floor(x), round(x), sqrt(x)
-- Collections
RETURN size(list), head(list), tail(list), range(1, 10)
-- Type
RETURN type(r), labels(n), keys(n)MATCH (p:Person)
RETURN
COUNT(*) AS total,
AVG(p.age) AS avgAge,
MIN(p.age) AS minAge,
MAX(p.age) AS maxAge,
SUM(p.salary) AS totalSalary,
COLLECT(p.name) AS namesMATCH (p:Person)
RETURN p.name,
CASE
WHEN p.age < 18 THEN 'minor'
WHEN p.age < 65 THEN 'adult'
ELSE 'senior'
END AS category| Type | Example |
|---|---|
| Integer | 42, -17 |
| Float | 3.14, -2.5e10 |
| String | 'hello', "world" |
| Boolean | true, false |
| Null | null |
| List | [1, 2, 3], ['a', 'b'] |
| Map | {name: 'Alice', age: 30} |
-- Assign path to variable
MATCH p = (a:Person)-[:KNOWS*]->(b:Person)
RETURN p, length(p)
-- Path functions
RETURN nodes(p), relationships(p), length(p)- Use labels - Always specify node labels for faster lookups
- Index properties - Create indexes on frequently queried properties
- Limit results - Use
LIMITto avoid large result sets - Parameterize - Use parameters for values to enable query caching