Skip to content

Commit a5ee9d7

Browse files
authored
SDK - Added boosting for vector search (#1371)
1 parent 9510b55 commit a5ee9d7

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pgml-sdks/pgml/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ mod tests {
10521052
#[tokio::test]
10531053
async fn can_vector_search_with_local_embeddings() -> anyhow::Result<()> {
10541054
internal_init_logger(None, None).ok();
1055-
let collection_name = "test r_c_cvswle_9";
1055+
let collection_name = "test r_c_cvswle_13";
10561056
let mut collection = Collection::new(collection_name, None)?;
10571057
let documents = generate_dummy_documents(10);
10581058
collection.upsert_documents(documents.clone(), None).await?;
@@ -1095,10 +1095,12 @@ mod tests {
10951095
"parameters": {
10961096
"instruction": "Represent the Wikipedia document for retrieval"
10971097
},
1098-
"full_text_filter": "test"
1098+
"full_text_filter": "test",
1099+
"boost": 1.2
10991100
},
11001101
"body": {
1101-
"query": "Test document: 2"
1102+
"query": "Test document: 2",
1103+
"boost": 1.0
11021104
},
11031105
},
11041106
"filter": {

pgml-sdks/pgml/src/vector_search_query_builder.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct ValidField {
2525
query: String,
2626
parameters: Option<Json>,
2727
full_text_filter: Option<String>,
28+
boost: Option<f32>,
2829
}
2930

3031
#[derive(Debug, Deserialize)]
@@ -98,6 +99,8 @@ pub async fn build_vector_search_query(
9899

99100
let mut query = Query::select();
100101

102+
let boost = vf.boost.unwrap_or(1.);
103+
101104
match model_runtime {
102105
ModelRuntime::Python => {
103106
// Build the embedding CTE
@@ -118,7 +121,7 @@ pub async fn build_vector_search_query(
118121

119122
query
120123
.expr(Expr::cust(format!(
121-
r#"1 - (embeddings.embedding <=> (SELECT embedding FROM "{key}_embedding")::vector) AS score"#
124+
r#"(1 - (embeddings.embedding <=> (SELECT embedding FROM "{key}_embedding")::vector)) * {boost} AS score"#
122125
)))
123126
.order_by_expr(Expr::cust(format!(
124127
r#"embeddings.embedding <=> (SELECT embedding FROM "{key}_embedding")::vector"#
@@ -152,7 +155,7 @@ pub async fn build_vector_search_query(
152155
// Build the score CTE
153156
query
154157
.expr(Expr::cust_with_values(
155-
r#"1 - (embeddings.embedding <=> $1::vector) AS score"#,
158+
r#"(1 - (embeddings.embedding <=> $1::vector)) {boost} AS score"#,
156159
[embedding.clone()],
157160
))
158161
.order_by_expr(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy