@@ -74,33 +74,27 @@ describe("PGVectorStore", () => {
74
74
expect ( results [ 0 ] . pageContent ) . toEqual ( "Cat drinks milk" ) ;
75
75
} ) ;
76
76
77
- test . only ( "Test MMR search" , async ( ) => {
77
+ test ( "Test MMR search" , async ( ) => {
78
78
const documents = [
79
79
{
80
80
pageContent : "hello" ,
81
81
metadata : { a : 1 } ,
82
82
} ,
83
- {
84
- pageContent : "Cat drinks milk" ,
85
- metadata : { a : 2 } ,
86
- } ,
87
83
{
88
84
pageContent : "foo" ,
89
85
metadata : { a : 2 } ,
90
86
} ,
91
- { pageContent : "hi " , metadata : { a : 1 } } ,
87
+ { pageContent : "bye " , metadata : { a : 1 } } ,
92
88
] ;
93
89
await pgvectorVectorStore . addDocuments ( documents ) ;
94
90
const results = await pgvectorVectorStore . maxMarginalRelevanceSearch (
95
- "milk " ,
91
+ "hello " ,
96
92
{
97
- k : 2 ,
93
+ k : 4 ,
98
94
}
99
95
) ;
100
96
101
- expect ( results ) . toHaveLength ( 2 ) ;
102
- expect ( results [ 0 ] . pageContent ) . toEqual ( "Cat drinks milk" ) ;
103
- expect ( results [ 1 ] . pageContent ) . toEqual ( "foo" ) ;
97
+ expect ( results ) . toHaveLength ( 3 ) ;
104
98
} ) ;
105
99
106
100
test ( "PGvector can save documents with a list greater than default chunk size" , async ( ) => {
@@ -157,16 +151,28 @@ describe("PGVectorStore", () => {
157
151
158
152
expect ( result . length ) . toEqual ( 2 ) ;
159
153
expect ( result ) . toEqual ( [
160
- { pageContent : "Lorem Ipsum" , metadata : { a : 100 } } ,
161
- { pageContent : "Lorem Ipsum" , metadata : { a : 300 } } ,
154
+ {
155
+ id : expect . any ( String ) ,
156
+ pageContent : "Lorem Ipsum" ,
157
+ metadata : { a : 100 } ,
158
+ } ,
159
+ {
160
+ id : expect . any ( String ) ,
161
+ pageContent : "Lorem Ipsum" ,
162
+ metadata : { a : 300 } ,
163
+ } ,
162
164
] ) ;
163
165
164
166
const result2 = await pgvectorVectorStore . similaritySearch ( "hello" , 2 , {
165
167
a : 200 ,
166
168
} ) ;
167
169
expect ( result2 . length ) . toEqual ( 1 ) ;
168
170
expect ( result2 ) . toEqual ( [
169
- { pageContent : "Lorem Ipsum" , metadata : { a : 200 } } ,
171
+ {
172
+ id : expect . any ( String ) ,
173
+ pageContent : "Lorem Ipsum" ,
174
+ metadata : { a : 200 } ,
175
+ } ,
170
176
] ) ;
171
177
172
178
const result3 = await pgvectorVectorStore . similaritySearch ( "hello" , 3 ) ;
@@ -191,8 +197,16 @@ describe("PGVectorStore", () => {
191
197
192
198
expect ( result . length ) . toEqual ( 2 ) ;
193
199
expect ( result ) . toEqual ( [
194
- { pageContent : "Lorem Ipsum" , metadata : { a : [ "tag1" , "tag2" ] } } ,
195
- { pageContent : "Lorem Ipsum" , metadata : { a : [ "tag1" ] } } ,
200
+ {
201
+ id : expect . any ( String ) ,
202
+ pageContent : "Lorem Ipsum" ,
203
+ metadata : { a : [ "tag1" , "tag2" ] } ,
204
+ } ,
205
+ {
206
+ id : expect . any ( String ) ,
207
+ pageContent : "Lorem Ipsum" ,
208
+ metadata : { a : [ "tag1" ] } ,
209
+ } ,
196
210
] ) ;
197
211
198
212
const result2 = await pgvectorVectorStore . similaritySearch ( "hello" , 2 , {
@@ -202,14 +216,28 @@ describe("PGVectorStore", () => {
202
216
} ) ;
203
217
expect ( result2 . length ) . toEqual ( 2 ) ;
204
218
expect ( result2 ) . toEqual ( [
205
- { pageContent : "Lorem Ipsum" , metadata : { a : [ "tag1" , "tag2" ] } } ,
206
- { pageContent : "Lorem Ipsum" , metadata : { a : [ "tag2" ] } } ,
219
+ {
220
+ id : expect . any ( String ) ,
221
+ pageContent : "Lorem Ipsum" ,
222
+ metadata : { a : [ "tag1" , "tag2" ] } ,
223
+ } ,
224
+ {
225
+ id : expect . any ( String ) ,
226
+ pageContent : "Lorem Ipsum" ,
227
+ metadata : { a : [ "tag2" ] } ,
228
+ } ,
207
229
] ) ;
208
230
209
231
const result3 = await pgvectorVectorStore . similaritySearch ( "hello" , 3 ) ;
210
232
211
233
expect ( result3 . length ) . toEqual ( 3 ) ;
212
- expect ( result3 ) . toEqual ( documents ) ;
234
+ expect ( result3 ) . toEqual (
235
+ documents . map ( ( doc ) => {
236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-param-reassign
237
+ ( doc as any ) . id = expect . any ( String ) ;
238
+ return doc ;
239
+ } )
240
+ ) ;
213
241
} ) ;
214
242
215
243
test ( "PGvector can delete document by id" , async ( ) => {
@@ -439,16 +467,28 @@ describe("PGVectorStore with collection", () => {
439
467
440
468
expect ( result . length ) . toEqual ( 2 ) ;
441
469
expect ( result ) . toEqual ( [
442
- { pageContent : "Lorem Ipsum" , metadata : { a : 100 } } ,
443
- { pageContent : "Lorem Ipsum" , metadata : { a : 300 } } ,
470
+ {
471
+ id : expect . any ( String ) ,
472
+ pageContent : "Lorem Ipsum" ,
473
+ metadata : { a : 100 } ,
474
+ } ,
475
+ {
476
+ id : expect . any ( String ) ,
477
+ pageContent : "Lorem Ipsum" ,
478
+ metadata : { a : 300 } ,
479
+ } ,
444
480
] ) ;
445
481
446
482
const result2 = await pgvectorVectorStore . similaritySearch ( "hello" , 2 , {
447
483
a : 200 ,
448
484
} ) ;
449
485
expect ( result2 . length ) . toEqual ( 1 ) ;
450
486
expect ( result2 ) . toEqual ( [
451
- { pageContent : "Lorem Ipsum" , metadata : { a : 200 } } ,
487
+ {
488
+ id : expect . any ( String ) ,
489
+ pageContent : "Lorem Ipsum" ,
490
+ metadata : { a : 200 } ,
491
+ } ,
452
492
] ) ;
453
493
454
494
const result3 = await pgvectorVectorStore . similaritySearch ( "hello" , 3 ) ;
@@ -667,16 +707,28 @@ describe("PGVectorStore with schema", () => {
667
707
668
708
expect ( result . length ) . toEqual ( 2 ) ;
669
709
expect ( result ) . toEqual ( [
670
- { pageContent : "Lorem Ipsum" , metadata : { a : 100 } } ,
671
- { pageContent : "Lorem Ipsum" , metadata : { a : 300 } } ,
710
+ {
711
+ id : expect . any ( String ) ,
712
+ pageContent : "Lorem Ipsum" ,
713
+ metadata : { a : 100 } ,
714
+ } ,
715
+ {
716
+ id : expect . any ( String ) ,
717
+ pageContent : "Lorem Ipsum" ,
718
+ metadata : { a : 300 } ,
719
+ } ,
672
720
] ) ;
673
721
674
722
const result2 = await pgvectorVectorStore . similaritySearch ( "hello" , 2 , {
675
723
a : 200 ,
676
724
} ) ;
677
725
expect ( result2 . length ) . toEqual ( 1 ) ;
678
726
expect ( result2 ) . toEqual ( [
679
- { pageContent : "Lorem Ipsum" , metadata : { a : 200 } } ,
727
+ {
728
+ id : expect . any ( String ) ,
729
+ pageContent : "Lorem Ipsum" ,
730
+ metadata : { a : 200 } ,
731
+ } ,
680
732
] ) ;
681
733
682
734
const result3 = await pgvectorVectorStore . similaritySearch ( "hello" , 3 ) ;
0 commit comments