Skip to content

Commit

Permalink
add top n recommenders to candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz committed May 6, 2023
1 parent a4bb5e3 commit 319044c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sync"
"time"

"github.com/antonmedv/expr"
"github.com/go-playground/locales/en"
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
Expand Down Expand Up @@ -109,6 +110,7 @@ type RecommendConfig struct {
Replacement ReplacementConfig `mapstructure:"replacement"`
Offline OfflineConfig `mapstructure:"offline"`
Online OnlineConfig `mapstructure:"online"`
Candidate CandidateConfig `mapstructure:"candidate"`
}

type DataSourceConfig struct {
Expand Down Expand Up @@ -164,6 +166,20 @@ type OnlineConfig struct {
NumFeedbackFallbackItemBased int `mapstructure:"num_feedback_fallback_item_based" validate:"gt=0"`
}

type CandidateConfig struct {
Top []TopConfig `mapstructure:"top"`
}

type TopConfig struct {
Name string `mapstructure:"name" validate:"required"`
Score string `mapstructure:"score" validate:"required"`
}

func (top *TopConfig) Validate() error {
_, err := expr.Compile(top.Score)
return err
}

type TracingConfig struct {
EnableTracing bool `mapstructure:"enable_tracing"`
Exporter string `mapstructure:"exporter" validate:"oneof=jaeger zipkin otlp otlphttp"`
Expand Down
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,10 @@ func TestConfig_OfflineRecommendDigest(t *testing.T) {
cfg2.Recommend.Replacement.PositiveReplacementDecay = 0.2
assert.Equal(t, cfg1.OfflineRecommendDigest(), cfg2.OfflineRecommendDigest())
}

func TestTopConfig(t *testing.T) {
top := TopConfig{Score: "a+b"}
assert.NoError(t, top.Validate())
top = TopConfig{Score: "%%"}
assert.Error(t, top.Validate())
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/ReneKroon/ttlcache/v2 v2.11.0
github.com/XSAM/otelsql v0.17.0
github.com/antonmedv/expr v1.12.5
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/benhoyt/goawk v1.20.0
github.com/bits-and-blooms/bitset v1.2.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antonmedv/expr v1.12.5 h1:Fq4okale9swwL3OeLLs9WD9H6GbgBLJyN/NUHRv+n0E=
github.com/antonmedv/expr v1.12.5/go.mod h1:FPC8iWArxls7axbVLsW+kpg1mz29A1b2M6jt+hZfDkU=
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA=
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
Expand Down

0 comments on commit 319044c

Please sign in to comment.