Cypher Overview
LatticeDB uses the Cypher query language for graph operations. Cypher is a declarative language where you describe patterns to match and operations to perform, rather than specifying how to execute them.
Syntax at a Glance
Nodes are written in parentheses, edges in square brackets:
-- Match a pattern
MATCH (person:Person)-[:KNOWS]->(friend:Person)
WHERE person.name = "Alice"
RETURN friend.name
Supported Clauses
| Clause | Purpose |
|---|---|
| MATCH | Find patterns in the graph |
| WHERE | Filter results with conditions |
| RETURN | Specify output columns |
| CREATE | Create nodes and edges |
| SET | Update properties and labels |
| DELETE | Remove nodes and edges |
| REMOVE | Remove properties and labels |
| MERGE | Match or create a pattern |
| WITH | Chain query parts, pipe results |
| UNWIND | Expand lists into rows |
| ORDER BY | Sort results |
| LIMIT | Limit number of results |
| SKIP | Skip first N results |
LatticeDB Extensions
LatticeDB extends Cypher with two operators for search:
Vector Distance (<=>)
Find nodes with similar embeddings:
MATCH (chunk:Chunk)
WHERE chunk.embedding <=> $query_vector < 0.5
RETURN chunk.text
ORDER BY chunk.embedding <=> $query_vector
See Vector Search for details.
Full-Text Search (@@)
Search indexed text content:
MATCH (doc:Document)
WHERE doc.content @@ "neural networks"
RETURN doc.title
See Full-Text Search for details.
Expressions
Operators
| Category | Operators |
|---|---|
| Comparison | =, <>, <, <=, >, >= |
| Logical | AND, OR, NOT, XOR |
| Arithmetic | +, -, *, /, %, ^ |
| String | CONTAINS, STARTS WITH, ENDS WITH |
| Null | IS NULL, IS NOT NULL |
| Search | <=> (vector distance), @@ (full-text) |
Functions
| Function | Description |
|---|---|
id(node) | Get node ID |
coalesce(a, b, ...) | Return first non-null value |
abs(x) | Absolute value |
size(list) | List length |
toInteger(x) | Convert to integer |
toFloat(x) | Convert to float |
See Functions for details.
Aggregations
| Function | Description |
|---|---|
count(x) | Count values |
sum(x) | Sum values |
avg(x) | Average values |
min(x) | Minimum value |
max(x) | Maximum value |
collect(x) | Collect into list |
See Aggregations for details.
Parameters
Use $name syntax to pass values safely:
MATCH (n:Person) WHERE n.name = $name RETURN n
See Parameters for language-specific binding.