parent
586d3f4c0c
commit
6700d4d817
2 changed files with 10 additions and 9 deletions
|
@ -11,7 +11,7 @@ services:
|
||||||
- "RUST_LOG=info"
|
- "RUST_LOG=info"
|
||||||
- "ROCKET_ADDRESS=0.0.0.0"
|
- "ROCKET_ADDRESS=0.0.0.0"
|
||||||
- "DATABASE_URL=postgres://user:pass@postgres/webarc"
|
- "DATABASE_URL=postgres://user:pass@postgres/webarc"
|
||||||
command: "webarc serve"
|
command: "/webarc serve"
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
# Any Postgres with support for pgvector
|
# Any Postgres with support for pgvector
|
||||||
|
|
17
src/ai.rs
17
src/ai.rs
|
@ -29,13 +29,12 @@ pub struct DocEmbedding {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DocEmbedding {
|
impl DocEmbedding {
|
||||||
pub async fn total_chunks(&self) -> i32 {
|
pub async fn total_chunks(&self) -> i64 {
|
||||||
let res: (i32,) = sqlx::query_as(
|
let res: (i64,) = sqlx::query_as(
|
||||||
"SELECT MAX(chunk) FROM doc_embedding WHERE domain = $1 AND path = $2 AND ver = $3",
|
"SELECT COUNT(chunk) FROM doc_embedding WHERE domain = $1 AND path = $2",
|
||||||
)
|
)
|
||||||
.bind(&self.domain)
|
.bind(&self.domain)
|
||||||
.bind(&self.path)
|
.bind(&self.path)
|
||||||
.bind(&self.ver)
|
|
||||||
.fetch_one(get_pg!())
|
.fetch_one(get_pg!())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -48,12 +47,12 @@ impl DocEmbedding {
|
||||||
pub struct SearchResult {
|
pub struct SearchResult {
|
||||||
pub domain: String,
|
pub domain: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub total_chunks: i32,
|
pub total_chunks: i64,
|
||||||
pub chunks: Vec<DocEmbedding>,
|
pub chunks: Vec<DocEmbedding>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SearchResult {
|
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 {
|
Self {
|
||||||
domain,
|
domain,
|
||||||
path,
|
path,
|
||||||
|
@ -63,8 +62,10 @@ impl SearchResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn similarity(&self) -> f64 {
|
pub fn similarity(&self) -> f64 {
|
||||||
total_score(&self.chunks)
|
let chunks = f64::from(self.chunks.len() as u32);
|
||||||
* (f64::from(self.chunks.len() as u32) / f64::from(self.total_chunks))
|
let total = f64::from(self.total_chunks as i32);
|
||||||
|
let match_percent = chunks / total;
|
||||||
|
total_score(&self.chunks) * match_percent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue