Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SilasMarvin merged 1 commit intomasterfromsilas-add-boosting-for-vector-search
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionspgml-sdks/pgml/src/lib.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 = "testr_c_cvswle_9";
let collection_name = "testr_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 DownExpand 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 deletionspgml-sdks/pgml/src/vector_search_query_builder.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp