From 08fec35d6959edd4504ca335627b98676970b0e8 Mon Sep 17 00:00:00 2001 From: SilasMarvin <19626586+SilasMarvin@users.noreply.github.com> Date: Sat, 23 Mar 2024 15:22:22 -0700 Subject: [PATCH] Added vector_search_local --- pgml-sdks/pgml/src/collection.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pgml-sdks/pgml/src/collection.rs b/pgml-sdks/pgml/src/collection.rs index 69dd8574a..f8107d050 100644 --- a/pgml-sdks/pgml/src/collection.rs +++ b/pgml-sdks/pgml/src/collection.rs @@ -935,7 +935,6 @@ impl Collection { /// Ok(()) /// } #[instrument(skip(self))] - #[allow(clippy::type_complexity)] pub async fn vector_search( &mut self, query: Json, @@ -995,6 +994,32 @@ impl Collection { } } + /// Same as vector_search but assumes embeddings are done locally + #[instrument(skip(self))] + pub async fn vector_search_local( + &self, + query: Json, + pipeline: &Pipeline, + ) -> anyhow::Result> { + let pool = get_or_initialize_pool(&self.database_url).await?; + let (built_query, values) = + build_vector_search_query(query.clone(), self, pipeline).await?; + let results: Vec<(Json, String, f64)> = sqlx::query_as_with(&built_query, values) + .fetch_all(&pool) + .await?; + Ok(results + .into_iter() + .map(|v| { + serde_json::json!({ + "document": v.0, + "chunk": v.1, + "score": v.2 + }) + .into() + }) + .collect()) + } + /// Archives a [Collection] /// This will free up the name to be reused. It does not delete it. /// 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