Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56d6b54

Browse files
authored
Updated docs (#951)
1 parentfb27d39 commit56d6b54

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-
constmodel=pgml.newModel(name="text-embedding-ada-002",source="openai")
378+
constmodel=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-
importpgmlfrom'../../index.js'
1+
importpgmlfrom"../../index.js";
22

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

12-
constDATABASE_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
constLOG_LEVEL=process.env.LOG_LEVEL ?process.env.LOG_LEVEL :"ERROR";
18-
1913
pgml.js_init_logger(LOG_LEVEL);
2014

2115
constgenerate_dummy_documents=(count:number)=>{
2216
letdocs=[];
2317
for(leti=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
returndocs;
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
awaitcollection.archive();
119111
});
120112

113+
it("can vector search with query builder and metadata filtering",async()=>{
114+
letmodel=pgml.newModel();
115+
letsplitter=pgml.newSplitter();
116+
letpipeline=pgml.newPipeline("test_j_p_cvswqbamf_0",model,splitter);
117+
letcollection=pgml.newCollection("test_j_c_cvswqbamf_4");
118+
awaitcollection.upsert_documents(generate_dummy_documents(3));
119+
awaitcollection.add_pipeline(pipeline);
120+
letresults=awaitcollection
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+
awaitcollection.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
returndummy_documents
@@ -135,6 +136,31 @@ async def test_can_vector_search_with_query_builder_with_remote_embeddings():
135136
awaitcollection.archive()
136137

137138

139+
@pytest.mark.asyncio
140+
asyncdeftest_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+
awaitcollection.upsert_documents(generate_dummy_documents(3))
146+
awaitcollection.add_pipeline(pipeline)
147+
results= (
148+
awaitcollection.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+
assertlen(results)==1
161+
awaitcollection.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-
defvector_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-
asyncdefsilas_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-
awaitcollection.add_pipeline(pipeline)
209-
210-
asyncdefsilas_test_upsert_documents():
211-
collection=pgml.Collection(name="silas_test_c_9")
212-
awaitcollection.upsert_documents(generate_dummy_documents(10))
213-
214-
asyncdefsilas_test_vector_search():
215-
pipeline=pgml.Pipeline("silas_test_p_1")
216-
collection=pgml.Collection(name="silas_test_c_9")
217-
results=awaitcollection.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 deftest_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 deftest_upsert_documents():
237+
# collection = pgml.Collection(name="silas_test_c_9")
238+
# await collection.upsert_documents(generate_dummy_documents(10))
239+
#
240+
#async deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp