Skip to content

Fix clippy lints #1188

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 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix clippy lints in pgml-sdk/pgml
  • Loading branch information
kczimm committed Nov 27, 2023
commit c64144505d6ef3e858ddf03511d25b036b1cbb99
16 changes: 8 additions & 8 deletions pgml-sdks/pgml/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ impl Collection {
let mut document_ids = Vec::new();
for chunk in documents?.chunks(10) {
// Need to make it a vec to partition it and must include explicit typing here
let mut chunk: Vec<&(uuid::Uuid, Option<String>, Json)> = chunk.into_iter().collect();
let mut chunk: Vec<&(uuid::Uuid, Option<String>, Json)> = chunk.iter().collect();

// Split the chunk into two groups, one with text, and one with just metadata
let split_index = itertools::partition(&mut chunk, |(_, text, _)| text.is_some());
Expand All @@ -623,7 +623,7 @@ impl Collection {
if !metadata_chunk.is_empty() {
// Update the metadata
// Merge the metadata if the user has specified to do so otherwise replace it
if args["metadata"]["merge"].as_bool().unwrap_or(false) == true {
if args["metadata"]["merge"].as_bool().unwrap_or(false) {
sqlx::query(query_builder!(
"UPDATE %s d SET metadata = d.metadata || v.metadata FROM (SELECT UNNEST($1) source_uuid, UNNEST($2) metadata) v WHERE d.source_uuid = v.source_uuid",
self.documents_table_name
Expand Down Expand Up @@ -1245,7 +1245,7 @@ impl Collection {
let file_types: Vec<&str> = args["file_types"]
.as_array()
.context("file_types must be an array of valid file types. E.G. ['md', 'txt']")?
.into_iter()
.iter()
.map(|v| {
let v = v.as_str().with_context(|| {
format!("file_types must be an array of valid file types. E.G. ['md', 'txt']. Found: {}", v)
Expand All @@ -1265,10 +1265,10 @@ impl Collection {
args["ignore_paths"]
.as_array()
.map_or(Ok(Vec::new()), |v| {
v.into_iter()
v.iter()
.map(|v| {
let v = v.as_str().with_context(|| {
format!("ignore_paths must be an array of valid regexes")
"ignore_paths must be an array of valid regexes".to_string()
})?;
Regex::new(v).with_context(|| format!("Invalid regex: {}", v))
})
Expand All @@ -1291,7 +1291,7 @@ impl Collection {
continue;
}

let contents = utils::get_file_contents(&entry.path())?;
let contents = utils::get_file_contents(entry.path())?;
documents.push(
json!({
"id": nice_path,
Expand All @@ -1306,7 +1306,7 @@ impl Collection {
}
}
}
if documents.len() > 0 {
if !documents.is_empty() {
self.upsert_documents(documents, None).await?;
}
Ok(())
Expand All @@ -1315,7 +1315,7 @@ impl Collection {
pub async fn upsert_file(&mut self, path: &str) -> anyhow::Result<()> {
self.verify_in_database(false).await?;
let path = Path::new(path);
let contents = utils::get_file_contents(&path)?;
let contents = utils::get_file_contents(path)?;
let document = json!({
"id": path,
"text": contents
Expand Down
16 changes: 8 additions & 8 deletions pgml-sdks/pgml/src/filter_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":\"test\"}}' AND "test_table"."metadata" @> E'{\"id4\":{\"id5\":{\"id6\":true}}}' AND "test_table"."metadata" @> E'{\"id7\":{\"id8\":{\"id9\":{\"id10\":[1,2,3]}}}}'"##
r#"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":\"test\"}}' AND "test_table"."metadata" @> E'{\"id4\":{\"id5\":{\"id6\":true}}}' AND "test_table"."metadata" @> E'{\"id7\":{\"id8\":{\"id9\":{\"id10\":[1,2,3]}}}}'"#
);
}

Expand All @@ -303,7 +303,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE NOT "test_table"."metadata" @> E'{\"id\":1}' AND NOT "test_table"."metadata" @> E'{\"id2\":{\"id3\":\"test\"}}' AND NOT "test_table"."metadata" @> E'{\"id4\":{\"id5\":{\"id6\":true}}}' AND NOT "test_table"."metadata" @> E'{\"id7\":{\"id8\":{\"id9\":{\"id10\":[1,2,3]}}}}'"##
r#"SELECT "id" FROM "test_table" WHERE NOT "test_table"."metadata" @> E'{\"id\":1}' AND NOT "test_table"."metadata" @> E'{\"id2\":{\"id3\":\"test\"}}' AND NOT "test_table"."metadata" @> E'{\"id4\":{\"id5\":{\"id6\":true}}}' AND NOT "test_table"."metadata" @> E'{\"id7\":{\"id8\":{\"id9\":{\"id10\":[1,2,3]}}}}'"#
);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}'"##
r#"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}'"#
);
}

Expand All @@ -383,7 +383,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"id\":1}' OR "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}'"##
r#"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"id\":1}' OR "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}'"#
);
}

Expand All @@ -399,7 +399,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE NOT ("test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}')"##
r#"SELECT "id" FROM "test_table" WHERE NOT ("test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}')"#
);
}

Expand All @@ -419,7 +419,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE ("test_table"."metadata" @> E'{\"id\":1}' OR "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}') AND "test_table"."metadata" @> E'{\"id4\":1}'"##
r#"SELECT "id" FROM "test_table" WHERE ("test_table"."metadata" @> E'{\"id\":1}' OR "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}') AND "test_table"."metadata" @> E'{\"id4\":1}'"#
);
let sql = construct_filter_builder_with_json(json!({
"$or": [
Expand All @@ -435,7 +435,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE ("test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}') OR "test_table"."metadata" @> E'{\"id4\":1}'"##
r#"SELECT "id" FROM "test_table" WHERE ("test_table"."metadata" @> E'{\"id\":1}' AND "test_table"."metadata" @> E'{\"id2\":{\"id3\":1}}') OR "test_table"."metadata" @> E'{\"id4\":1}'"#
);
let sql = construct_filter_builder_with_json(json!({
"metadata": {"$or": [
Expand All @@ -447,7 +447,7 @@ mod tests {
.to_valid_sql_query();
assert_eq!(
sql,
r##"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"metadata\":{\"uuid\":\"1\"}}' OR "test_table"."metadata" @> E'{\"metadata\":{\"uuid2\":\"2\"}}'"##
r#"SELECT "id" FROM "test_table" WHERE "test_table"."metadata" @> E'{\"metadata\":{\"uuid\":\"1\"}}' OR "test_table"."metadata" @> E'{\"metadata\":{\"uuid2\":\"2\"}}'"#
);
}
}
28 changes: 14 additions & 14 deletions pgml-sdks/pgml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod tests {
let mut collection = Collection::new(collection_name, None);
collection.add_pipeline(&mut pipeline).await?;
let full_embeddings_table_name = pipeline.create_or_get_embeddings_table().await?;
let embeddings_table_name = full_embeddings_table_name.split(".").collect::<Vec<_>>()[1];
let embeddings_table_name = full_embeddings_table_name.split('.').collect::<Vec<_>>()[1];
let pool = get_or_initialize_pool(&None).await?;
let results: Vec<(String, String)> = sqlx::query_as(&query_builder!(
"select indexname, indexdef from pg_indexes where tablename = '%d' and schemaname = '%d'",
Expand All @@ -346,10 +346,10 @@ mod tests {
collection.add_pipeline(&mut pipeline).await?;
let queried_pipeline = &collection.get_pipelines().await?[0];
assert_eq!(pipeline.name, queried_pipeline.name);
collection.disable_pipeline(&mut pipeline).await?;
collection.disable_pipeline(&pipeline).await?;
let queried_pipelines = &collection.get_pipelines().await?;
assert!(queried_pipelines.is_empty());
collection.enable_pipeline(&mut pipeline).await?;
collection.enable_pipeline(&pipeline).await?;
let queried_pipeline = &collection.get_pipelines().await?[0];
assert_eq!(pipeline.name, queried_pipeline.name);
collection.archive().await?;
Expand Down Expand Up @@ -510,13 +510,13 @@ mod tests {
collection.add_pipeline(&mut pipeline).await?;

// Recreate the pipeline to replicate a more accurate example
let mut pipeline = Pipeline::new("test_r_p_cvswqb_1", None, None, None);
let pipeline = Pipeline::new("test_r_p_cvswqb_1", None, None, None);
collection
.upsert_documents(generate_dummy_documents(4), None)
.await?;
let results = collection
.query()
.vector_recall("Here is some query", &mut pipeline, None)
.vector_recall("Here is some query", &pipeline, None)
.limit(3)
.fetch_all()
.await?;
Expand Down Expand Up @@ -553,15 +553,15 @@ mod tests {
collection.add_pipeline(&mut pipeline).await?;

// Recreate the pipeline to replicate a more accurate example
let mut pipeline = Pipeline::new("test_r_p_cvswqbapmpis_1", None, None, None);
let pipeline = Pipeline::new("test_r_p_cvswqbapmpis_1", None, None, None);
collection
.upsert_documents(generate_dummy_documents(3), None)
.await?;
let results = collection
.query()
.vector_recall(
"Here is some query",
&mut pipeline,
&pipeline,
Some(
json!({
"instruction": "Represent the Wikipedia document for retrieval: "
Expand Down Expand Up @@ -604,13 +604,13 @@ mod tests {
collection.add_pipeline(&mut pipeline).await?;

// Recreate the pipeline to replicate a more accurate example
let mut pipeline = Pipeline::new("test_r_p_cvswqbwre_1", None, None, None);
let pipeline = Pipeline::new("test_r_p_cvswqbwre_1", None, None, None);
collection
.upsert_documents(generate_dummy_documents(4), None)
.await?;
let results = collection
.query()
.vector_recall("Here is some query", &mut pipeline, None)
.vector_recall("Here is some query", &pipeline, None)
.limit(3)
.fetch_all()
.await?;
Expand All @@ -631,15 +631,15 @@ mod tests {
collection.add_pipeline(&mut pipeline).await?;

// Recreate the pipeline to replicate a more accurate example
let mut pipeline = Pipeline::new("test_r_p_cvswqbachesv_1", None, None, None);
let pipeline = Pipeline::new("test_r_p_cvswqbachesv_1", None, None, None);
collection
.upsert_documents(generate_dummy_documents(3), None)
.await?;
let results = collection
.query()
.vector_recall(
"Here is some query",
&mut pipeline,
&pipeline,
Some(
json!({
"hnsw": {
Expand Down Expand Up @@ -676,15 +676,15 @@ mod tests {
collection.add_pipeline(&mut pipeline).await?;

// Recreate the pipeline to replicate a more accurate example
let mut pipeline = Pipeline::new("test_r_p_cvswqbachesvare_2", None, None, None);
let pipeline = Pipeline::new("test_r_p_cvswqbachesvare_2", None, None, None);
collection
.upsert_documents(generate_dummy_documents(3), None)
.await?;
let results = collection
.query()
.vector_recall(
"Here is some query",
&mut pipeline,
&pipeline,
Some(
json!({
"hnsw": {
Expand Down Expand Up @@ -754,7 +754,7 @@ mod tests {
for (expected_result_count, filter) in filters {
let results = collection
.query()
.vector_recall("Here is some query", &mut pipeline, None)
.vector_recall("Here is some query", &pipeline, None)
.filter(filter)
.fetch_all()
.await?;
Expand Down
2 changes: 1 addition & 1 deletion pgml-sdks/pgml/src/migrations/pgml--0.9.1--0.9.2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub async fn migrate(pool: PgPool, _: Vec<i64>) -> anyhow::Result<String> {
sqlx::query_scalar("SELECT extversion FROM pg_extension WHERE extname = 'vector'")
.fetch_one(&pool)
.await?;
let value = version.split(".").collect::<Vec<&str>>()[1].parse::<u64>()?;
let value = version.split('.').collect::<Vec<&str>>()[1].parse::<u64>()?;
anyhow::ensure!(
value >= 5,
"Vector extension must be at least version 0.5.0"
Expand Down
3 changes: 2 additions & 1 deletion pgml-sdks/pgml/src/transformer_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{get_or_initialize_pool, types::Json};
#[cfg(feature = "python")]
use crate::types::JsonPython;

#[allow(clippy::type_complexity)]
#[derive(alias_manual)]
pub struct TransformerStream {
transaction: Option<Transaction<'static, Postgres>>,
Expand Down Expand Up @@ -61,7 +62,7 @@ impl Stream for TransformerStream {
) -> Poll<Option<Self::Item>> {
if self.done {
if let Some(c) = self.commit.as_mut() {
if let Poll::Ready(_) = c.as_mut().poll(cx) {
if c.as_mut().poll(cx).is_ready() {
self.commit = None;
}
}
Expand Down
6 changes: 2 additions & 4 deletions pgml-sdks/pgml/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ pub fn get_file_contents(path: &Path) -> anyhow::Result<String> {
"pdf" => {
let doc = Document::load(path)
.with_context(|| format!("Error reading PDF file: {}", path.display()))?;
doc.get_pages()
.into_iter()
.map(|(page_number, _)| {
doc.extract_text(&vec![page_number]).with_context(|| {
doc.get_pages().into_keys().map(|page_number| {
doc.extract_text(&[page_number]).with_context(|| {
format!("Error extracting content from PDF file: {}", path.display())
})
})
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