Skip to content

Commit 9f25ffd

Browse files
committed
format code
1 parent 44c8db7 commit 9f25ffd

6 files changed

Lines changed: 32 additions & 22 deletions

File tree

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ grpc = { path = "crates/grpc" }
5151
http = { path = "crates/http" }
5252
index = { path = "crates/index" }
5353
server = { path = "crates/server" }
54-
storage = { path = "crates/storage" }
5554
snapshot = { path = "crates/snapshot" }
55+
storage = { path = "crates/storage" }
5656
tui = { path = "crates/tui" }

‎crates/api/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license.workspace = true
99
[dependencies]
1010
defs.workspace = true
1111
index.workspace = true
12+
snapshot.workspace = true
1213
storage.workspace = true
1314
tempfile.workspace = true
1415
uuid.workspace = true
15-
snapshot.workspace = true

‎crates/defs/src/types.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct IndexedVector {
4747
pub vector: DenseVector,
4848
}
4949

50-
#[derive(Debug, Serialize , Deserialize, Copy, Clone)]
50+
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
5151
pub enum Similarity {
5252
Euclidean,
5353
Manhattan,

‎crates/index/Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ edition.workspace = true
77
license.workspace = true
88

99
[dependencies]
10+
bincode.workspace = true
1011
defs.workspace = true
1112
rand.workspace = true
12-
uuid.workspace = true
13-
bincode.workspace = true
1413
serde.workspace = true
1514
storage.workspace = true
15+
uuid.workspace = true

‎crates/index/src/hnsw/serialize.rs‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ use defs::{DbError, Dimension, PointId, Similarity};
44
use serde::{Deserialize, Serialize};
55
use storage::StorageEngine;
66

7-
use crate::{IndexSnapshot, IndexType, SerializableIndex, hnsw::{HNSW_MAGIC_BYTES, HnswIndex, types::{LevelGenerator, Node, PointIndexation}}};
7+
use crate::{
8+
IndexSnapshot, IndexType, SerializableIndex,
9+
hnsw::{
10+
HNSW_MAGIC_BYTES, HnswIndex,
11+
types::{LevelGenerator, Node, PointIndexation},
12+
},
13+
};
814

915
#[repr(packed)]
1016
#[derive(Serialize, Deserialize)]
11-
pub struct HnswMetadataPack{
17+
pub struct HnswMetadataPack {
1218
pub ef_construction: usize,
1319
pub data_dimension: Dimension,
1420
pub ef: usize,
@@ -26,7 +32,6 @@ pub struct HnswIndexPack {
2632
pub level_scale: f64,
2733
}
2834

29-
3035
impl SerializableIndex for HnswIndex {
3136
fn serialize_topology(&self) -> Result<Vec<u8>, DbError> {
3237
let mut buffer = Vec::new();
@@ -42,7 +47,8 @@ impl SerializableIndex for HnswIndex {
4247
level_scale: self.index.level_generator.level_scale,
4348
};
4449

45-
let index_bytes = bincode::serialize(&index_pack).map_err(|e| DbError::SerializationError(e.to_string()))?;
50+
let index_bytes = bincode::serialize(&index_pack)
51+
.map_err(|e| DbError::SerializationError(e.to_string()))?;
4652
buffer.extend(index_bytes);
4753

4854
return Ok(buffer);
@@ -54,10 +60,11 @@ impl SerializableIndex for HnswIndex {
5460
ef_construction: self.ef_construction,
5561
data_dimension: self.data_dimension,
5662
ef: self.ef,
57-
similarity: self.similarity
63+
similarity: self.similarity,
5864
};
5965

60-
let metadata_bytes = bincode::serialize(&index_pack).map_err(|e| DbError::SerializationError(e.to_string()))?;
66+
let metadata_bytes = bincode::serialize(&index_pack)
67+
.map_err(|e| DbError::SerializationError(e.to_string()))?;
6168
buffer.extend(metadata_bytes);
6269
return Ok(buffer);
6370
}
@@ -76,15 +83,18 @@ impl SerializableIndex for HnswIndex {
7683
fn populate_vectors(&mut self, storage: &dyn StorageEngine) -> Result<(), DbError> {
7784
// assumes index topology is restored
7885
for id in self.index.nodes.keys() {
79-
let vec = storage.get_vector(*id)?.ok_or(DbError::SerializationError(format!("Failed to locate vector for id: {} in storage", id)))?;
86+
let vec = storage
87+
.get_vector(*id)?
88+
.ok_or(DbError::SerializationError(format!(
89+
"Failed to locate vector for id: {} in storage",
90+
id
91+
)))?;
8092
self.cache.insert(*id, vec);
8193
}
8294
Ok(())
8395
}
8496
}
8597

86-
87-
8898
impl HnswIndex {
8999
pub fn deserialize(
90100
IndexSnapshot {
@@ -110,7 +120,7 @@ impl HnswIndex {
110120
DbError::SerializationError(format!("Failed to deserialize HNSW Metadata: {}", e))
111121
})?;
112122

113-
let index_pack : HnswIndexPack = bincode::deserialize(topology_b).map_err(|e| {
123+
let index_pack: HnswIndexPack = bincode::deserialize(topology_b).map_err(|e| {
114124
DbError::SerializationError(format!("Failed to deserialize HNSW Index: {}", e))
115125
})?;
116126

@@ -121,24 +131,23 @@ impl HnswIndex {
121131
points_by_layer: index_pack.points_by_layer,
122132
entry_point: index_pack.entry_point,
123133
nodes: HashMap::new(),
124-
level_generator: LevelGenerator{
125-
level_scale: index_pack.level_scale
126-
}
134+
level_generator: LevelGenerator {
135+
level_scale: index_pack.level_scale,
136+
},
127137
};
128138

129139
// restore nodes hashmap
130140
for i in index_pack.nodes {
131141
hnsw_index_restored.nodes.insert(i.id, i);
132142
}
133143

134-
135144
let hnsw = HnswIndex {
136-
ef_construction : metadata.ef_construction,
145+
ef_construction: metadata.ef_construction,
137146
data_dimension: metadata.data_dimension,
138147
ef: metadata.ef,
139148
cache: HashMap::new(),
140149
similarity: metadata.similarity,
141-
index: hnsw_index_restored
150+
index: hnsw_index_restored,
142151
};
143152

144153
Ok(hnsw)

‎crates/snapshot/src/lib.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use chrono::{DateTime, Local};
1515
use defs::DbError;
1616
use flate2::read::GzDecoder;
1717
use index::{
18-
IndexSnapshot, IndexType, VectorIndex, flat::index::FlatIndex, hnsw::HnswIndex, kd_tree::index::KDTree
18+
IndexSnapshot, IndexType, VectorIndex, flat::index::FlatIndex, hnsw::HnswIndex,
19+
kd_tree::index::KDTree,
1920
};
2021
use semver::Version;
2122
use std::{

0 commit comments

Comments
 (0)