Skip to content

Commit 743fd79

Browse files
authored
SDK - Patch re-ranking (#1521)
1 parent 71219aa commit 743fd79

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pgml-sdks/pgml/src/vector_search_query_builder.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub async fn build_sqlx_query(
326326
SIden::Str("chunk"),
327327
SIden::Str("score"),
328328
]);
329-
query.expr_as(Expr::cust("(rank).score"), Alias::new("rank_score"));
329+
query.expr_as(Expr::cust("(rank).score"), Alias::new("rerank_score"));
330330

331331
// Build the actual select statement sub query
332332
let mut sub_query_rank_call = Query::select();
@@ -364,6 +364,20 @@ pub async fn build_sqlx_query(
364364

365365
query
366366
} else {
367+
// Wrap our query to return a fourth null column
368+
let mut vector_search_cte = CommonTableExpression::from_select(query);
369+
vector_search_cte.table_name(Alias::new(format!("{prefix}_vector_search")));
370+
ctes.push(vector_search_cte);
371+
372+
let mut query = Query::select();
373+
query
374+
.columns([
375+
SIden::Str("document"),
376+
SIden::Str("chunk"),
377+
SIden::Str("score"),
378+
])
379+
.expr_as(Expr::cust("NULL"), Alias::new("rerank_score"))
380+
.from(SIden::String(format!("{prefix}_vector_search")));
367381
query
368382
};
369383

0 commit comments

Comments
 (0)