Skip to content

Commit 89bdfa0

Browse files
committed
support more than one vertex per cell
1 parent b02edf9 commit 89bdfa0

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

  • src/apps/hnsw/coordinator

src/apps/hnsw/coordinator/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use crate::{
2424
use super::{
2525
measurements::MetricEncoding,
2626
partition::{
27-
index::HNSWIndex, service::service::AsyncServiceClient as PartitionSvrClient,
28-
types::OrderedFloat,
27+
index::HNSWIndex, schema::{CELL_FIELD_ID, HNSW_VERTEX_SCHEMA_ID}, service::service::AsyncServiceClient as PartitionSvrClient, types::OrderedFloat
2928
},
3029
};
3130
use bifrost::service_with_id;
@@ -39,7 +38,7 @@ service! {
3938
rpc delete_index(schema: u32, field_id: u64) -> Result<(), String>;
4039

4140
rpc new_cell(schema: u32, field_id: u64, cell_id: Id, ef_construction: u64, metric: MetricEncoding) -> Result<(), String>;
42-
rpc del_cell(schema: u32, field_id: u64, cell_id: Id) -> Result<(), String>;
41+
rpc del_cell(cell_id: Id) -> Result<(), String>;
4342
rpc update_cell(schema: u32, field_id: u64, cell_id: Id, ef_construction: u64, metric: MetricEncoding) -> Result<(), String>;
4443

4544
rpc query_top(schema: u32, field_id: u64, query: OwnedPrimArray, ef: u64, max_iter: u8, metric: MetricEncoding) -> Result<Option<(Id, Distance)>, String>;
@@ -245,27 +244,32 @@ impl Service for HNSWIndexService {
245244

246245
fn del_cell<'a>(
247246
&'a self,
248-
schema: u32,
249-
field_id: u64,
250247
cell_id: Id,
251248
) -> BoxFuture<'a, Result<(), String>> {
252249
async move {
250+
// Use the hash index to get the vertex id by the cell id
253251
let cell_id_value = OwnedValue::Id(cell_id);
254-
let index_id = get_hash_id_from_value(schema, field_id, &cell_id_value);
252+
let index_id = get_hash_id_from_value(HNSW_VERTEX_SCHEMA_ID, CELL_FIELD_ID, &cell_id_value);
255253
let index_vertex = self
256254
.indexer
257-
.hashed_query(index_id, field_id, &cell_id_value)
255+
.hashed_query(index_id, CELL_FIELD_ID, &cell_id_value)
258256
.await
259257
.map_err(|e| format!("Failed to get index client: {:?}", e))?
260258
.map_err(|e| format!("Failed to get index client: {:?}", e))?;
261259
self.engine.graph_transaction(DefaultPartitioner, |txn| {
260+
let index_vertex = index_vertex.clone();
262261
async move {
263-
txn.remove_vertex(index_vertex).await
262+
for vid in &index_vertex {
263+
if let Err(e) = txn.remove_vertex(vid).await? {
264+
return Ok(Err(e));
265+
}
266+
}
267+
Ok(Ok(()))
264268
}
265269
})
266270
.await
267-
.map_err(|e| format!("Failed to delete cell: {:?}", e))?
268-
.map_err(|e| format!("Failed to delete cell: {:?}", e))?;
271+
.map_err(|e| format!("Failed to delete vertex: {:?}", e))?
272+
.map_err(|e| format!("Failed to delete vertex: {:?}", e))?;
269273
Ok(())
270274
}
271275
.boxed()
@@ -280,7 +284,7 @@ impl Service for HNSWIndexService {
280284
metric: MetricEncoding,
281285
) -> BoxFuture<'a, Result<(), String>> {
282286
async move {
283-
let _ = self.del_cell(schema, field_id, cell_id).await;
287+
let _ = self.del_cell(cell_id).await;
284288
self.new_cell(schema, field_id, cell_id, ef_construction, metric).await
285289
}
286290
.boxed()

0 commit comments

Comments
 (0)