π Satori Rust SDK
This library allows you to easily and efficiently interact with the Satori database via WebSockets, supporting CRUD operations, real-time notifications, advanced queries, and graph-like relations.
β¨ Main Features
- Ultra-fast CRUD operations β‘
- Advanced queries using
field_arrayπ - Real-time notifications π’
- Graph-like relations (vertices and references) πΈοΈ
- Data encryption and decryption π
π Installation
Add the following to your Cargo.toml:
[]
= "0.1.4"
= { = "1.36", = ["full"] }
π Basic Usage
use Satori;
async
ποΈ CRUD Operations
Create Data
client.set.await?;
Read Data
let user = client.get.await?;
Modify a Field
client.put.await?;
Delete Data
client.delete.await?;
π§© Advanced Queries with field_array π
You can perform operations on multiple objects that meet certain conditions using the field_array field:
let results = client.get.await?;
field_arrayis an array of conditions{ "field": ..., "value": ... }.- You can combine it with
"one": trueto get only the first matching result.
π Real-time Notifications
Receive automatic updates when an object changes:
client.set_notify.await?;
πΈοΈ Relations and Graphs
You can create relationships between objects (vertices):
client.set_vertex.await?;
And traverse the graph with DFS:
client.dfs.await?;
Get all neighbors of an object:
client.get_vertex.await?;
Remove a specific neighbor:
client.delete_vertex.await?;
π Encryption and Security
Easily encrypt and decrypt data:
client.encrypt.await?;
client.decrypt.await?;
π¦ Array Manipulation Methods
Below are the available methods to manipulate arrays in the Satori database using the Rust client:
πΉ push
Adds a value to an existing array in an object.
client.push.await?;
πΉ pop
Removes the last element from an array in an object.
client.pop.await?;
πΉ splice
Modifies an array in an object (for example, to cut or replace elements).
client.splice.await?;
πΉ remove
Removes a specific value from an array in an object.
client.remove.await?;
## π€ AI Methods
### πΉ ann
Perform an Aproximate Nearest Neighbors search
```rust
client.ann(serde_json::json!({
"key": "user:123",
"top_k" : 5 //return the top 5 neighbors
})).await?;
πΉ query
Make a query to the db in natural language
client.query.await?;
πΉ ask
Ask questions about your data
client.ask.await?;
πΉ train
Train an embedding model with your data.
client.train.await?;
Notes on AI
In the functions where backend must be specified this parameter must passed with the following format: openai:model-name or ollama:model-name. If you're using OpenAI as your backend you must specify the OPENAI_API_KEY env variable. If backend isn't specified openai:gpt-4o-mini will be used as default.
The trained embedding model will be at the root of your db in a folder called satori_semantic_model.
You can train your embedding model manually whenever you want to but Satori will automatically fine-tune your model with any new updates and use this updated model for all emebedding operations.
π¦ Schema Struct (Data Model) β Rust
You can use the Schema struct to model your data in an object-oriented way:
use ;
let satori = connect.await.unwrap;
let mut user = new;
user.set.await.unwrap;
It includes useful methods such as:
-
set,delete,encrypt,decrypt,set_vertex,get_vertex,delete_vertex,dfs -
Array methods:
push,pop,splice,remove
π Complete Example
use Satori;
async
π§ Key Concepts
- key: Unique identifier of the object.
- type: Object type (e.g., 'user').
- field_array: Advanced filters for bulk operations.
- notifications: Subscription to real-time changes.
- vertices: Graph-like relationships between objects.
Responses
All responses obbey the following pattern:
{
data: any //the requested data if any
message: string //status message
type: string //SUCCESS || ERROR
}
AI responses obbey a different patern:
ask
{
response: string //response to the question
}
query
{
result: string //response from the operation made in the db
status: string //status
}
ann
{
results: array //response from the operation made in the db
}
π¬ Questions or Suggestions?
Feel free to open an issue or contribute! With β€οΈ from the Satori team.