Skip to content

Commit a16ff70

Browse files
authored
Added vector_search_local (#1387)
1 parent 730d523 commit a16ff70

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

pgml-sdks/pgml/src/collection.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,6 @@ impl Collection {
935935
/// Ok(())
936936
/// }
937937
#[instrument(skip(self))]
938-
#[allow(clippy::type_complexity)]
939938
pub async fn vector_search(
940939
&mut self,
941940
query: Json,
@@ -995,6 +994,32 @@ impl Collection {
995994
}
996995
}
997996

997+
/// Same as vector_search but assumes embeddings are done locally
998+
#[instrument(skip(self))]
999+
pub async fn vector_search_local(
1000+
&self,
1001+
query: Json,
1002+
pipeline: &Pipeline,
1003+
) -> anyhow::Result<Vec<Json>> {
1004+
let pool = get_or_initialize_pool(&self.database_url).await?;
1005+
let (built_query, values) =
1006+
build_vector_search_query(query.clone(), self, pipeline).await?;
1007+
let results: Vec<(Json, String, f64)> = sqlx::query_as_with(&built_query, values)
1008+
.fetch_all(&pool)
1009+
.await?;
1010+
Ok(results
1011+
.into_iter()
1012+
.map(|v| {
1013+
serde_json::json!({
1014+
"document": v.0,
1015+
"chunk": v.1,
1016+
"score": v.2
1017+
})
1018+
.into()
1019+
})
1020+
.collect())
1021+
}
1022+
9981023
/// Archives a [Collection]
9991024
/// This will free up the name to be reused. It does not delete it.
10001025
///

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