Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

The top-level KeraDB client.

§Example

use keradb_sdk::{connect, Client};
use serde_json::json;

let mut client = connect("mydb.ndb").unwrap();
let coll = client.database().collection("users");
let res = coll.insert_one(json!({"name": "Alice"})).unwrap();
println!("inserted: {}", res.inserted_id);
client.close();

Or use the Drop-based RAII via the with / scope pattern – the database is flushed and closed when Client is dropped.

Implementations§

Source§

impl Client

Source

pub fn database(&self) -> Database

Return the Database associated with this client.

The optional name argument is accepted for MongoDB API compatibility but is ignored (KeraDB is single-database per file).

Source

pub fn sync(&self) -> Result<()>

Sync all pending writes to disk.

Source

pub fn close(&mut self)

Close the database. Subsequent calls are safe (no-ops).

Source

pub fn create_vector_collection( &self, name: &str, config: &VectorConfig, ) -> Result<()>

Create a new vector collection with the given configuration.

Source

pub fn list_vector_collections(&self) -> Result<Vec<VectorCollectionInfo>>

Return a list of all vector collections.

Source

pub fn drop_vector_collection(&self, name: &str) -> Result<bool>

Drop a vector collection, returning true on success.

Source

pub fn insert_vector( &self, collection: &str, embedding: &[f32], metadata: Option<&Value>, ) -> Result<u64>

Insert a vector embedding with optional JSON metadata.

Returns the numeric ID assigned by KeraDB.

Source

pub fn insert_text( &self, collection: &str, text: &str, metadata: Option<&Value>, ) -> Result<u64>

Insert text (requires a lazy-embedding collection) and return its ID.

Perform a k-nearest-neighbour vector search.

Source

pub fn vector_search_text( &self, collection: &str, query: &str, k: usize, ) -> Result<Vec<VectorSearchResult>>

Perform a text-based similarity search (requires lazy-embedding collection).

Source

pub fn vector_search_filtered( &self, collection: &str, query: &[f32], k: usize, filter: &MetadataFilter, ) -> Result<Vec<VectorSearchResult>>

Perform a filtered k-NN search.

Source

pub fn get_vector( &self, collection: &str, id: u64, ) -> Result<Option<VectorDocument>>

Retrieve a single vector document by its numeric ID.

Source

pub fn delete_vector(&self, collection: &str, id: u64) -> Result<bool>

Delete a vector document by its numeric ID. Returns true if deleted.

Source

pub fn vector_stats(&self, collection: &str) -> Result<VectorCollectionStats>

Return statistics for a vector collection.

Source

pub fn has_vector_support(&self) -> bool

Returns true when the loaded native library includes vector support.

Trait Implementations§

Source§

impl Drop for Client

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Client

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.