Skip to content

Commit 0b84746

Browse files
authored
Updated docs (#951)
1 parent a7d7fca commit 0b84746

File tree

4 files changed

+88
-51
lines changed

4 files changed

+88
-51
lines changed

pgml-sdks/rust/pgml/javascript/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ const model = pgml.newModel(
375375
376376
**Use an OpenAI model**
377377
```javascript
378-
const model = pgml.newModel(name="text-embedding-ada-002", source="openai")
378+
const model = pgml.newModel("text-embedding-ada-002", "openai")
379379
```
380380
381381
### Splitters

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pgml from '../../index.js'
1+
import pgml from "../../index.js";
22

33
////////////////////////////////////////////////////////////////////////////////////
44
////////////////////////////////////////////////////////////////////////////////////
@@ -9,29 +9,21 @@ import pgml from '../../index.js'
99
////////////////////////////////////////////////////////////////////////////////////
1010
////////////////////////////////////////////////////////////////////////////////////
1111

12-
const DATABASE_URL = process.env.DATABASE_URL;
13-
if (!DATABASE_URL) {
14-
console.log("No DATABASE_URL environment variable found. Please set one")
15-
process.exit(1)
16-
}
1712
const LOG_LEVEL = process.env.LOG_LEVEL ? process.env.LOG_LEVEL : "ERROR";
18-
1913
pgml.js_init_logger(LOG_LEVEL);
2014

2115
const generate_dummy_documents = (count: number) => {
2216
let docs = [];
2317
for (let i = 0; i < count; i++) {
2418
docs.push({
25-
"id": i,
26-
"text": `This is a test document: ${i}`,
27-
"metadata": {
28-
"uuid": i * 10,
29-
"name": `Test Document ${i}`
30-
}
19+
id: i,
20+
text: `This is a test document: ${i}`,
21+
uuid: i * 10,
22+
name: `Test Document ${i}`,
3123
});
3224
}
3325
return docs;
34-
}
26+
};
3527

3628
///////////////////////////////////////////////////
3729
// Test the API exposed is correct ////////////////
@@ -118,6 +110,25 @@ it("can vector search with query builder with remote embeddings", async() => {
118110
await collection.archive();
119111
});
120112

113+
it("can vector search with query builder and metadata filtering", async () => {
114+
let model = pgml.newModel();
115+
let splitter = pgml.newSplitter();
116+
let pipeline = pgml.newPipeline("test_j_p_cvswqbamf_0", model, splitter);
117+
let collection = pgml.newCollection("test_j_c_cvswqbamf_4");
118+
await collection.upsert_documents(generate_dummy_documents(3));
119+
await collection.add_pipeline(pipeline);
120+
let results = await collection
121+
.query()
122+
.vector_recall("Here is some query", pipeline)
123+
.filter({
124+
metadata: {
125+
$or: [{ uuid: { $eq: 0 } }, { uuid: { $eq: 20 } }],
126+
},
127+
})
128+
.limit(10).fetch_all();
129+
expect(results).toHaveLength(2);
130+
await collection.archive();
131+
});
121132

122133
///////////////////////////////////////////////////
123134
// Test user output facing functions //////////////

pgml-sdks/rust/pgml/python/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,13 @@ results = (
315315
{
316316
"$and": [
317317
{
318-
"$eq": {
319-
"uuid": 1
318+
"uuid": {
319+
"$eq": 1
320320
}
321321
},
322322
{
323-
"$lt": {
324-
"index": 100
323+
"index": {
324+
"$lt": 100
325325
}
326326
}
327327
]

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

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def generate_dummy_documents(count: int) -> List[Dict[str, Any]]:
3030
"id": i,
3131
"text": "This is a test document: {}".format(i),
3232
"some_random_thing": "This will be metadata on it",
33-
"metadata": {"uuid": i * 10, "name": "Test Document {}".format(i)},
33+
"uuid": i * 10,
34+
"name": "Test Document {}".format(i),
3435
}
3536
)
3637
return dummy_documents
@@ -135,6 +136,31 @@ async def test_can_vector_search_with_query_builder_with_remote_embeddings():
135136
await collection.archive()
136137

137138

139+
@pytest.mark.asyncio
140+
async def test_can_vector_search_with_query_builder_and_metadata_filtering():
141+
model = pgml.Model()
142+
splitter = pgml.Splitter()
143+
pipeline = pgml.Pipeline("test_p_p_tcvswqbamf_1", model, splitter)
144+
collection = pgml.Collection(name="test_p_c_tcvswqbamf_2")
145+
await collection.upsert_documents(generate_dummy_documents(3))
146+
await collection.add_pipeline(pipeline)
147+
results = (
148+
await collection.query()
149+
.vector_recall("Here is some query", pipeline)
150+
.filter({
151+
"metadata": {
152+
"uuid": {
153+
"$eq": 0
154+
}
155+
}
156+
})
157+
.limit(10)
158+
.fetch_all()
159+
)
160+
assert len(results) == 1
161+
await collection.archive()
162+
163+
138164
###################################################
139165
## Test user output facing functions ##############
140166
###################################################
@@ -158,17 +184,17 @@ async def test_pipeline_to_dict():
158184
###################################################
159185

160186

161-
def vector_search(collection_name, pipeline_name):
162-
collection = pgml.Collection(collection_name)
163-
pipeline = pgml.Pipeline(pipeline_name)
164-
result = asyncio.run(
165-
collection.query()
166-
.vector_recall("Here is some query", pipeline)
167-
.limit(10)
168-
.fetch_all()
169-
)
170-
print(result)
171-
return [0, 1, 2]
187+
# def vector_search(collection_name, pipeline_name):
188+
# collection = pgml.Collection(collection_name)
189+
# pipeline = pgml.Pipeline(pipeline_name)
190+
# result = asyncio.run(
191+
# collection.query()
192+
# .vector_recall("Here is some query", pipeline)
193+
# .limit(10)
194+
# .fetch_all()
195+
# )
196+
# print(result)
197+
# return [0, 1, 2]
172198

173199

174200
# @pytest.mark.asyncio
@@ -200,23 +226,23 @@ def vector_search(collection_name, pipeline_name):
200226
###################################################
201227

202228

203-
async def silas_test_add_pipeline():
204-
model = pgml.Model()
205-
splitter = pgml.Splitter()
206-
pipeline = pgml.Pipeline("silas_test_p_1", model, splitter)
207-
collection = pgml.Collection(name="silas_test_c_10")
208-
await collection.add_pipeline(pipeline)
209-
210-
async def silas_test_upsert_documents():
211-
collection = pgml.Collection(name="silas_test_c_9")
212-
await collection.upsert_documents(generate_dummy_documents(10))
213-
214-
async def silas_test_vector_search():
215-
pipeline = pgml.Pipeline("silas_test_p_1")
216-
collection = pgml.Collection(name="silas_test_c_9")
217-
results = await collection.vector_search("Here is some query", pipeline)
218-
print(results)
219-
220-
# asyncio.run(silas_test_add_pipeline())
221-
# asyncio.run(silas_test_upsert_documents())
222-
# asyncio.run(silas_test_vector_search())
229+
# async def test_add_pipeline():
230+
# model = pgml.Model()
231+
# splitter = pgml.Splitter()
232+
# pipeline = pgml.Pipeline("silas_test_p_1", model, splitter)
233+
# collection = pgml.Collection(name="silas_test_c_10")
234+
# await collection.add_pipeline(pipeline)
235+
#
236+
# async def test_upsert_documents():
237+
# collection = pgml.Collection(name="silas_test_c_9")
238+
# await collection.upsert_documents(generate_dummy_documents(10))
239+
#
240+
# async def test_vector_search():
241+
# pipeline = pgml.Pipeline("silas_test_p_1")
242+
# collection = pgml.Collection(name="silas_test_c_9")
243+
# results = await collection.vector_search("Here is some query", pipeline)
244+
# print(results)
245+
246+
# asyncio.run(test_add_pipeline())
247+
# asyncio.run(test_upsert_documents())
248+
# asyncio.run(test_vector_search())

0 commit comments

Comments
 (0)
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