github.com/weaviate/weaviate@v1.24.6/usecases/objects/vector.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package objects 13 14 import ( 15 "context" 16 "fmt" 17 18 "github.com/go-openapi/strfmt" 19 "github.com/weaviate/weaviate/entities/additional" 20 "github.com/weaviate/weaviate/entities/models" 21 "github.com/weaviate/weaviate/entities/moduletools" 22 "github.com/weaviate/weaviate/entities/search" 23 ) 24 25 func (m *Manager) updateRefVector(ctx context.Context, principal *models.Principal, 26 className string, id strfmt.UUID, tenant string, 27 ) error { 28 if m.modulesProvider.UsingRef2Vec(className) { 29 parent, err := m.vectorRepo.Object(ctx, className, id, 30 search.SelectProperties{}, additional.Properties{}, nil, tenant) 31 if err != nil { 32 return fmt.Errorf("find parent '%s/%s': %w", 33 className, id, err) 34 } 35 36 obj := parent.Object() 37 38 class, err := m.schemaManager.GetClass(ctx, principal, className) 39 if err != nil { 40 return err 41 } 42 compFactory := func() (moduletools.VectorizablePropsComparator, error) { 43 return moduletools.NewVectorizablePropsComparatorDummy(class.Properties, obj.Properties), nil 44 } 45 if err := m.modulesProvider.UpdateVector( 46 ctx, obj, class, compFactory, m.findObject, m.logger); err != nil { 47 return fmt.Errorf("calculate ref vector for '%s/%s': %w", 48 className, id, err) 49 } 50 51 if err := m.vectorRepo.PutObject(ctx, obj, obj.Vector, obj.Vectors, nil); err != nil { 52 return fmt.Errorf("put object: %w", err) 53 } 54 55 return nil 56 } 57 58 // nothing to do 59 return nil 60 } 61 62 // TODO: remove this method and just pass m.vectorRepo.Object to 63 // m.modulesProvider.UpdateVector when m.vectorRepo.ObjectByID 64 // is finally removed 65 func (m *Manager) findObject(ctx context.Context, class string, 66 id strfmt.UUID, props search.SelectProperties, addl additional.Properties, 67 tenant string, 68 ) (*search.Result, error) { 69 // to support backwards compat 70 if class == "" { 71 return m.vectorRepo.ObjectByID(ctx, id, props, addl, tenant) 72 } 73 return m.vectorRepo.Object(ctx, class, id, props, addl, nil, tenant) 74 } 75 76 // TODO: remove this method and just pass b.vectorRepo.Object to 77 // b.modulesProvider.UpdateVector when b.vectorRepo.ObjectByID 78 // is finally removed 79 func (b *BatchManager) findObject(ctx context.Context, class string, 80 id strfmt.UUID, props search.SelectProperties, addl additional.Properties, 81 tenant string, 82 ) (*search.Result, error) { 83 // to support backwards compat 84 if class == "" { 85 return b.vectorRepo.ObjectByID(ctx, id, props, addl, tenant) 86 } 87 return b.vectorRepo.Object(ctx, class, id, props, addl, nil, tenant) 88 }