Skip to main content

LanceStorageGraph

Struct LanceStorageGraph 

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

Lance-based storage backend for ArrowSpace graph embeddings.

Stores dense and sparse matrices as Lance datasets using a columnar format (row, col, value for sparse; col_* for dense) schema for efficient random and columnar access.

Metadata must be seeded before any save_* call so the storage directory is initialized; the example below is executed as a doc-test on every cargo test run so it cannot go stale.

§Examples

use genegraph_storage::lance_storage_graph::LanceStorageGraph;
use genegraph_storage::metadata::GeneMetadata;
use genegraph_storage::traits::backend::StorageBackend;
use genegraph_storage::traits::metadata::Metadata;
use smartcore::linalg::basic::arrays::{Array, Array2};
use smartcore::linalg::basic::matrix::DenseMatrix;

let base = std::env::temp_dir().join(format!("genegraph_doc_{}", std::process::id()));
let storage = LanceStorageGraph::new(
    base.to_string_lossy().to_string(),
    "doc_example".to_string(),
);

// some 2D data
let dense: Vec<Vec<f64>> = vec![vec![0.1, 0.4], vec![0.5, 0.2], vec![0.03, 0.8]];
let (nitems, nfeatures) = (dense.len(), dense[0].len());
let data = DenseMatrix::<f64>::from_iterator(
    dense.iter().flatten().copied(),
    nitems,
    nfeatures,
    0,
);

// seed metadata FIRST to initialize the storage directory
let md = GeneMetadata::seed_metadata("doc_example", nitems, nfeatures, &storage)
    .await
    .unwrap();
let md_path = storage.save_metadata(&md).await.unwrap();

// your data is saved in an efficient Lance format
storage.save_dense("my_dataset", &data, &md_path).await.unwrap();

// Loading back
let loaded = storage.load_dense("my_dataset").await.unwrap();
assert_eq!(loaded.shape(), (nitems, nfeatures));

Implementations§

Source§

impl LanceStorageGraph

Source

pub fn new(base: String, name: String) -> Self

Creates a new Lance storage backend.

This is used for on-the-fly creation. For proper setup use Genefold<...>::seed.

§Arguments
  • base - Base directory path for all storage files
  • name - Name prefix for this storage instance
Source

pub async fn spawn( base_path: String, ) -> Result<(Self, GeneMetadata), StorageError>

Spawn a LanceStorage from an existing seeded directory (with metadata.json)

Source

pub fn scoped_generation(&self, generation: u64) -> Self

A handle over generation gen of this logical dataset: artifact paths resolve as {logical}__g{gen}_{key}.lance and the metadata path as {logical}__g{gen}_metadata.json — the per-generation commit pointer (#93, RFC #81-P5). The logical identity stays recoverable via crate::generations::logical_name.

Trait Implementations§

Source§

impl Clone for LanceStorageGraph

Source§

fn clone(&self) -> LanceStorageGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LanceStorageGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LanceStorage for LanceStorageGraph

Source§

async fn write_lance_batch_async( &self, uri: String, batch: RecordBatch, ) -> StorageResult<()>

Source§

async fn read_lance_all_batches_async( &self, uri: String, ) -> StorageResult<RecordBatch>

Source§

async fn save_primitive_column<T: ArrowPrimitiveType>( &self, key: &str, field_name: &str, values: Vec<T::Native>, md_path: &Path, ) -> StorageResult<()>
where Self: StorageBackend,

Writes a single-column primitive vector as a Lance dataset named <name>_<key>.lance and registers it in the metadata files map under key with filetype “vector” and shape (<len>, 1). Read more
Source§

impl StorageBackend for LanceStorageGraph

Source§

fn basepath_to_uri(&self) -> StorageResult<String>

Converts the base path for the store to a file:// URI for Lance.

Source§

async fn save_dense( &self, key: &str, matrix: &DenseMatrix<f64>, md_path: &Path, ) -> StorageResult<()>

Save dense matrix using Lance-optimized vector format.

Each row of the matrix becomes a FixedSizeList entry for efficient vector operations. This format is optimized for vector search and enables Lance’s full-zip encoding.

§Arguments
  • filename - any name
  • matrix - Dense matrix to save (N rows × F cols)
  • md_path - Metadata file path for validation
Source§

async fn load_dense(&self, key: &str) -> StorageResult<DenseMatrix<f64>>

Load dense matrix from Lance-optimized vector format.

Reads FixedSizeList vectors and reconstructs a column-major DenseMatrix.

§Arguments
  • filename - any name previously assigned
§Returns

Column-major DenseMatrix matching smartcore conventions

Source§

async fn load_dense_from_file( &self, path: &Path, ) -> StorageResult<DenseMatrix<f64>>

Load initial data using columnar format from a file path.

Async test helper that avoids any internal blocking runtimes.

Source§

async fn save_dense_to_file( data: &DenseMatrix<f64>, path: &Path, ) -> StorageResult<()>

Save dense matrix to file in columnar format (col_0, col_1, …, col_N)

Async test helper that avoids any internal blocking runtimes.

Source§

async fn save_centroid_map( &self, map: &[usize], md_path: &Path, ) -> StorageResult<()>

Save centroid_map (item-to-centroid assignments)

Source§

async fn load_centroid_map(&self) -> StorageResult<Vec<usize>>

Load centroid_map

Source§

async fn save_subcentroid_lambdas( &self, lambdas: &[f64], md_path: &Path, ) -> StorageResult<()>

Save subcentroid_lambdas (tau values for subcentroids)

Source§

async fn load_subcentroid_lambdas(&self) -> StorageResult<Vec<f64>>

Load subcentroid_lambdas

Source§

async fn save_subcentroids( &self, subcentroids: &DenseMatrix<f64>, md_path: &Path, ) -> StorageResult<()>

Save subcentroids (dense matrix)

Source§

async fn load_subcentroids(&self) -> StorageResult<Vec<Vec<f64>>>

Load subcentroids as Vec<Vec>

Source§

async fn save_item_norms( &self, item_norms: &[f64], md_path: &Path, ) -> StorageResult<()>

Save item norms vector

Source§

async fn load_item_norms(&self) -> StorageResult<Vec<f64>>

Load item norms vector

Source§

fn get_base(&self) -> String

Base directory of the instance
Source§

fn get_name(&self) -> String

Name of the instance
Source§

fn base_path(&self) -> PathBuf

Returns the base directory path.
Source§

fn metadata_path(&self) -> PathBuf

Returns the metadata path.
Source§

fn file_path(&self, key: &str) -> PathBuf

Compute the full Lance/parquet file path for a logical filetype.
Source§

async fn save_sparse( &self, key: &str, matrix: &CsMat<f64>, md_path: &Path, ) -> StorageResult<()>

Saves a sparse matrix. Requires metadata to exist.
Source§

async fn load_sparse(&self, key: &str) -> StorageResult<CsMat<f64>>

Loads a sparse matrix from storage.
Source§

async fn save_lambdas( &self, lambdas: &[f64], md_path: &Path, ) -> StorageResult<()>

Saves lambda eigenvalues. Requires metadata to exist.
Source§

async fn load_lambdas(&self) -> StorageResult<Vec<f64>>

Loads lambda eigenvalues from storage.
Source§

async fn save_vector( &self, key: &str, vector: &[f64], md_path: &Path, ) -> StorageResult<()>

save a generic f64 sequence
Source§

async fn save_index( &self, key: &str, vector: &[usize], md_path: &Path, ) -> StorageResult<()>

Save vectors that are not lambdas but indices.
Source§

async fn load_vector(&self, filename: &str) -> StorageResult<Vec<f64>>

Source§

async fn load_index(&self, filename: &str) -> StorageResult<Vec<usize>>

Load index or generic usize vector from storage.
Source§

async fn save_cluster_assignments( &self, assignments: &[Option<usize>], md_path: &Path, ) -> StorageResult<()>

Save cluster assignments (Vec<Option>)
Source§

async fn load_cluster_assignments(&self) -> StorageResult<Vec<Option<usize>>>

Load cluster assignments
Source§

fn exists(path: &str) -> (bool, Option<PathBuf>)

Returns true and the path to the metadata file if metadata file exists and is valid, false otherwise. This is used to avoid overwriting existing indexes.
Source§

fn path_to_uri(path: &Path) -> StorageResult<String>

Converts a full file path to a file:// URI for Lance. Read more
Source§

fn validate_initialized(&self, md_path: &Path) -> StorageResult<()>

Validates that the storage directory is properly initialized with metadata. Read more
Source§

fn to_dense_record_batch( &self, matrix: &DenseMatrix<f64>, ) -> Result<RecordBatch, StorageError>

Converts a dense matrix to a RecordBatch in vector format (Lance-optimized). Each row of the matrix becomes a single FixedSizeList entry. Read more
Source§

fn from_dense_record_batch( &self, batch: &RecordBatch, ) -> Result<DenseMatrix<f64>, StorageError>

Reconstructs a dense matrix from a RecordBatch in vector format. Read more
Source§

fn to_sparse_record_batch(&self, m: &CsMat<f64>) -> StorageResult<RecordBatch>

Converts a sparse CSR matrix to a RecordBatch in columnar format. Read more
Source§

fn from_sparse_record_batch( &self, batch: RecordBatch, expected_rows: usize, expected_cols: usize, ) -> StorageResult<CsMat<f64>>

Reconstructs a sparse CSR matrix from a RecordBatch in columnar format. Read more
Source§

async fn save_metadata(&self, metadata: &GeneMetadata) -> StorageResult<PathBuf>

Initializes storage by saving metadata. Must be called first.
Source§

async fn load_metadata(&self) -> StorageResult<GeneMetadata>

Loads metadata from storage.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.