@@ -151,7 +151,7 @@ PRIMARY KEY (uuid))`, s.embeddingTableName, s.collectionTableName)
151
151
152
152
func (s Store ) AddDocuments (ctx context.Context , docs []schema.Document , options ... vectorstores.Option ) error {
153
153
opts := s .getOptions (options ... )
154
- if opts .Embedder != nil || opts . ScoreThreshold != 0 || opts .Filters != nil || opts .NameSpace != "" {
154
+ if opts .ScoreThreshold != 0 || opts .Filters != nil || opts .NameSpace != "" {
155
155
return ErrUnsupportedOptions
156
156
}
157
157
@@ -160,7 +160,11 @@ func (s Store) AddDocuments(ctx context.Context, docs []schema.Document, options
160
160
texts = append (texts , doc .PageContent )
161
161
}
162
162
163
- vectors , err := s .embedder .EmbedDocuments (ctx , texts )
163
+ embedder := s .embedder
164
+ if opts .Embedder != nil {
165
+ embedder = opts .Embedder
166
+ }
167
+ vectors , err := embedder .EmbedDocuments (ctx , texts )
164
168
if err != nil {
165
169
return err
166
170
}
@@ -186,11 +190,8 @@ func (s Store) SimilaritySearch(
186
190
numDocuments int ,
187
191
options ... vectorstores.Option ,
188
192
) ([]schema.Document , error ) {
189
- collectionName := s .collectionName
190
193
opts := s .getOptions (options ... )
191
- if nameSpace := s .getNameSpace (opts ); nameSpace != "" {
192
- collectionName = nameSpace
193
- }
194
+ collectionName := s .getNameSpace (opts )
194
195
scoreThreshold , err := s .getScoreThreshold (opts )
195
196
if err != nil {
196
197
return nil , err
@@ -199,7 +200,11 @@ func (s Store) SimilaritySearch(
199
200
if err != nil {
200
201
return nil , err
201
202
}
202
- embedder , err := s .embedder .EmbedQuery (ctx , query )
203
+ embedder := s .embedder
204
+ if opts .Embedder != nil {
205
+ embedder = opts .Embedder
206
+ }
207
+ embedderData , err := embedder .EmbedQuery (ctx , query )
203
208
if err != nil {
204
209
return nil , err
205
210
}
@@ -236,7 +241,7 @@ LIMIT %d`, s.embeddingTableName,
236
241
s .embeddingTableName ,
237
242
s .collectionTableName , s .embeddingTableName , s .collectionTableName , s .collectionTableName , collectionName ,
238
243
whereQuery , numDocuments )
239
- rows , err := tx .Query (ctx , sql , pgvector .NewVector (embedder ))
244
+ rows , err := tx .Query (ctx , sql , pgvector .NewVector (embedderData ))
240
245
if err != nil {
241
246
return nil , err
242
247
}
@@ -295,6 +300,8 @@ func (s Store) createOrGetCollection(ctx context.Context) (string, error) {
295
300
return collectionUUID , nil
296
301
}
297
302
303
+ // getOptions applies given options to default Options and returns it
304
+ // This uses options pattern so clients can easily pass options without changing function signature.
298
305
func (s Store ) getOptions (options ... vectorstores.Option ) vectorstores.Options {
299
306
opts := vectorstores.Options {}
300
307
for _ , opt := range options {
@@ -307,7 +314,7 @@ func (s Store) getNameSpace(opts vectorstores.Options) string {
307
314
if opts .NameSpace != "" {
308
315
return opts .NameSpace
309
316
}
310
- return ""
317
+ return s . collectionName
311
318
}
312
319
313
320
func (s Store ) getScoreThreshold (opts vectorstores.Options ) (float32 , error ) {
@@ -317,6 +324,7 @@ func (s Store) getScoreThreshold(opts vectorstores.Options) (float32, error) {
317
324
return opts .ScoreThreshold , nil
318
325
}
319
326
327
+ // getFilters return metadata filters, now only support map[key]value pattern
320
328
// TODO: should support more types like {"key1": {"key2":"values2"}} or {"key": ["value1", "values2"]}.
321
329
func (s Store ) getFilters (opts vectorstores.Options ) (map [string ]any , error ) {
322
330
if opts .Filters != nil {
0 commit comments