From cdf89aaa86765e0f547f7012a3baf4c90d603671 Mon Sep 17 00:00:00 2001 From: SilasMarvin <19626586+SilasMarvin@users.noreply.github.com> Date: Fri, 25 Aug 2023 11:41:37 -0700 Subject: [PATCH 1/4] Fixed postgres floating point type --- .../javascript/tests/typescript-tests/test.ts | 30 +++++++++++++------ pgml-sdks/rust/pgml/src/filter_builder.rs | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts b/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts index 133d91198..45597082a 100644 --- a/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts +++ b/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts @@ -18,7 +18,9 @@ const generate_dummy_documents = (count: number) => { docs.push({ id: i, text: `This is a test document: ${i}`, + project: "a10", uuid: i * 10, + floating_uuid: i * 1.1, name: `Test Document ${i}`, }); } @@ -36,7 +38,7 @@ it("can create collection", () => { it("can create model", () => { let model = pgml.newModel("test", "openai", { - "tester": "test 0123948712394871234987" + tester: "test 0123948712394871234987", }); expect(model).toBeTruthy(); }); @@ -74,7 +76,7 @@ it("can vector search with local embeddings", async () => { await collection.archive(); }); -it("can vector search with remote embeddings", async() => { +it("can vector search with remote embeddings", async () => { let model = pgml.newModel("text-embedding-ada-002", "openai"); let splitter = pgml.newSplitter(); let pipeline = pgml.newPipeline("test_j_p_cvswre_0", model, splitter); @@ -86,26 +88,34 @@ it("can vector search with remote embeddings", async() => { await collection.archive(); }); -it("can vector search with query builder", async() => { +it("can vector search with query builder", async () => { let model = pgml.newModel(); let splitter = pgml.newSplitter(); let pipeline = pgml.newPipeline("test_j_p_cvswqb_0", model, splitter); let collection = pgml.newCollection("test_j_c_cvswqb_1"); await collection.upsert_documents(generate_dummy_documents(3)); await collection.add_pipeline(pipeline); - let results = await collection.query().vector_recall("Here is some query", pipeline).limit(10).fetch_all(); + let results = await collection + .query() + .vector_recall("Here is some query", pipeline) + .limit(10) + .fetch_all(); expect(results).toHaveLength(3); await collection.archive(); }); -it("can vector search with query builder with remote embeddings", async() => { +it("can vector search with query builder with remote embeddings", async () => { let model = pgml.newModel("text-embedding-ada-002", "openai"); let splitter = pgml.newSplitter(); let pipeline = pgml.newPipeline("test_j_p_cvswqbwre_0", model, splitter); let collection = pgml.newCollection("test_j_c_cvswqbwre_1"); await collection.upsert_documents(generate_dummy_documents(3)); await collection.add_pipeline(pipeline); - let results = await collection.query().vector_recall("Here is some query", pipeline).limit(10).fetch_all(); + let results = await collection + .query() + .vector_recall("Here is some query", pipeline) + .limit(10) + .fetch_all(); expect(results).toHaveLength(3); await collection.archive(); }); @@ -122,10 +132,12 @@ it("can vector search with query builder and metadata filtering", async () => { .vector_recall("Here is some query", pipeline) .filter({ metadata: { - $or: [{ uuid: { $eq: 0 } }, { uuid: { $eq: 20 } }], + $or: [{ uuid: { $eq: 0 } }, { floating_uuid: { $lt: 2 } }], + project: { $eq: "a10" }, }, }) - .limit(10).fetch_all(); + .limit(10) + .fetch_all(); expect(results).toHaveLength(2); await collection.archive(); }); @@ -141,7 +153,7 @@ it("pipeline to dict", async () => { let collection = pgml.newCollection("test_j_c_ptd_2"); await collection.add_pipeline(pipeline); let pipeline_dict = await pipeline.to_dict(); - console.log(JSON.stringify(pipeline_dict)) + console.log(JSON.stringify(pipeline_dict)); expect(pipeline_dict["name"]).toBe("test_j_p_ptd_0"); await collection.archive(); }); diff --git a/pgml-sdks/rust/pgml/src/filter_builder.rs b/pgml-sdks/rust/pgml/src/filter_builder.rs index a156405e5..16c17b7d3 100644 --- a/pgml-sdks/rust/pgml/src/filter_builder.rs +++ b/pgml-sdks/rust/pgml/src/filter_builder.rs @@ -119,7 +119,7 @@ fn get_value_type(value: &serde_json::Value) -> String { } else if value.is_i64() { "bigint".to_string() } else if value.is_f64() { - "double".to_string() + "float8".to_string() } else if value.is_boolean() { "bool".to_string() } else { From c82090ad7dc8765faddd28ef4069cfc45fc216fb Mon Sep 17 00:00:00 2001 From: SilasMarvin <19626586+SilasMarvin@users.noreply.github.com> Date: Fri, 25 Aug 2023 11:42:46 -0700 Subject: [PATCH 2/4] Fixed postgres floating point type --- pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts b/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts index 45597082a..ef2bfe9d6 100644 --- a/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts +++ b/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts @@ -153,7 +153,6 @@ it("pipeline to dict", async () => { let collection = pgml.newCollection("test_j_c_ptd_2"); await collection.add_pipeline(pipeline); let pipeline_dict = await pipeline.to_dict(); - console.log(JSON.stringify(pipeline_dict)); expect(pipeline_dict["name"]).toBe("test_j_p_ptd_0"); await collection.archive(); }); From 2b3ba500187e9e1fb5cc63d54b84de7d157e2023 Mon Sep 17 00:00:00 2001 From: SilasMarvin <19626586+SilasMarvin@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:01:45 -0700 Subject: [PATCH 3/4] Added new test to python --- pgml-sdks/rust/pgml/python/tests/test.py | 18 ++++++++++-------- pgml-sdks/rust/pgml/src/filter_builder.rs | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pgml-sdks/rust/pgml/python/tests/test.py b/pgml-sdks/rust/pgml/python/tests/test.py index c6e85e3b6..88c19685d 100644 --- a/pgml-sdks/rust/pgml/python/tests/test.py +++ b/pgml-sdks/rust/pgml/python/tests/test.py @@ -29,7 +29,8 @@ def generate_dummy_documents(count: int) -> List[Dict[str, Any]]: { "id": i, "text": "This is a test document: {}".format(i), - "some_random_thing": "This will be metadata on it", + "project": "a10", + "floating_uuid": i * 1.01, "uuid": i * 10, "name": "Test Document {}".format(i), } @@ -147,17 +148,18 @@ async def test_can_vector_search_with_query_builder_and_metadata_filtering(): results = ( await collection.query() .vector_recall("Here is some query", pipeline) - .filter({ - "metadata": { - "uuid": { - "$eq": 0 - } + .filter( + { + "metadata": { + "$or": [{"uuid": {"$eq": 0}}, {"floating_uuid": {"$lt": 2}}], + "project": {"$eq": "a10"}, + }, } - }) + ) .limit(10) .fetch_all() ) - assert len(results) == 1 + assert len(results) == 2 await collection.archive() diff --git a/pgml-sdks/rust/pgml/src/filter_builder.rs b/pgml-sdks/rust/pgml/src/filter_builder.rs index 16c17b7d3..b9792191b 100644 --- a/pgml-sdks/rust/pgml/src/filter_builder.rs +++ b/pgml-sdks/rust/pgml/src/filter_builder.rs @@ -117,7 +117,7 @@ fn get_value_type(value: &serde_json::Value) -> String { } else if value.is_string() { "text".to_string() } else if value.is_i64() { - "bigint".to_string() + "float8".to_string() } else if value.is_f64() { "float8".to_string() } else if value.is_boolean() { From 8e6b129dbf36b07ce30a7fe9741162b6768d2042 Mon Sep 17 00:00:00 2001 From: SilasMarvin <19626586+SilasMarvin@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:03:34 -0700 Subject: [PATCH 4/4] Renamed for clarification --- pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts b/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts index ef2bfe9d6..5e5b76061 100644 --- a/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts +++ b/pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts @@ -38,7 +38,7 @@ it("can create collection", () => { it("can create model", () => { let model = pgml.newModel("test", "openai", { - tester: "test 0123948712394871234987", + some_example_parameter: "test 0123948712394871234987", }); expect(model).toBeTruthy(); });