overgraph 0.11.0

An absurdly fast embedded graph database. Pure Rust, sub-microsecond reads.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# Getting Started with OverGraph

This guide gets you up and running with OverGraph in Python, Node.js, or Rust. You'll open a database, create some nodes and edges, query neighbors, and run a vector search.

For full parameter documentation, see the [API Reference](api-reference.md).

## Install

**Python**
```bash
pip install overgraph
```

**Node.js**
```bash
npm install overgraph
```

**Rust**
```bash
cargo add overgraph
```

## Open a database

A database is a directory on disk. Pass a vector dimension if you want to use dense vector search.

**Python**
```python
from overgraph import OverGraph

db = OverGraph.open("./my-graph", dense_vector_dimension=3)
```

**Node.js**
```javascript
import { OverGraph } from 'overgraph';

const db = OverGraph.open('./my-graph', {
  denseVector: { dimension: 3 },
});
```

**Rust**
```rust
use overgraph::*;
use std::{collections::BTreeMap, path::Path};

let opts = DbOptions {
    dense_vector: Some(DenseVectorConfig {
        dimension: 3,
        metric: DenseMetric::Cosine,
        hnsw: HnswConfig::default(),
    }),
    ..Default::default()
};
let mut db = DatabaseEngine::open(Path::new("./my-graph"), &opts)?;
```

## Choose labels and edge labels

OverGraph uses labels to classify nodes and edge labels to classify edges. They are
ordinary strings at the public API boundary.

## Create nodes and edges

**Python**
```python
project_dense = [0.18, 0.71, 0.39]
project_sparse = [(101, 0.6), (407, 0.8)]

# Also accepts multiple labels: ["User", "Engineer"]
alice = db.upsert_node("User", "alice", props={"role": "engineer"})
bob = db.upsert_node("User", "bob")
project = db.upsert_node("Project", "atlas",
    dense_vector=project_dense,
    sparse_vector=project_sparse)

db.upsert_edge(alice, project, "WORKS_ON")
db.upsert_edge(bob, project, "WORKS_ON", weight=0.5)
```

**Node.js**
```javascript
const projectDense = [0.18, 0.71, 0.39];
const projectSparse = [{ dimension: 101, value: 0.6 }, { dimension: 407, value: 0.8 }];

// Also accepts multiple labels: ['User', 'Engineer']
const alice = db.upsertNode('User', 'alice', { props: { role: 'engineer' } });
const bob = db.upsertNode('User', 'bob');
const project = db.upsertNode('Project', 'atlas', {
  denseVector: projectDense,
  sparseVector: projectSparse,
});

db.upsertEdge(alice, project, 'WORKS_ON');
db.upsertEdge(bob, project, 'WORKS_ON', { weight: 0.5 });
```

**Rust**
```rust
let project_dense = vec![0.18_f32, 0.71, 0.39];
let project_sparse = vec![(101, 0.6_f32), (407, 0.8)];

// Also accepts multiple labels: &["User", "Engineer"]
let alice = db.upsert_node("User", "alice", UpsertNodeOptions {
    props: BTreeMap::from([("role".into(), PropValue::String("engineer".into()))]),
    ..Default::default()
})?;
let bob = db.upsert_node("User", "bob", UpsertNodeOptions::default())?;
let project = db.upsert_node("Project", "atlas", UpsertNodeOptions {
    dense_vector: Some(project_dense),
    sparse_vector: Some(project_sparse),
    ..Default::default()
})?;

db.upsert_edge(alice, project, "WORKS_ON", UpsertEdgeOptions::default())?;
db.upsert_edge(bob, project, "WORKS_ON", UpsertEdgeOptions { weight: 0.5, ..Default::default() })?;
```

Upsert APIs accept either a single label string or a label collection. Each live
`(label, key)` membership points at one node; if every supplied label/key membership
resolves to the same node, the upsert updates that node instead of creating a duplicate.

## Read data back

**Python**
```python
node = db.get_node(alice)
node = db.get_node_by_key("User", "alice")
nodes = db.get_nodes([alice, bob])       # batch read
```

**Node.js**
```javascript
const node = db.getNode(alice);
const node2 = db.getNodeByKey('User', 'alice');
const nodes = db.getNodes([alice, bob]);
```

**Rust**
```rust
let node = db.get_node(alice)?;
let node = db.get_node_by_key("User", "alice")?;
let nodes = db.get_nodes(&[alice, bob])?;
```

## Optional: use GQL Beta for query strings

GQL Beta is useful when a graph read or mutation is clearer as a GQL/Cypher-shaped string. This
example creates nodes, creates edges, then queries the graph with aggregation.

**Python**
```python
db.execute_gql(
    """
    CREATE (alice:User {key: 'gql-alice', role: 'engineer'}),
           (bob:User {key: 'gql-bob', role: 'designer'}),
           (project:Project {key: 'gql-atlas', name: 'Atlas'})
    RETURN alice.key AS alice, bob.key AS bob, project.name AS project
    """
)

db.execute_gql(
    """
    MATCH (alice:User {key: 'gql-alice'})
    MATCH (bob:User {key: 'gql-bob'})
    MATCH (project:Project {key: 'gql-atlas'})
    CREATE (alice)-[:WORKS_ON {since: 2026}]->(project),
           (bob)-[:WORKS_ON {since: 2026}]->(project)
    RETURN project.name AS project
    """
)

rows = db.execute_gql(
    """
    MATCH (u:User)-[r:WORKS_ON]->(p:Project)
    WHERE p.key = 'gql-atlas'
    WITH p.name AS project, count(*) AS contributors, collect(u.key) AS users
    RETURN project, contributors, users
    """
)

print(rows["rows"])
```

**Node.js**
```javascript
db.executeGql(
  `CREATE (alice:User {key: 'gql-alice', role: 'engineer'}),
          (bob:User {key: 'gql-bob', role: 'designer'}),
          (project:Project {key: 'gql-atlas', name: 'Atlas'})
   RETURN alice.key AS alice, bob.key AS bob, project.name AS project`
);

db.executeGql(
  `MATCH (alice:User {key: 'gql-alice'})
   MATCH (bob:User {key: 'gql-bob'})
   MATCH (project:Project {key: 'gql-atlas'})
   CREATE (alice)-[:WORKS_ON {since: 2026}]->(project),
          (bob)-[:WORKS_ON {since: 2026}]->(project)
   RETURN project.name AS project`
);

const rows = db.executeGql(
  `MATCH (u:User)-[r:WORKS_ON]->(p:Project)
   WHERE p.key = 'gql-atlas'
   WITH p.name AS project, count(*) AS contributors, collect(u.key) AS users
   RETURN project, contributors, users`
);

console.log(rows.rows);
```

**Rust**
```rust
db.execute_gql(
    "CREATE (alice:User {key: 'gql-alice', role: 'engineer'}), \
            (bob:User {key: 'gql-bob', role: 'designer'}), \
            (project:Project {key: 'gql-atlas', name: 'Atlas'}) \
     RETURN alice.key AS alice, bob.key AS bob, project.name AS project",
    &GqlParams::new(),
    &GqlExecutionOptions::default(),
)?;

db.execute_gql(
    "MATCH (alice:User {key: 'gql-alice'}) \
     MATCH (bob:User {key: 'gql-bob'}) \
     MATCH (project:Project {key: 'gql-atlas'}) \
     CREATE (alice)-[:WORKS_ON {since: 2026}]->(project), \
            (bob)-[:WORKS_ON {since: 2026}]->(project) \
     RETURN project.name AS project",
    &GqlParams::new(),
    &GqlExecutionOptions::default(),
)?;

let rows = db.execute_gql(
    "MATCH (u:User)-[r:WORKS_ON]->(p:Project) \
     WHERE p.key = 'gql-atlas' \
     WITH p.name AS project, count(*) AS contributors, collect(u.key) AS users \
     RETURN project, contributors, users",
    &GqlParams::new(),
    &GqlExecutionOptions::default(),
)?;
```

## Query neighbors

**Python**
```python
neighbors = db.neighbors(alice, direction="outgoing")
for n in neighbors:
    print(n.node_id, n.weight)
```

**Node.js**
```javascript
const neighbors = db.neighbors(alice, { direction: 'outgoing' });
for (const n of neighbors) {
  console.log(n.nodeId, n.weight);
}
```

**Rust**
```rust
let neighbors = db.neighbors(alice, &NeighborOptions::default())?;
for n in &neighbors {
    println!("{} {}", n.node_id, n.weight);
}
```

## Vector search

**Python**
```python
query_dense = [0.14, 0.74, 0.36]
query_sparse = [(101, 1.0)]

hits = db.vector_search("hybrid", k=10,
    dense_query=query_dense,
    sparse_query=query_sparse,
    scope_start_node_id=alice,
    scope_max_depth=3)

for hit in hits:
    print(hit.node_id, hit.score)
```

**Node.js**
```javascript
const queryDense = [0.14, 0.74, 0.36];
const querySparse = [{ dimension: 101, value: 1.0 }];

const hits = db.vectorSearch('hybrid', {
  k: 10,
  denseQuery: queryDense,
  sparseQuery: querySparse,
  scope: { startNodeId: alice, maxDepth: 3 },
});

hits.forEach(h => console.log(h.nodeId, h.score));
```

**Rust**
```rust
let query_dense = vec![0.14_f32, 0.74, 0.36];
let query_sparse = vec![(101, 1.0_f32)];

let hits = db.vector_search(&VectorSearchRequest {
    mode: VectorSearchMode::Hybrid,
    dense_query: Some(query_dense),
    sparse_query: Some(query_sparse),
    k: 10,
    label_filter: None,
    ef_search: None,
    scope: Some(VectorSearchScope {
        start_node_id: alice,
        max_depth: 3,
        direction: Direction::Outgoing,
        edge_label_filter: None,
        at_epoch: None,
    }),
    dense_weight: None,
    sparse_weight: None,
    fusion_mode: None,
})?;

for hit in &hits {
    println!("{} {:.4}", hit.node_id, hit.score);
}
```

## Optional: declare property indexes

Property queries work without any extra setup. If a property is hot in your workload, you can declare an optional equality or numeric range index for it. OverGraph will use the declaration-backed path when the index is `Ready`, and otherwise fall back to the same public query API.

Equality indexes use semantic numeric equality for finite scalar numbers, so signed integers, unsigned integers, and finite floats compare by exact numeric value. String equality and other non-numeric equality remain unchanged. Range indexes are domainless numeric indexes over finite scalar numeric values; non-finite floats, non-numeric values, arrays, and maps are excluded.

**Python**
```python
from overgraph import PropertyRangeBound

db.ensure_node_property_index("User", "role", "equality")
db.ensure_node_property_index("Project", "priority", "range")

user_ids = db.find_nodes("User", "role", "engineer")
priority_ids = db.find_nodes_range(
    "Project",
    "priority",
    PropertyRangeBound(1, domain="int"),
    PropertyRangeBound(5.0, domain="float"),
)
```

**Node.js**
```javascript
db.ensureNodePropertyIndex('User', 'role', 'equality');
db.ensureNodePropertyIndex('Project', 'priority', 'range');

const userIds = db.findNodes('User', 'role', 'engineer');
const priorityIds = db.findNodesRange(
  'Project',
  'priority',
  { value: 1, inclusive: true, domain: 'int' },
  { value: 5, inclusive: true, domain: 'float' },
);
```

**Rust**
```rust
db.ensure_node_property_index("User", "role", SecondaryIndexKind::Equality)?;
db.ensure_node_property_index(
    "Project",
    "priority",
    SecondaryIndexKind::Range,
)?;

let user_ids = db.find_nodes("User", "role", &PropValue::String("engineer".into()))?;
let lower = PropertyRangeBound::Included(PropValue::Int(1));
let upper = PropertyRangeBound::Included(PropValue::Float(5.0));
let priority_ids = db.find_nodes_range(
    "Project",
    "priority",
    Some(&lower),
    Some(&upper),
)?;
```

## Close

**Python**
```python
db.close()

# Or use a context manager:
with OverGraph.open("./my-graph") as db:
    db.upsert_node("User", "alice")
```

**Node.js**
```javascript
db.close();
```

**Rust**
```rust
db.close()?;
```

## Async

**Python** - use `AsyncOverGraph`:
```python
from overgraph import AsyncOverGraph

async with await AsyncOverGraph.open("./my-graph") as db:
    alice = await db.upsert_node("User", "alice")
    neighbors = await db.neighbors(alice)
```

**Node.js** - append `Async` to any method:
```javascript
const node = await db.getNodeAsync(alice);
const hits = await db.vectorSearchAsync('hybrid', { k: 10, denseQuery: query });
```

## Next steps

- [API Reference]api-reference.md - every method, parameter, type, and return value across all three languages
- [Architecture Overview]architecture-overview.md - how the storage engine works under the hood