MCPcopy Create free account
hub / github.com/53AI/53AIHub / updateWithAutoCreate

Method updateWithAutoCreate

api/service/rag/entity_vector.go:291–314  ·  view source on GitHub ↗
(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int)

Source from the content-addressed store, hash-verified

289}
290
291func (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
316func (s *EntityVectorService) DeleteCollection(ctx context.Context, collection string) error {
317 if s.vectorDB == nil {

Callers 1

IndexEntityMethod · 0.95

Calls 2

UpdateMethod · 0.65
CreateCollectionMethod · 0.65

Tested by

no test coverage detected