Browse Source

feat(searcher): basic logger

iwanhae 1 year ago
parent
commit
c2368f756c

+ 2 - 0
searcher/Cargo.toml

@@ -25,6 +25,8 @@ rusqlite = { version = "0.29.0", features = ["bundled", "trace", "array"] }
 usearch = "1.1.1"
 usearch = "1.1.1"
 actix = "0.13.0"
 actix = "0.13.0"
 cxx = "1.0.106"
 cxx = "1.0.106"
+env_logger = "0.10.0"
+log = "0.4.20"
 
 
 
 
 [features]
 [features]

+ 1 - 1
searcher/src/args.rs

@@ -30,7 +30,7 @@ pub struct Args {
 impl Args {
 impl Args {
     pub fn terminate_if_ci(&self) {
     pub fn terminate_if_ci(&self) {
         if self.ci {
         if self.ci {
-            println!("terminating ci mode");
+            info!("terminating ci mode");
             std::process::exit(0)
             std::process::exit(0)
         }
         }
     }
     }

+ 1 - 1
searcher/src/embed/encoder.rs

@@ -36,7 +36,7 @@ impl Encoder {
 
 
         // mean pooling
         // mean pooling
         let embeddings = (embeddings.sum(1).unwrap() / (n_tokens as f64)).unwrap();
         let embeddings = (embeddings.sum(1).unwrap() / (n_tokens as f64)).unwrap();
-        dbg!(prompt, start.elapsed());
+        debug!("{:?} {}", start.elapsed(), prompt);
         let tensor = normalize_l2(&embeddings).get(0).unwrap();
         let tensor = normalize_l2(&embeddings).get(0).unwrap();
 
 
         let mut result: Vec<f32> = Vec::new();
         let mut result: Vec<f32> = Vec::new();

+ 14 - 3
searcher/src/main.rs

@@ -1,18 +1,23 @@
 #[cfg(feature = "mkl")]
 #[cfg(feature = "mkl")]
 extern crate intel_mkl_src;
 extern crate intel_mkl_src;
+
+#[macro_use]
+extern crate log;
+
 mod args;
 mod args;
 mod database;
 mod database;
 mod embed;
 mod embed;
 mod server;
 mod server;
 mod vector_db;
 mod vector_db;
 
 
-use actix_web::{web, App, HttpServer};
+use actix_web::{middleware, web, App, HttpServer};
 use args::Args;
 use args::Args;
 use clap::Parser;
 use clap::Parser;
 use embed::encoder;
 use embed::encoder;
 
 
 #[actix_web::main]
 #[actix_web::main]
 async fn main() -> std::io::Result<()> {
 async fn main() -> std::io::Result<()> {
+    env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug"));
     let args = Args::parse();
     let args = Args::parse();
 
 
     // [BEGIN] INIT
     // [BEGIN] INIT
@@ -21,21 +26,27 @@ async fn main() -> std::io::Result<()> {
     let (model, tokenizer) = args.build_model_and_tokenizer().unwrap();
     let (model, tokenizer) = args.build_model_and_tokenizer().unwrap();
     let enc = encoder::Encoder::new(model, tokenizer);
     let enc = encoder::Encoder::new(model, tokenizer);
     let app_data_encoder = web::Data::new(enc);
     let app_data_encoder = web::Data::new(enc);
+    info!("MODEL loaded");
 
 
     // DATABSE
     // DATABSE
     let database = database::new_connection_pool();
     let database = database::new_connection_pool();
     let app_data_database = web::Data::new(database);
     let app_data_database = web::Data::new(database);
+    info!("DATABASE loaded");
 
 
     // VECTOR DATABASE
     // VECTOR DATABASE
     let vector = vector_db::start();
     let vector = vector_db::start();
     let app_data_vector = web::Data::new(vector);
     let app_data_vector = web::Data::new(vector);
+    info!("VECTOR DATABASE loaded");
 
 
     // [END] INIT
     // [END] INIT
     args.terminate_if_ci();
     args.terminate_if_ci();
 
 
-    println!("Listen on 0.0.0.0:8080");
+    info!("Listen on 0.0.0.0:8080");
+
     let result = HttpServer::new(move || {
     let result = HttpServer::new(move || {
         App::new()
         App::new()
+            .wrap(middleware::Logger::default())
+            .wrap(middleware::Compress::default())
             .app_data(app_data_encoder.clone())
             .app_data(app_data_encoder.clone())
             .app_data(app_data_database.clone())
             .app_data(app_data_database.clone())
             .app_data(app_data_vector.clone())
             .app_data(app_data_vector.clone())
@@ -45,6 +56,6 @@ async fn main() -> std::io::Result<()> {
     .bind(("0.0.0.0", 8080))?
     .bind(("0.0.0.0", 8080))?
     .run()
     .run()
     .await;
     .await;
-    println!("Server Terminated. Byebye :-)");
+    info!("Server Terminated. Byebye :-)");
     result
     result
 }
 }

+ 7 - 3
searcher/src/vector_db/mod.rs

@@ -22,7 +22,7 @@ pub fn start() -> Addr<VectorDB> {
     .unwrap();
     .unwrap();
 
 
     index
     index
-        .load("./kuberian.usearch")
+        .view("./kuberian.usearch")
         .expect("fail to load usearch index");
         .expect("fail to load usearch index");
 
 
     VectorDB { index }.start()
     VectorDB { index }.start()
@@ -31,9 +31,13 @@ pub fn start() -> Addr<VectorDB> {
 impl Actor for VectorDB {
 impl Actor for VectorDB {
     type Context = Context<Self>;
     type Context = Context<Self>;
 
 
-    fn started(&mut self, _ctx: &mut Context<Self>) {}
+    fn started(&mut self, _ctx: &mut Context<Self>) {
+        info!("vector db service initiated");
+    }
 
 
-    fn stopped(&mut self, _ctx: &mut Context<Self>) {}
+    fn stopped(&mut self, _ctx: &mut Context<Self>) {
+        error!("vector db service shutdown")
+    }
 }
 }
 
 
 impl Handler<Query> for VectorDB {
 impl Handler<Query> for VectorDB {