(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int)
| 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}) |
| 293 | if err == nil { |
| 294 | return nil |
| 295 | } |
| 296 | if vsErr, ok := err.(*vectorstore.VectorStoreError); ok { |
| 297 | if vsErr.Code == vectorstore.ErrCodeCollectionNotFound || vsErr.Code == vectorstore.ErrCodeUnknown { |
| 298 | collectionConfig := vectorstore.CollectionConfig{ |
| 299 | Name: collection, |
| 300 | Dimension: dimension, |
| 301 | Metric: "cosine", |
| 302 | IndexType: "HNSW", |
| 303 | } |
| 304 | if createErr := s.vectorDB.CreateCollection(ctx, collectionConfig); createErr != nil && !vectorstore.IsExistsError(createErr) { |
| 305 | return createErr |
| 306 | } |
| 307 | if updateErr := s.vectorDB.Update(ctx, collection, []vectorstore.VectorRecord{record}); updateErr != nil { |
| 308 | return updateErr |
| 309 | } |
| 310 | return nil |
| 311 | } |
| 312 | } |
| 313 | return err |
| 314 | } |
| 315 | |
| 316 | func (s *EntityVectorService) DeleteCollection(ctx context.Context, collection string) error { |
| 317 | if s.vectorDB == nil { |
no test coverage detected