Skip to content

SDK - Added boosting for vector search #1371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pgml-sdks/pgml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ mod tests {
#[tokio::test]
async fn can_vector_search_with_local_embeddings() -> anyhow::Result<()> {
internal_init_logger(None, None).ok();
let collection_name = "test r_c_cvswle_9";
let collection_name = "test r_c_cvswle_13";
let mut collection = Collection::new(collection_name, None)?;
let documents = generate_dummy_documents(10);
collection.upsert_documents(documents.clone(), None).await?;
Expand Down Expand Up @@ -1095,10 +1095,12 @@ mod tests {
"parameters": {
"instruction": "Represent the Wikipedia document for retrieval"
},
"full_text_filter": "test"
"full_text_filter": "test",
"boost": 1.2
},
"body": {
"query": "Test document: 2"
"query": "Test document: 2",
"boost": 1.0
},
},
"filter": {
Expand Down
7 changes: 5 additions & 2 deletions pgml-sdks/pgml/src/vector_search_query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ValidField {
query: String,
parameters: Option<Json>,
full_text_filter: Option<String>,
boost: Option<f32>,
}

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

let mut query = Query::select();

let boost = vf.boost.unwrap_or(1.);

match model_runtime {
ModelRuntime::Python => {
// Build the embedding CTE
Expand All @@ -118,7 +121,7 @@ pub async fn build_vector_search_query(

query
.expr(Expr::cust(format!(
r#"1 - (embeddings.embedding <=> (SELECT embedding FROM "{key}_embedding")::vector) AS score"#
r#"(1 - (embeddings.embedding <=> (SELECT embedding FROM "{key}_embedding")::vector)) * {boost} AS score"#
)))
.order_by_expr(Expr::cust(format!(
r#"embeddings.embedding <=> (SELECT embedding FROM "{key}_embedding")::vector"#
Expand Down Expand Up @@ -152,7 +155,7 @@ pub async fn build_vector_search_query(
// Build the score CTE
query
.expr(Expr::cust_with_values(
r#"1 - (embeddings.embedding <=> $1::vector) AS score"#,
r#"(1 - (embeddings.embedding <=> $1::vector)) {boost} AS score"#,
[embedding.clone()],
))
.order_by_expr(
Expand Down
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