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
impl Client
Sourcepub fn database(&self) -> Database
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).
Sourcepub fn create_vector_collection(
&self,
name: &str,
config: &VectorConfig,
) -> Result<()>
pub fn create_vector_collection( &self, name: &str, config: &VectorConfig, ) -> Result<()>
Create a new vector collection with the given configuration.
Sourcepub fn list_vector_collections(&self) -> Result<Vec<VectorCollectionInfo>>
pub fn list_vector_collections(&self) -> Result<Vec<VectorCollectionInfo>>
Return a list of all vector collections.
Sourcepub fn drop_vector_collection(&self, name: &str) -> Result<bool>
pub fn drop_vector_collection(&self, name: &str) -> Result<bool>
Drop a vector collection, returning true on success.
Sourcepub fn insert_vector(
&self,
collection: &str,
embedding: &[f32],
metadata: Option<&Value>,
) -> Result<u64>
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.
Sourcepub fn insert_text(
&self,
collection: &str,
text: &str,
metadata: Option<&Value>,
) -> Result<u64>
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.
Sourcepub fn vector_search(
&self,
collection: &str,
query: &[f32],
k: usize,
) -> Result<Vec<VectorSearchResult>>
pub fn vector_search( &self, collection: &str, query: &[f32], k: usize, ) -> Result<Vec<VectorSearchResult>>
Perform a k-nearest-neighbour vector search.
Sourcepub fn vector_search_text(
&self,
collection: &str,
query: &str,
k: usize,
) -> Result<Vec<VectorSearchResult>>
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).
Sourcepub fn vector_search_filtered(
&self,
collection: &str,
query: &[f32],
k: usize,
filter: &MetadataFilter,
) -> Result<Vec<VectorSearchResult>>
pub fn vector_search_filtered( &self, collection: &str, query: &[f32], k: usize, filter: &MetadataFilter, ) -> Result<Vec<VectorSearchResult>>
Perform a filtered k-NN search.
Sourcepub fn get_vector(
&self,
collection: &str,
id: u64,
) -> Result<Option<VectorDocument>>
pub fn get_vector( &self, collection: &str, id: u64, ) -> Result<Option<VectorDocument>>
Retrieve a single vector document by its numeric ID.
Sourcepub fn delete_vector(&self, collection: &str, id: u64) -> Result<bool>
pub fn delete_vector(&self, collection: &str, id: u64) -> Result<bool>
Delete a vector document by its numeric ID. Returns true if deleted.
Sourcepub fn vector_stats(&self, collection: &str) -> Result<VectorCollectionStats>
pub fn vector_stats(&self, collection: &str) -> Result<VectorCollectionStats>
Return statistics for a vector collection.
Sourcepub fn has_vector_support(&self) -> bool
pub fn has_vector_support(&self) -> bool
Returns true when the loaded native library includes vector support.