Skip to content

Commit eafc5b8

Browse files
authored
Fixed postgres floating point type (#952)
1 parent 0b84746 commit eafc5b8

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

pgml-sdks/rust/pgml/javascript/tests/typescript-tests/test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const generate_dummy_documents = (count: number) => {
1818
docs.push({
1919
id: i,
2020
text: `This is a test document: ${i}`,
21+
project: "a10",
2122
uuid: i * 10,
23+
floating_uuid: i * 1.1,
2224
name: `Test Document ${i}`,
2325
});
2426
}
@@ -36,7 +38,7 @@ it("can create collection", () => {
3638

3739
it("can create model", () => {
3840
let model = pgml.newModel("test", "openai", {
39-
"tester": "test 0123948712394871234987"
41+
some_example_parameter: "test 0123948712394871234987",
4042
});
4143
expect(model).toBeTruthy();
4244
});
@@ -74,7 +76,7 @@ it("can vector search with local embeddings", async () => {
7476
await collection.archive();
7577
});
7678

77-
it("can vector search with remote embeddings", async() => {
79+
it("can vector search with remote embeddings", async () => {
7880
let model = pgml.newModel("text-embedding-ada-002", "openai");
7981
let splitter = pgml.newSplitter();
8082
let pipeline = pgml.newPipeline("test_j_p_cvswre_0", model, splitter);
@@ -86,26 +88,34 @@ it("can vector search with remote embeddings", async() => {
8688
await collection.archive();
8789
});
8890

89-
it("can vector search with query builder", async() => {
91+
it("can vector search with query builder", async () => {
9092
let model = pgml.newModel();
9193
let splitter = pgml.newSplitter();
9294
let pipeline = pgml.newPipeline("test_j_p_cvswqb_0", model, splitter);
9395
let collection = pgml.newCollection("test_j_c_cvswqb_1");
9496
await collection.upsert_documents(generate_dummy_documents(3));
9597
await collection.add_pipeline(pipeline);
96-
let results = await collection.query().vector_recall("Here is some query", pipeline).limit(10).fetch_all();
98+
let results = await collection
99+
.query()
100+
.vector_recall("Here is some query", pipeline)
101+
.limit(10)
102+
.fetch_all();
97103
expect(results).toHaveLength(3);
98104
await collection.archive();
99105
});
100106

101-
it("can vector search with query builder with remote embeddings", async() => {
107+
it("can vector search with query builder with remote embeddings", async () => {
102108
let model = pgml.newModel("text-embedding-ada-002", "openai");
103109
let splitter = pgml.newSplitter();
104110
let pipeline = pgml.newPipeline("test_j_p_cvswqbwre_0", model, splitter);
105111
let collection = pgml.newCollection("test_j_c_cvswqbwre_1");
106112
await collection.upsert_documents(generate_dummy_documents(3));
107113
await collection.add_pipeline(pipeline);
108-
let results = await collection.query().vector_recall("Here is some query", pipeline).limit(10).fetch_all();
114+
let results = await collection
115+
.query()
116+
.vector_recall("Here is some query", pipeline)
117+
.limit(10)
118+
.fetch_all();
109119
expect(results).toHaveLength(3);
110120
await collection.archive();
111121
});
@@ -122,10 +132,12 @@ it("can vector search with query builder and metadata filtering", async () => {
122132
.vector_recall("Here is some query", pipeline)
123133
.filter({
124134
metadata: {
125-
$or: [{ uuid: { $eq: 0 } }, { uuid: { $eq: 20 } }],
135+
$or: [{ uuid: { $eq: 0 } }, { floating_uuid: { $lt: 2 } }],
136+
project: { $eq: "a10" },
126137
},
127138
})
128-
.limit(10).fetch_all();
139+
.limit(10)
140+
.fetch_all();
129141
expect(results).toHaveLength(2);
130142
await collection.archive();
131143
});
@@ -141,7 +153,6 @@ it("pipeline to dict", async () => {
141153
let collection = pgml.newCollection("test_j_c_ptd_2");
142154
await collection.add_pipeline(pipeline);
143155
let pipeline_dict = await pipeline.to_dict();
144-
console.log(JSON.stringify(pipeline_dict))
145156
expect(pipeline_dict["name"]).toBe("test_j_p_ptd_0");
146157
await collection.archive();
147158
});

pgml-sdks/rust/pgml/python/tests/test.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def generate_dummy_documents(count: int) -> List[Dict[str, Any]]:
2929
{
3030
"id": i,
3131
"text": "This is a test document: {}".format(i),
32-
"some_random_thing": "This will be metadata on it",
32+
"project": "a10",
33+
"floating_uuid": i * 1.01,
3334
"uuid": i * 10,
3435
"name": "Test Document {}".format(i),
3536
}
@@ -147,17 +148,18 @@ async def test_can_vector_search_with_query_builder_and_metadata_filtering():
147148
results = (
148149
await collection.query()
149150
.vector_recall("Here is some query", pipeline)
150-
.filter({
151-
"metadata": {
152-
"uuid": {
153-
"$eq": 0
154-
}
151+
.filter(
152+
{
153+
"metadata": {
154+
"$or": [{"uuid": {"$eq": 0}}, {"floating_uuid": {"$lt": 2}}],
155+
"project": {"$eq": "a10"},
156+
},
155157
}
156-
})
158+
)
157159
.limit(10)
158160
.fetch_all()
159161
)
160-
assert len(results) == 1
162+
assert len(results) == 2
161163
await collection.archive()
162164

163165

pgml-sdks/rust/pgml/src/filter_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ fn get_value_type(value: &serde_json::Value) -> String {
117117
} else if value.is_string() {
118118
"text".to_string()
119119
} else if value.is_i64() {
120-
"bigint".to_string()
120+
"float8".to_string()
121121
} else if value.is_f64() {
122-
"double".to_string()
122+
"float8".to_string()
123123
} else if value.is_boolean() {
124124
"bool".to_string()
125125
} else {

0 commit comments

Comments
 (0)