From 6700d4d817420dc6d8dd34e285aedeffacd792bc Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 2 Jan 2025 22:56:51 +0100 Subject: [PATCH] fix --- docker-compose.yml | 2 +- src/ai.rs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a3858b1..0711b30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: - "RUST_LOG=info" - "ROCKET_ADDRESS=0.0.0.0" - "DATABASE_URL=postgres://user:pass@postgres/webarc" - command: "webarc serve" + command: "/webarc serve" postgres: # Any Postgres with support for pgvector diff --git a/src/ai.rs b/src/ai.rs index 803a0be..c3c8b46 100644 --- a/src/ai.rs +++ b/src/ai.rs @@ -29,13 +29,12 @@ pub struct DocEmbedding { } impl DocEmbedding { - pub async fn total_chunks(&self) -> i32 { - let res: (i32,) = sqlx::query_as( - "SELECT MAX(chunk) FROM doc_embedding WHERE domain = $1 AND path = $2 AND ver = $3", + pub async fn total_chunks(&self) -> i64 { + let res: (i64,) = sqlx::query_as( + "SELECT COUNT(chunk) FROM doc_embedding WHERE domain = $1 AND path = $2", ) .bind(&self.domain) .bind(&self.path) - .bind(&self.ver) .fetch_one(get_pg!()) .await .unwrap(); @@ -48,12 +47,12 @@ impl DocEmbedding { pub struct SearchResult { pub domain: String, pub path: String, - pub total_chunks: i32, + pub total_chunks: i64, pub chunks: Vec, } impl SearchResult { - pub fn new(domain: String, path: String, total_chunks: i32) -> Self { + pub fn new(domain: String, path: String, total_chunks: i64) -> Self { Self { domain, path, @@ -63,8 +62,10 @@ impl SearchResult { } pub fn similarity(&self) -> f64 { - total_score(&self.chunks) - * (f64::from(self.chunks.len() as u32) / f64::from(self.total_chunks)) + let chunks = f64::from(self.chunks.len() as u32); + let total = f64::from(self.total_chunks as i32); + let match_percent = chunks / total; + total_score(&self.chunks) * match_percent } }