(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int)
| 264 | } |
| 265 | |
| 266 | func (s *EntityVectorService) insertWithAutoCreate(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int) error { |
| 267 | err := s.vectorDB.Insert(ctx, collection, []vectorstore.VectorRecord{record}) |
| 268 | if err == nil { |
| 269 | return nil |
| 270 | } |
| 271 | if vsErr, ok := err.(*vectorstore.VectorStoreError); ok { |
| 272 | if vsErr.Code == vectorstore.ErrCodeCollectionNotFound || vsErr.Code == vectorstore.ErrCodeUnknown { |
| 273 | collectionConfig := vectorstore.CollectionConfig{ |
| 274 | Name: collection, |
| 275 | Dimension: dimension, |
| 276 | Metric: "cosine", |
| 277 | IndexType: "HNSW", |
| 278 | } |
| 279 | if createErr := s.vectorDB.CreateCollection(ctx, collectionConfig); createErr != nil && !vectorstore.IsExistsError(createErr) { |
| 280 | return createErr |
| 281 | } |
| 282 | if insertErr := s.vectorDB.Insert(ctx, collection, []vectorstore.VectorRecord{record}); insertErr != nil { |
| 283 | return insertErr |
| 284 | } |
| 285 | return nil |
| 286 | } |
| 287 | } |
| 288 | return err |
| 289 | } |
| 290 | |
| 291 | func (s *EntityVectorService) updateWithAutoCreate(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int) error { |
| 292 | err := s.vectorDB.Update(ctx, collection, []vectorstore.VectorRecord{record}) |
nothing calls this directly
no test coverage detected