pub struct VelesDatabase { /* private fields */ }Expand description
VelesDB database instance.
Thread-safe handle to a VelesDB database. Can be shared across threads.
Implementations§
Source§impl VelesDatabase
impl VelesDatabase
Sourcepub fn open_with_observer(
path: String,
observer: Arc<dyn MobileObserver>,
) -> Result<Arc<Self>, VelesError>
pub fn open_with_observer( path: String, observer: Arc<dyn MobileObserver>, ) -> Result<Arc<Self>, VelesError>
Opens or creates a database with a read-path MobileObserver attached.
The observer is consulted before every governed read (dense / text /
hybrid / sparse / multi-query search and VelesQL SELECT / MATCH):
returning MobileAccessDecision::Deny aborts the read with that
message and zero results, MobileAccessDecision::Allow runs it
unmodified. This is the mobile counterpart of the observer gate already
wired on server and Python (audit F-5.4, #1392).
§Arguments
path- Path to the database directory (will be created if needed)observer- A Kotlin/Swift implementation ofMobileObserver
§Errors
Returns an error if the path is invalid or cannot be accessed.
Sourcepub fn open_with_config(
path: String,
config_path: String,
) -> Result<Arc<Self>, VelesError>
pub fn open_with_config( path: String, config_path: String, ) -> Result<Arc<Self>, VelesError>
Opens or creates a database configured from a TOML file on disk.
The file is parsed with
VelesConfig::load_from_path_engine_only:
only the engine sections ([search]/[hnsw]/[storage]/[limits]/
[quantization]/[wal_batch]) are considered, any other top-level
table is dropped, and VELESDB_* environment variables still layer on
top of the filtered file. The database is then opened with
Database::open_with_config,
so every subsystem honours the loaded values instead of core defaults.
This is the mobile counterpart of the server/CLI --config wiring
(issue #1549). If the app ships its config as an in-memory string
(bundled asset, remote config), use
open_with_config_toml instead.
§Arguments
path- Path to the database directory (will be created if needed)config_path- Path to an existing TOML configuration file
§Errors
Fails fast — never falls back to defaults silently — if the config
file is missing, unreadable, not valid TOML, or fails validation
(typed as a VELES-009 configuration error), or if the database path
is invalid or cannot be accessed.
Sourcepub fn open_with_config_toml(
path: String,
config_toml: String,
) -> Result<Arc<Self>, VelesError>
pub fn open_with_config_toml( path: String, config_toml: String, ) -> Result<Arc<Self>, VelesError>
Opens or creates a database configured from an in-memory TOML string.
Same semantics as open_with_config but the
TOML is passed directly (parsed with
VelesConfig::from_toml_engine_only,
no environment-variable layer) — the most portable option on mobile,
where config often lives in a bundled asset or remote-config payload
rather than a standalone file.
§Arguments
path- Path to the database directory (will be created if needed)config_toml- TOML configuration string (engine sections only)
§Errors
Fails fast — never falls back to defaults silently — if config_toml
is not valid TOML or fails validation (typed as a VELES-009
configuration error), or if the database path is invalid or cannot be
accessed.
Sourcepub fn open_with_observer_and_config(
path: String,
observer: Arc<dyn MobileObserver>,
config_path: String,
) -> Result<Arc<Self>, VelesError>
pub fn open_with_observer_and_config( path: String, observer: Arc<dyn MobileObserver>, config_path: String, ) -> Result<Arc<Self>, VelesError>
Opens or creates a database with both a read-path MobileObserver
and a TOML configuration file.
Combines open_with_observer (read gate)
and open_with_config (engine config) on a
single handle via
Database::open_with_observer_and_config.
§Arguments
path- Path to the database directory (will be created if needed)observer- A Kotlin/Swift implementation ofMobileObserverconfig_path- Path to an existing TOML configuration file
§Errors
Same fail-fast semantics as open_with_config.
Sourcepub fn open_with_observer_and_config_toml(
path: String,
observer: Arc<dyn MobileObserver>,
config_toml: String,
) -> Result<Arc<Self>, VelesError>
pub fn open_with_observer_and_config_toml( path: String, observer: Arc<dyn MobileObserver>, config_toml: String, ) -> Result<Arc<Self>, VelesError>
Opens or creates a database with both a read-path MobileObserver
and an in-memory TOML configuration string.
Combines open_with_observer (read gate)
and open_with_config_toml (engine
config) on a single handle.
§Arguments
path- Path to the database directory (will be created if needed)observer- A Kotlin/Swift implementation ofMobileObserverconfig_toml- TOML configuration string (engine sections only)
§Errors
Same fail-fast semantics as
open_with_config_toml.
Sourcepub fn update_guardrails(&self, limits: MobileQueryLimits)
pub fn update_guardrails(&self, limits: MobileQueryLimits)
Updates query guardrail limits for every collection in this database.
This is a full replacement: all fields of limits are applied.
Sourcepub fn create_collection(
&self,
name: String,
dimension: u32,
metric: DistanceMetric,
) -> Result<(), VelesError>
pub fn create_collection( &self, name: String, dimension: u32, metric: DistanceMetric, ) -> Result<(), VelesError>
Creates a new collection with the specified parameters.
§Arguments
name- Unique name for the collectiondimension- Vector dimension (e.g., 384, 768, 1536)metric- Distance metric for similarity calculations
Sourcepub fn create_collection_with_storage(
&self,
name: String,
dimension: u32,
metric: DistanceMetric,
storage_mode: StorageMode,
) -> Result<(), VelesError>
pub fn create_collection_with_storage( &self, name: String, dimension: u32, metric: DistanceMetric, storage_mode: StorageMode, ) -> Result<(), VelesError>
Creates a new collection with custom storage mode for IoT/Edge devices.
§Arguments
name- Unique name for the collectiondimension- Vector dimensionmetric- Distance metricstorage_mode- Storage optimization (seeStorageMode)
§Storage Modes
- Full: Best recall, 4 bytes/dimension
- Sq8: 4x compression, ~1% recall loss (recommended for mobile)
- Binary: 32x compression, ~5-10% recall loss (for extreme constraints)
ProductQuantization: 8x-16x compression via trained codebooks (requires a training step before upserts)Rabitq: 32x compression with ~1-2% recall loss (1-bit with rotation + scalar correction)
Sourcepub fn create_metadata_collection(&self, name: String) -> Result<(), VelesError>
pub fn create_metadata_collection(&self, name: String) -> Result<(), VelesError>
Creates a metadata-only collection (no vectors).
Useful for storing reference data, lookups, or auxiliary information that doesn’t require vector similarity search.
§Arguments
name- Unique name for the collection
Sourcepub fn create_graph_collection(&self, name: String) -> Result<(), VelesError>
pub fn create_graph_collection(&self, name: String) -> Result<(), VelesError>
Creates a graph collection for knowledge graph workloads.
Creates a schemaless graph collection (no node embeddings).
For graph collections with node embeddings, use
create_graph_collection_with_embeddings.
§Arguments
name- Unique name for the collection
Sourcepub fn create_graph_collection_with_embeddings(
&self,
name: String,
dimension: u32,
metric: DistanceMetric,
) -> Result<(), VelesError>
pub fn create_graph_collection_with_embeddings( &self, name: String, dimension: u32, metric: DistanceMetric, ) -> Result<(), VelesError>
Creates a graph collection with node embeddings.
Nodes in this collection can store vector embeddings and support similarity search alongside graph traversal.
§Arguments
name- Unique name for the collectiondimension- Vector dimension for node embeddingsmetric- Distance metric for similarity calculations
Sourcepub fn get_collection(
&self,
name: String,
) -> Result<Option<Arc<VelesCollection>>, VelesError>
pub fn get_collection( &self, name: String, ) -> Result<Option<Arc<VelesCollection>>, VelesError>
Gets a vector collection by name.
Returns None if the collection does not exist.
Returns an error if the collection exists but is not a vector collection.
Graph collections are queried through execute_query
(VelesQL); metadata collections are not retrievable through this accessor.
Sourcepub fn list_collections(&self) -> Vec<String>
pub fn list_collections(&self) -> Vec<String>
Lists all collection names.
Sourcepub fn delete_collection(&self, name: String) -> Result<(), VelesError>
pub fn delete_collection(&self, name: String) -> Result<(), VelesError>
Deletes a collection by name.
Sourcepub fn train_pq(
&self,
collection_name: String,
config: PqTrainConfig,
) -> Result<String, VelesError>
pub fn train_pq( &self, collection_name: String, config: PqTrainConfig, ) -> Result<String, VelesError>
Sourcepub fn execute_query(
&self,
sql: String,
params_json: Option<String>,
) -> Result<QueryResult, VelesError>
pub fn execute_query( &self, sql: String, params_json: Option<String>, ) -> Result<QueryResult, VelesError>
Executes an arbitrary VelesQL query and returns structured results.
This is the primary entry point for mobile apps to run the full VelesQL surface: SELECT, INSERT, UPDATE, DELETE, MATCH, DDL (CREATE/DROP/ALTER/TRUNCATE), TRAIN QUANTIZER, SHOW, DESCRIBE, EXPLAIN, ANALYZE, and FLUSH.
§Arguments
sql- VelesQL query stringparams_json- Optional JSON object with query parameters (keys are bare names; use$namesyntax in SQL). PassNoneor"{}"when no parameters are needed.
§Returns
A QueryResult containing the result kind, rows (as JSON strings),
row count, and a human-readable status message.
§Example (Swift)
let result = try db.executeQuery(
sql: "SELECT * FROM docs LIMIT 10",
paramsJson: nil
)
for row in result.rows {
let json = try JSONSerialization.jsonObject(with: row.dataJson.data(using: .utf8)!)
print(json)
}Trait Implementations§
Source§impl<UT> LiftRef<UT> for VelesDatabase
impl<UT> LiftRef<UT> for VelesDatabase
type LiftType = Arc<VelesDatabase>
Source§impl<UT> LowerError<UT> for VelesDatabase
impl<UT> LowerError<UT> for VelesDatabase
Source§fn lower_error(obj: Self) -> RustBuffer
fn lower_error(obj: Self) -> RustBuffer
Source§impl<UT> LowerReturn<UT> for VelesDatabase
impl<UT> LowerReturn<UT> for VelesDatabase
Source§type ReturnType = <Arc<VelesDatabase> as LowerReturn<UniFfiTag>>::ReturnType
type ReturnType = <Arc<VelesDatabase> as LowerReturn<UniFfiTag>>::ReturnType
Source§fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
Source§fn handle_failed_lift(
error: LiftArgsError,
) -> Result<Self::ReturnType, RustCallError>
fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>
Source§impl<UT> TypeId<UT> for VelesDatabase
impl<UT> TypeId<UT> for VelesDatabase
Auto Trait Implementations§
impl !RefUnwindSafe for VelesDatabase
impl !UnwindSafe for VelesDatabase
impl Freeze for VelesDatabase
impl Send for VelesDatabase
impl Sync for VelesDatabase
impl Unpin for VelesDatabase
impl UnsafeUnpin for VelesDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);