satori-client 0.1.9

A WebSocket client for interacting with the Satori database.
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# πŸ“š Satori Rust SDK


A comprehensive Rust client library for interacting with the Satori database via WebSockets. Satori is a powerful in-memory database with support for CRUD operations, advanced queries, graph relationships, encryption, AI-powered semantic search, and mindspace conversations.

---

## ✨ Features


- **Ultra-fast CRUD operations** ⚑
- **Advanced queries** using `field_array` for conditional operations πŸ”
- **Real-time notifications** πŸ“’
- **Graph-like relations** (vertices and edges) πŸ•ΈοΈ
- **Data encryption and decryption** using AES πŸ”
- **Approximate Nearest Neighbor (ANN) search** for semantic similarity 🎯
- **Mindspace conversations** for AI-powered context-aware chat πŸ’¬

---

## πŸš€ Installation


Add the following to your `Cargo.toml`:

```toml
[dependencies]
satori-client = "0.1.8"
tokio = { version = "1.36", features = ["full"] }
serde_json = "1.0"
```

---

## 🏁 Quick Start


```rust
use satori_client::Satori;

#[tokio::main]

async fn main() -> anyhow::Result<()> {
    let client = Satori::connect(
        "username".to_string(),
        "password".to_string(),
        "ws://localhost:8000".to_string()
    ).await?;

    // Create an object
    client.set(serde_json::json!({
        "key": "user:john",
        "data": { "name": "John Doe", "email": "john@example.com", "age": 30 },
        "type": "user"
    })).await?;

    Ok(())
}
```

---

## πŸ“‹ Command Reference


All operations are invoked via WebSocket with a JSON request format. The client provides convenient methods for each operation.

### Base Request Structure


```json
{
  "command": "OPERATION_NAME",
  "id": "unique-request-id",
  "username": "optional-username",
  "password": "optional-password",
  "key": "object-key",
  "data": { ... }
}
```

---

## πŸ—ƒοΈ CRUD Operations


### SET - Create Data


Creates a new object in the database. If no key is provided, a UUID is automatically generated.

```rust
client.set(serde_json::json!({
    "key": "user:john",
    "data": { "name": "John Doe", "email": "john@example.com" },
    "type": "user",
    "expires": false,
    "expiration_time": -1
})).await?;
```

**Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `key` | string | No | Object key. If omitted, a UUID is generated |
| `data` | JSON | No | Object data content (default: `{}`) |
| `type` | string | No | Object class/type (default: `"normal"`) |
| `expires` | boolean | No | Whether object expires (default: `false`) |
| `expiration_time` | integer | No | Expiration timestamp in milliseconds |

---

### GET - Read Data


Retrieves one or more objects from the database. If key is `"*"`, returns all objects in memory.

```rust
// Get single object
let user = client.get(serde_json::json!({ "key": "user:john" })).await?;

// Get all objects
let all = client.get(serde_json::json!({ "key": "*" })).await?;

// Query by field
let results = client.get(serde_json::json!({
    "field_array": [
        { "field": "age", "value": 30 }
    ],
    "one": true,
    "max": 10
})).await?;
```

**Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `key` | string | No* | Object key to retrieve. Use `"*"` for all objects |
| `field_array` | array | No* | Query conditions for field-based search |
| `one` | boolean | No | Return only first match (default: `false`) |
| `max` | integer | No | Maximum results to return |
| `encryption_key` | string | No | Key to decrypt encrypted objects |

*Either `key` or `field_array` must be provided, but not both.

---

### PUT - Update Data


Updates one or more fields of an existing object.

```rust
client.put(serde_json::json!({
    "key": "user:john",
    "replace_field": "age",
    "replace_value": 31
})).await?;

// Batch update using field_array
client.put(serde_json::json!({
    "field_array": [{ "field": "type", "value": "user" }],
    "replace_field": "status",
    "replace_value": "active"
})).await?;
```

**Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `key` | string | No* | Object key to update |
| `field_array` | array | No* | Query to select objects for batch update |
| `replace_field` | string | Yes | Field name to update |
| `replace_value` | any | Yes | New value for the field |
| `encryption_key` | string | No | Key for encrypted objects |

*Either `key` or `field_array` must be provided.

---

### DELETE - Remove Data


Removes one or more objects from the database.

```rust
client.delete(serde_json::json!({ "key": "user:john" })).await?;

// Delete multiple objects matching a query
client.delete(serde_json::json!({
    "field_array": [{ "field": "status", "value": "inactive" }]
})).await?;
```

**Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `key` | string | No* | Object key to delete |
| `field_array` | array | No* | Query to select objects for deletion |

*Either `key` or `field_array` must be provided.

---

## πŸ“¦ Array Manipulation


### PUSH - Add to Array


Appends a value to an array field within an object.

```rust
client.push(serde_json::json!({
    "key": "user:john",
    "array": "tags",
    "value": "premium"
})).await?;
```

### POP - Remove Last from Array


Removes and returns the last element from an array field.

```rust
client.pop(serde_json::json!({
    "key": "user:john",
    "array": "notifications"
})).await?;
```

### SPLICE - Remove First from Array


Removes the first element from an array field.

```rust
client.splice(serde_json::json!({
    "key": "user:john",
    "array": "notifications"
})).await?;
```

### REMOVE - Remove Specific Value


Removes a specific value from an array field by finding and removing the first matching element.

```rust
client.remove(serde_json::json!({
    "key": "user:john",
    "array": "tags",
    "value": "premium"
})).await?;
```

**Common Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `key` | string | No* | Object key |
| `field_array` | array | No* | Query for batch operation |
| `array` | string | Yes | Name of the array field |
| `value` | any | Yes* | Value to add/remove |
| `encryption_key` | string | No | Key for encrypted objects |

*Required for PUSH and REMOVE; not required for POP and SPLICE.

---

## πŸ” Encryption


### ENCRYPT


Encrypts the data field of an object using AES encryption.

```rust
client.encrypt(serde_json::json!({
    "key": "user:john",
    "encryption_key": "secret-key-123"
})).await?;
```

### DECRYPT


Decrypts an encrypted object's data using the provided encryption key.

```rust
client.decrypt(serde_json::json!({
    "key": "user:john",
    "encryption_key": "secret-key-123"
})).await?;
```

---

## πŸ•ΈοΈ Graph Operations


### SET_VERTEX


Adds vertices (connections) to an object for graph relationships.

```rust
// Simple vertex
client.set_vertex(serde_json::json!({
    "key": "user:john",
    "vertex": "user:jane"
})).await?;

// Vertex with relation
client.set_vertex(serde_json::json!({
    "key": "user:john",
    "vertex": { "vertex": "user:jane", "relation": "friend", "weight": 1.0 }
})).await?;

// Multiple vertices
client.set_vertex(serde_json::json!({
    "key": "user:john",
    "vertex": ["user:jane", "user:alice"]
})).await?;
```

### GET_VERTEX


Retrieves all vertices from an object.

```rust
let vertices = client.get_vertex(serde_json::json!({
    "key": "user:john"
})).await?;
```

### DELETE_VERTEX


Removes a specific vertex from an object.

```rust
client.delete_vertex(serde_json::json!({
    "key": "user:john",
    "vertex": "user:jane"
})).await?;
```

### DFS - Depth-First Search


Traverses the graph starting from a given node using depth-first search.

```rust
let results = client.dfs(serde_json::json!({
    "node": "user:john",
    "relation": "friend"
})).await?;
```

### GRAPH_BFS - Breadth-First Search


Returns all nodes reachable from a starting node using breadth-first search.

```rust
let results = client.graph_bfs(serde_json::json!({
    "node": "user:john"
})).await?;
```

### GRAPH_DFS - Graph Depth-First Search


Returns all nodes reachable from a starting node using depth-first search.

```rust
let results = client.graph_dfs(serde_json::json!({
    "node": "user:john"
})).await?;
```

### GRAPH_SHORTEST_PATH


Finds the shortest path between a start node and end node using Dijkstra's algorithm.

```rust
let path = client.graph_shortest_path(serde_json::json!({
    "node": "user:john",
    "target": "post:123"
})).await?;
```

### GRAPH_CONNECTED_COMPONENTS


Identifies all connected components in the graph (groups of nodes where each node is reachable from any other node in the group).

```rust
let components = client.graph_connected_components(serde_json::json!({
    "id": "req-001"
})).await?;
```

### GRAPH_SCC - Strongly Connected Components


Identifies strongly connected components using Tarjan's algorithm.

```rust
let scc = client.graph_scc(serde_json::json!({
    "id": "req-001"
})).await?;
```

### GRAPH_DEGREE_CENTRALITY


Calculates the degree centrality (number of connections) for each node in the graph.

```rust
let centrality = client.graph_degree_centrality(serde_json::json!({
    "id": "req-001"
})).await?;
```

### GRAPH_CLOSENESS_CENTRALITY


Calculates closeness centrality for each node, which measures how close a node is to all other nodes.

```rust
let centrality = client.graph_closeness_centrality(serde_json::json!({
    "id": "req-001"
})).await?;
```

### GRAPH_CENTROID


Finds the node with the highest closeness centrality (the most central node in the graph).

```rust
let centroid = client.graph_centroid(serde_json::json!({
    "id": "req-001"
})).await?;
```

---

## πŸ€– AI Operations


### ANN / GET_SIMILAR


Performs approximate nearest neighbor search to find semantically similar objects using vector embeddings.

```rust
// Search by vector
let similar = client.ann(serde_json::json!({
    "vector": [0.1, 0.2, 0.3, ...],
    "k": 10,
    "ef": 25
})).await?;

// Search by existing object's embedding
let similar = client.get_similar(serde_json::json!({
    "key": "user:john",
    "use": "embedding",
    "k": 10
})).await?;
```

**Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `vector` | array | No* | Query vector as array of floats |
| `key` | string | No* | Use embedding from existing object |
| `k` | integer | No | Number of neighbors to return (default: 5) |
| `ef` | integer | No | Search width parameter (default: 25) |
| `use` | string | No | For key-based search: `"data"` or `"embedding"` |

*Either `vector` or `key` must be provided.

---

### ASK


Uses AI to answer complex questions about the database. The system automatically gathers relevant context.

```rust
let response = client.ask(serde_json::json!({
    "question": "Which user has the most posts?",
    "session": "global",
    "backend": "ollama"
})).await?;
```

**Note:** This operation requires a valid license.

---

## πŸ’¬ Mindspace Operations


Mindspaces provide cognitive contexts for AI-powered conversations and semantic operations.

### SET_MINDSPACE / CREATE_MINDSPACE


Creates a new mindspace.

```rust
let mindspace_id = client.set_mindspace(serde_json::json!({
    "mindspace_id": "conversation-1"
})).await?;

// Or use alias
let mindspace_id = client.create_mindspace(serde_json::json!({
    "mindspace_id": "conversation-1"
})).await?;
```

### DELETE_MINDSPACE


Removes a mindspace and all its associated context.

```rust
client.delete_mindspace(serde_json::json!({
    "mindspace_id": "conversation-1"
})).await?;
```

### CHAT_MINDSPACE


Sends a message to a mindspace and receives an AI-generated response. The mindspace maintains conversation context.

```rust
let response = client.chat_mindspace(serde_json::json!({
    "mindspace_id": "conversation-1",
    "message": "What do you know about users?"
})).await?;
```

### LECTURE_MINDSPACE


Imports text corpus into a mindspace for semantic search and context retrieval.

```rust
client.lecture_mindspace(serde_json::json!({
    "mindspace_id": "conversation-1",
    "corpus": "User John Doe is a software engineer who specializes in Rust and distributed systems..."
})).await?;
```

---

## πŸ“Š Analytics Operations


### GET_OPERATIONS


Returns a log of recent database operations.

```rust
let operations = client.get_operations().await?;
```

### GET_ACCESS_FREQUENCY


Returns the query count (access frequency) for a specific object.

```rust
let frequency = client.get_access_frequency(serde_json::json!({
    "key": "user:john"
})).await?;
```

---

## πŸ”” Real-time Notifications


Receive automatic updates when an object changes:

```rust
client.set_notify("user:john", |data| {
    println!("User updated! {:?}", data);
}).await?;
```

---

## πŸ“ Response Format


All successful responses follow this general structure:

```json
{
  "type": "SUCCESS",
  "message": "OK",
  "id": "request-id",
  "key": "optional-key",
  "data": { ... }
}
```

Error responses:

```json
{
  "type": "ERROR",
  "message": "Error description",
  "id": "request-id"
}
```

---

## 🧠 Key Concepts


| Concept | Description |
|---------|-------------|
| **key** | Unique identifier of the object |
| **type** | Object type (e.g., 'user', 'post') |
| **data** | The actual content stored in the object |
| **field_array** | Advanced filters for conditional operations |
| **vertices** | Graph-like relationships between objects |
| **encryption_key** | Key used for AES encryption/decryption |
| **mindspace** | Cognitive context for AI conversations |

---

## 🀝 Contributing


Questions or suggestions? Feel free to open an issue or contribute!

---

Made with ❀️ from the Satori team