Skip to content

Added vector_search_local #1387

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 23, 2024
Merged
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
27 changes: 26 additions & 1 deletion pgml-sdks/pgml/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@ impl Collection {
/// Ok(())
/// }
#[instrument(skip(self))]
#[allow(clippy::type_complexity)]
pub async fn vector_search(
&mut self,
query: Json,
Expand Down Expand Up @@ -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<Vec<Json>> {
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.
///
Expand Down