Skip to content

Commit

Permalink
Add Search_Config validation (#2811) (#2817)
Browse files Browse the repository at this point in the history
* add Search_Config validation

* change to error function and generate individual errors

* add search configuration

Co-authored-by: Kosuke Morimoto <[email protected]>
Co-authored-by: Kiichiro YUKAWA <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent 9d6d6d4 commit 220a33f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/errors/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ var (

// ErrIndexNotFound represents an error that the index not found.
ErrIndexNotFound = New("index not found")

// ErrInvalidSearchConfig represents an error that the invalid Search Configuration.
ErrInvalidSearchConfig = func(msg string) error {
return Errorf("Invalid Search_Config: %s", msg)
}
)
4 changes: 4 additions & 0 deletions pkg/gateway/lb/handler/grpc/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (s *server) aggregationSearch(
}
}()

if bcfg == nil {
return nil, nil, errors.ErrInvalidSearchConfig("bcfg is nil in aggregationSearch")
}

num := aggr.GetNum()
min := int(bcfg.GetMinNum())

Expand Down
22 changes: 22 additions & 0 deletions pkg/gateway/lb/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,28 @@ func (s *server) doSearch(
}
}()

if cfg == nil {
err = errors.ErrInvalidSearchConfig("search config is nil in doSearch")
err = status.WrapWithInvalidArgument(apiName+"/doSearch", err, &errdetails.RequestInfo{
RequestId: "Search_Config is nil",
ServingData: "Search_Config is nil",
},
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequestFieldViolation{
{
Field: "Search_Config is nil",
Description: err.Error(),
},
},
})
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeInvalidArgument(err.Error())...)
span.SetStatus(trace.StatusError, err.Error())
}
return nil, nil, err
}

var (
num = int(cfg.GetNum())
fnum int
Expand Down
5 changes: 5 additions & 0 deletions pkg/tools/cli/loadtest/service/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func searchRequestProvider(dataset assets.Dataset) (func() any, int, error) {
}
ret = &payload.Search_Request{
Vector: v.([]float32),
Config: &payload.Search_Config{
Num: 10,
Radius: -1,
Epsilon: 0.1,
},
}
}
return ret
Expand Down

0 comments on commit 220a33f

Please sign in to comment.