discovery

package
v0.58.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package discovery produces "similar to this work" and "for you" lists. A Candidates source generates ranked candidates; Recommender applies the shared policy (tenant, kinds, anchor, seen and disliked exclusions, dedupe, limit, popularity fill) so every source gets it. Engagement is the default co-engagement source; Fallback composes a new source over it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Ref   contentref.ContentRef
	Score float64
}

Candidate is one ranked work.

type Candidates

type Candidates interface {
	Similar(ctx context.Context, anchor contentref.ContentRef, q Query) ([]Candidate, error)
	ForSubject(ctx context.Context, subject signal.Subject, q Query) ([]Candidate, error)
}

Candidates generates ranked candidate works. Order is rank. Implementations should oversample past Limit: Recommender filters afterward and truncates.

type Engagement

type Engagement struct {
	Store  *signal.Store
	Tenant string
	// RRFK is the seed fusion constant (default 60).
	RRFK int
}

Engagement is the co-engagement Candidates source: Similar reads works co-engaged with the anchor; ForSubject seeds from the subject's highest-signal non-negative works and RRF-fuses each seed's co-engaged list.

func NewEngagement

func NewEngagement(conn signal.Conn, database, tenant string) (Engagement, error)

NewEngagement builds the default source over a hub's ClickHouse database.

func (Engagement) ForSubject

func (e Engagement) ForSubject(ctx context.Context, subject signal.Subject, q Query) ([]Candidate, error)

ForSubject never returns its seeds.

func (Engagement) Similar

func (e Engagement) Similar(ctx context.Context, anchor contentref.ContentRef, q Query) ([]Candidate, error)

type Fallback

type Fallback struct {
	Primary, Secondary Candidates
	OnError            func(error)
}

Fallback serves Primary and uses Secondary when Primary fails (after OnError) or returns fewer than Limit candidates (appended, deduplicated).

func (Fallback) ForSubject

func (f Fallback) ForSubject(ctx context.Context, subject signal.Subject, q Query) ([]Candidate, error)

func (Fallback) Similar

func (f Fallback) Similar(ctx context.Context, anchor contentref.ContentRef, q Query) ([]Candidate, error)

type Hit

type Hit struct {
	contentref.ContentRef
	Score float32
}

Hit is one ranked work of a discovery list.

type Query

type Query struct {
	// ContentKinds limits candidate kinds (empty = any).
	ContentKinds []string
	// Limit is the number of results the caller returns after filtering.
	Limit int
	// Window bounds the evidence (zero = all time).
	Window signal.Window
	// SeedLimit and SeedContentKinds bound which of the subject's history
	// informs ForSubject (0 / empty = implementation default).
	SeedLimit        int
	SeedContentKinds []string
}

Query bounds one candidate request.

type RecommendOptions

type RecommendOptions struct {
	// ContentKinds are the candidate kinds to recommend. Required.
	ContentKinds []string

	// Limit caps results (default: Recommender.DefaultLimit).
	Limit int

	// SeedLimit is how many of the subject's highest-signal works inform
	// candidates (source default; Engagement: 5).
	SeedLimit int

	// SeedContentKinds limits which kinds may seed (default: any).
	SeedContentKinds []string

	// IncludeSeen keeps already-seen works in results (default: excluded).
	IncludeSeen bool

	// PopularWindow is the popularity window used to fill out results on
	// cold start or thin candidate sets (zero = all time, like every Window).
	PopularWindow signal.Window
}

RecommendOptions controls Recommend ("for you": subject → works).

type Recommender

type Recommender struct {
	Candidates Candidates
	Store      *signal.Store
	Tenant     string
	// DefaultLimit applies when options leave Limit zero (default 20).
	DefaultLimit int
	// RRFK scales popularity-fill tail scores (default 60).
	RRFK int
}

Recommender turns a Candidates source into tenant-scoped discovery lists.

func (Recommender) Recommend

func (r Recommender) Recommend(ctx context.Context, subject signal.Subject, opts RecommendOptions) ([]Hit, error)

Recommend returns "for you" works for a subject: excluding already-seen (unless IncludeSeen) and always disliked works, filled from popularity on cold start or thin candidates.

func (Recommender) Similar

func (r Recommender) Similar(ctx context.Context, anchor contentref.ContentRef, opts SimilarOptions) ([]Hit, error)

Similar returns works like the anchor, never the anchor itself.

type SimilarOptions

type SimilarOptions struct {
	Limit int
	// ContentKinds limits result kinds (default: any).
	ContentKinds []string
	// Window bounds the candidate evidence (default all time).
	Window signal.Window

	// ExcludeSeenFor drops works this subject has already seen (and always
	// drops works they negatively reacted to).
	ExcludeSeenFor *signal.Subject
}

SimilarOptions controls Similar ("more like this").

Jump to

Keyboard shortcuts

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