Skip to content

Commit e8f57ec

Browse files
add documents number to complete (#15)
* add documents number to complete * fix lint * add documents number to complete --------- Co-authored-by: Francesca-Bit <francesca@terminusdb.com>
1 parent 9b8d9c9 commit e8f57ec

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/indexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub async fn operations_to_point_operations(
114114
} else {
115115
embeddings_for(key, &strings).await?
116116
};
117-
let loaded_vecs = vector_store.add_and_load_vecs(&domain, vecs.iter())?;
117+
let loaded_vecs: Vec<LoadedVec> = vector_store.add_and_load_vecs(&domain, vecs.iter())?;
118118
let mut new_ops: Vec<PointOperation> = zip(tuples, loaded_vecs)
119119
.map(|((op, _, id), vec)| match op {
120120
Op::Insert => PointOperation::Insert {

src/server.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use rand::Rng;
1515
use regex::Regex;
1616
use serde::Serialize;
1717
use serde::{self, Deserialize};
18+
use serde_json::json;
1819
use std::collections::HashSet;
20+
use std::string;
1921
use std::{
2022
collections::HashMap,
2123
convert::Infallible,
@@ -246,7 +248,7 @@ fn uri_to_spec(uri: &Uri) -> Result<ResourceSpec, SpecParseError> {
246248
pub enum TaskStatus {
247249
Pending(f32),
248250
Error(String),
249-
Completed,
251+
Completed(usize),
250252
}
251253

252254
#[derive(Clone, Debug, Serialize)]
@@ -474,8 +476,10 @@ impl Service {
474476
.await
475477
{
476478
Ok((id, hnsw)) => {
479+
let layer_len = hnsw.layer_len(0);
477480
self.set_index(id, hnsw.into()).await;
478-
self.set_task_status(task_id, TaskStatus::Completed).await;
481+
self.set_task_status(task_id, TaskStatus::Completed(layer_len.clone()))
482+
.await;
479483
self.clear_pending(&index_id).await;
480484
}
481485
Err(err) => {
@@ -601,14 +605,16 @@ impl Service {
601605
if let Some(state) = self.get_task_status(&task_id).await {
602606
match state {
603607
TaskStatus::Pending(f) => {
604-
Ok(Response::builder().body(format!("{}", f).into()).unwrap())
608+
let obj = json!({"status":"Pending","percentage":f});
609+
Ok(Response::builder().body(obj.to_string().into()).unwrap())
605610
}
606611
TaskStatus::Error(msg) => Ok(Response::builder()
607612
.status(StatusCode::INTERNAL_SERVER_ERROR)
608613
.body(format!("{:?}", msg).into())
609614
.unwrap()),
610-
TaskStatus::Completed => {
611-
Ok(Response::builder().body(format!("{}", 1.0).into()).unwrap())
615+
TaskStatus::Completed(u) => {
616+
let obj = json!({"status":"Complete","indexed_documents":u});
617+
Ok(Response::builder().body(obj.to_string().into()).unwrap())
612618
}
613619
}
614620
} else {

0 commit comments

Comments
 (0)