Skip to content

Commit

Permalink
[bugfix] fix error handling in readyForUpdate and return NotFound err…
Browse files Browse the repository at this point in the history
…or when delete fails in multiUpdate (#1681)

* 🐛 bugfix return NotFound error when delete fails in multiUpdate

Signed-off-by: vankichi <kyukawa315@gmail.com>

* ♻️ refactor readyForUpdate

Signed-off-by: vankichi <kyukawa315@gmail.com>

* Update pkg/agent/core/ngt/service/ngt.go

Co-authored-by: Yusuke Kato <kpango@vdaas.org>

* Update pkg/agent/core/ngt/service/ngt.go

Co-authored-by: Yusuke Kato <kpango@vdaas.org>
  • Loading branch information
vankichi and kpango authored Jun 1, 2022
1 parent f3f0823 commit 815b44a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/agent/core/ngt/service/ngt.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func (n *ngt) updateMultiple(vecs map[string][]float32, t int64) (err error) {
uuids = append(uuids, uuid)
}
}
err = n.deleteMultiple(uuids, t, false)
err = n.deleteMultiple(uuids, t, true) // `true` is to return NotFound error with non-existent ID
if err != nil {
return err
}
Expand Down Expand Up @@ -1226,10 +1226,12 @@ func (n *ngt) readyForUpdate(uuid string, vec []float32) (err error) {
return errors.ErrInvalidDimensionSize(len(vec), n.GetDimensionSize())
}
ovec, err := n.GetObject(uuid)
if err != nil ||
len(vec) != len(ovec) ||
conv.F32stos(vec) != conv.F32stos(ovec) {
// if error (GetObject cannot find vector) or vector length is not equal or if difference exists let's try update
// if error (GetObject cannot find vector) return error
if err != nil {
return err
}
// if vector length is not equal or if some difference exists let's try update
if len(vec) != len(ovec) || conv.F32stos(vec) != conv.F32stos(ovec) {
return nil
}
// if no difference exists (same vector already exists) return error for skip update
Expand Down

0 comments on commit 815b44a

Please sign in to comment.