logics

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LatestRecommender          = "latest"
	NonPersonalizedRecommender = "non-personalized/"
	ItemToItemRecommender      = "item-to-item/"
	UserToUserRecommender      = "user-to-user/"
	ExternalRecommender        = "external/"
	CollaborativeRecommender   = "collaborative"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRanker

type ChatRanker struct {
	// contains filtered or unexported fields
}

func NewChatRanker

func NewChatRanker(cfg config.OpenAIConfig, prompt string) (*ChatRanker, error)

func (*ChatRanker) Rank

func (r *ChatRanker) Rank(user *data.User, feedback []*FeedbackItem, items []*data.Item) ([]string, error)

type External

type External struct {
	// contains filtered or unexported fields
}

func NewExternal

func NewExternal(cfg config.ExternalConfig) (*External, error)

func (*External) Close

func (e *External) Close() error

func (*External) Pull

func (e *External) Pull(userId string) (res []string, err error)

type FeedbackItem

type FeedbackItem struct {
	FeedbackType string
	data.Item
}

type IDF

type IDF[T dataset.ID | int32] []float32

type ItemToItem

type ItemToItem interface {
	Timestamp() time.Time
	Items() []*data.Item
	Push(item *data.Item, feedback []int32)
	PopAll(i int) []cache.Score
	Pool() parallel.Pool
}

func NewItemToItem

func NewItemToItem(cfg config.ItemToItemConfig, n int, timestamp time.Time, opts *ItemToItemOptions) (ItemToItem, error)

type ItemToItemOptions

type ItemToItemOptions struct {
	TagsIDF      []float32
	UsersIDF     []float32
	OpenAIConfig config.OpenAIConfig
}

type MatrixFactorizationItems

type MatrixFactorizationItems struct {
	// contains filtered or unexported fields
}

func NewMatrixFactorizationItems

func NewMatrixFactorizationItems(timestamp time.Time) *MatrixFactorizationItems

func (*MatrixFactorizationItems) Add

func (items *MatrixFactorizationItems) Add(itemId string, v []float32)

func (*MatrixFactorizationItems) Marshal

func (items *MatrixFactorizationItems) Marshal(w io.Writer) error

func (*MatrixFactorizationItems) Search

func (items *MatrixFactorizationItems) Search(v []float32, n int) []cache.Score

func (*MatrixFactorizationItems) Unmarshal

func (items *MatrixFactorizationItems) Unmarshal(r io.Reader) error

type MatrixFactorizationUsers

type MatrixFactorizationUsers struct {
	// contains filtered or unexported fields
}

func NewMatrixFactorizationUsers

func NewMatrixFactorizationUsers() *MatrixFactorizationUsers

func (*MatrixFactorizationUsers) Add

func (users *MatrixFactorizationUsers) Add(userId string, v []float32)

func (*MatrixFactorizationUsers) Get

func (users *MatrixFactorizationUsers) Get(userId string) ([]float32, bool)

func (*MatrixFactorizationUsers) Marshal

func (users *MatrixFactorizationUsers) Marshal(w io.Writer) error

func (*MatrixFactorizationUsers) Unmarshal

func (users *MatrixFactorizationUsers) Unmarshal(r io.Reader) error

type NonPersonalized

type NonPersonalized struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewNonPersonalized

func NewNonPersonalized(cfg config.NonPersonalizedConfig, n int, timestamp time.Time) (*NonPersonalized, error)

func (*NonPersonalized) Name

func (l *NonPersonalized) Name() string

func (*NonPersonalized) PopAll

func (l *NonPersonalized) PopAll() []cache.Score

func (*NonPersonalized) Push

func (l *NonPersonalized) Push(item data.Item, feedback []data.Feedback)

func (*NonPersonalized) Timestamp

func (l *NonPersonalized) Timestamp() time.Time

type Recommender

type Recommender struct {
	// contains filtered or unexported fields
}

func NewRecommender

func NewRecommender(config config.RecommendConfig, cacheClient cache.Database, dataClient data.Database, online bool, userId string, categories []string) (*Recommender, error)

func (*Recommender) ExcludeSet

func (r *Recommender) ExcludeSet() mapset.Set[string]

func (*Recommender) IsColdStart

func (r *Recommender) IsColdStart() bool

func (*Recommender) Recommend

func (r *Recommender) Recommend(ctx context.Context, limit int) ([]cache.Score, error)

func (*Recommender) RecommendSequential

func (r *Recommender) RecommendSequential(ctx context.Context, result []cache.Score, limit int, names ...string) ([]cache.Score, string, error)

RecommendSequential recommend items from multiple recommenders sequentially util reaching the limit. If limit <= 0, all recommendations are returned.

func (*Recommender) UserFeedback

func (r *Recommender) UserFeedback() []data.Feedback

type RecommenderFunc

type RecommenderFunc func(ctx context.Context) ([]cache.Score, string, error)

type UserToUser

type UserToUser interface {
	Users() []*data.User
	Push(user *data.User, feedback []int32)
	PopAll(i int) []cache.Score
	Timestamp() time.Time
}

func NewUserToUser

func NewUserToUser(cfg config.UserToUserConfig, n int, timestamp time.Time, opts *UserToUserOptions) (UserToUser, error)

type UserToUserOptions

type UserToUserOptions struct {
	TagsIDF  []float32
	ItemsIDF []float32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL