Documentation
¶
Overview ¶
Package contentkit is the deterministic content library: tenant-scoped keyword search over host content, the ClickHouse signal plane, and the discovery reads over both. The DocumentSink port publishes document changes to optional external consumers.
Index ¶
- Constants
- Variables
- func Migrate(ctx context.Context, cfg MigrateConfig) error
- func NewEvalRunner(client *Client, base SearchOptions) eval.CaseRunner
- type CandidateTrace
- type CatalogQuery
- type Client
- func (c *Client) Search(ctx context.Context, userText string, opts SearchOptions) (SearchResult, error)
- func (c *Client) SearchWithTrace(ctx context.Context, userText string, opts SearchOptions) (SearchResult, SearchTrace, error)
- func (c *Client) Tenant() string
- func (c *Client) Typeahead(ctx context.Context, userText string, opts TypeaheadOptions) ([]TypeaheadHit, error)
- type ClientConfig
- type ContentCatalog
- type ContentCatalogFunc
- type ContentKey
- type ContentRef
- type ContributionTrace
- type DocumentKey
- type DocumentSink
- type Eligibility
- type EmbeddedConfig
- type EmbeddedHub
- func (h *EmbeddedHub) Attribution(ctx context.Context, opts signal.AttributionOptions) (signal.AttributionPage, error)
- func (h *EmbeddedHub) Client() *Client
- func (h *EmbeddedHub) Content(contentKind, contentID string) ContentRef
- func (h *EmbeddedHub) EnforceErasures(ctx context.Context) (signal.ErasureReport, error)
- func (h *EmbeddedHub) EraseSubjects(ctx context.Context, subjects []signal.Subject) (signal.ErasureReport, error)
- func (h *EmbeddedHub) Forget(ctx context.Context, subject signal.Subject, contentKind, contentID string) error
- func (h *EmbeddedHub) ForgetExposures(ctx context.Context, subject signal.Subject) error
- func (h *EmbeddedHub) History(ctx context.Context, subject signal.Subject, opts signal.HistoryOptions) ([]signal.StateRow, error)
- func (h *EmbeddedHub) HistoryCount(ctx context.Context, subject signal.Subject, opts signal.HistoryOptions) (int64, error)
- func (h *EmbeddedHub) Inventory(ctx context.Context) ([]signal.InventoryRow, error)
- func (h *EmbeddedHub) Metrics(ctx context.Context, refs []ContentRef, window signal.Window) (map[ContentKey]signal.ContentMetrics, error)
- func (h *EmbeddedHub) Popular(ctx context.Context, contentKind string, opts signal.PopularOptions) ([]signal.PopularHit, error)
- func (h *EmbeddedHub) PopularityFor(ctx context.Context, contentKind string, ids []string, window signal.Window) (map[string]float64, error)
- func (h *EmbeddedHub) PurgeContentKinds(ctx context.Context, contentKinds []string) error
- func (h *EmbeddedHub) Recommend(ctx context.Context, subject signal.Subject, opts RecommendOptions) ([]RecHit, error)
- func (h *EmbeddedHub) RecordExposures(ctx context.Context, exposures []signal.Exposure) error
- func (h *EmbeddedHub) RecordSignals(ctx context.Context, signals []signal.Signal) error
- func (h *EmbeddedHub) RefreshCoEngagement(ctx context.Context, opts signal.RefreshCoEngagementOptions) error
- func (h *EmbeddedHub) RepairProjections(ctx context.Context, opts signal.RepairOptions) (signal.RepairResult, error)
- func (h *EmbeddedHub) Search(ctx context.Context, userText string, opts HubSearchOptions) (SearchResult, error)
- func (h *EmbeddedHub) SeenIDs(ctx context.Context, subject signal.Subject, contentKind string) (map[string]struct{}, error)
- func (h *EmbeddedHub) SimilarTo(ctx context.Context, ref ContentRef, opts SimilarOptions) ([]RecHit, error)
- func (h *EmbeddedHub) States(ctx context.Context, subject signal.Subject, refs []ContentRef) (map[ContentKey]signal.State, error)
- func (h *EmbeddedHub) Tenant() string
- func (h *EmbeddedHub) Typeahead(ctx context.Context, userText string, opts TypeaheadOptions) ([]TypeaheadHit, error)
- func (h *EmbeddedHub) Unseen(ctx context.Context, subject signal.Subject, opts UnseenOptions) ([]string, error)
- type EmptyReason
- type Hub
- type HubSearchOptions
- type KeywordDocument
- type LanguageMode
- type MigrateConfig
- type Personalization
- type PublishedDocument
- type RecHit
- type RecommendOptions
- type ResultTrace
- type RetrievalBackend
- type Runtime
- func (r *Runtime) DeliverPreferences(ctx context.Context, after content.PreferenceKey, pageSize, maxRows int) (content.PreferenceDelivery, error)
- func (r *Runtime) EraseSubjects(ctx context.Context, subjects []signal.Subject) (signal.ErasureReport, error)
- func (r *Runtime) Handler() http.Handler
- func (r *Runtime) ReplayPreferences(ctx context.Context, after content.PreferenceKey, pageSize, maxRows int) (content.PreferenceDelivery, error)
- func (r *Runtime) WorkerOptions(host worker.Options) worker.Options
- type RuntimeConfig
- type ScoreKind
- type SearchHit
- type SearchOptions
- type SearchResult
- type SearchTrace
- type SimilarOptions
- type SourceStatus
- type SourceTrace
- type TaxonomyID
- type TraceKey
- type TypeaheadHit
- type TypeaheadOptions
- type UnseenOptions
Constants ¶
const PreferenceEventID = "current"
PreferenceEventID is the stable signal identity of a subject's current preference on one axis: (tenant, canonical reference, subject, axis, "current"). Every delivery of a newer snapshot supersedes the previous one by revision; a replay carries the same revision and converges.
Variables ¶
var ErrSignalPlaneDisabled = errors.New("contentkit: signal plane disabled (no ClickHouse configured)")
ErrSignalPlaneDisabled is returned by signal/discovery methods when the hub was constructed without a ClickHouse connection.
Functions ¶
func Migrate ¶
func Migrate(ctx context.Context, cfg MigrateConfig) error
Migrate applies every ContentKit lineage: social in Schema, keyword in SearchSchema, optional taxonomy in SearchSchema, and the configured signal plane.
func NewEvalRunner ¶
func NewEvalRunner(client *Client, base SearchOptions) eval.CaseRunner
NewEvalRunner adapts a Client to eval.CaseRunner so a golden suite can be executed against real search. The base options carry cross-case settings (LanguageMode and filters); each case overrides Language, ContentKinds, and Limit from its own definition.
This adapter is the single seam where the client meets the dependency-free eval package.
Types ¶
type CandidateTrace ¶
type CandidateTrace struct {
Key TraceKey `json:"key"`
Rank int `json:"rank"`
Score float32 `json:"score"`
}
CandidateTrace records one source candidate at its raw source rank.
type CatalogQuery ¶
type CatalogQuery struct {
Limit int
}
CatalogQuery bounds a Universe read. Limit 0 = host-defined default.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client answers keyword search and typeahead for one tenant.
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, userText string, opts SearchOptions) (SearchResult, error)
Search returns one page of content items. Documents from every searched language are grouped per work before Offset and Limit apply; each hit carries the matched document's reference and language.
func (*Client) SearchWithTrace ¶
func (c *Client) SearchWithTrace(ctx context.Context, userText string, opts SearchOptions) (SearchResult, SearchTrace, error)
SearchWithTrace executes Search and returns opt-in retrieval provenance. On failure, the returned trace contains all work completed before the error.
func (*Client) Typeahead ¶
func (c *Client) Typeahead(ctx context.Context, userText string, opts TypeaheadOptions) ([]TypeaheadHit, error)
Typeahead returns suggestions while a user is typing (typos/substring matching), one per content item, grouped before Limit.
type ClientConfig ¶
type ClientConfig struct {
Pool *pgxpool.Pool
Schema string
// Tenant scopes every document, query and result. Required.
Tenant string
// Defaults.
DefaultLanguage string
DefaultLimit int
}
ClientConfig configures the keyword search client of one tenant.
type ContentCatalog ¶
type ContentCatalog interface {
Universe(ctx context.Context, tenant string, contentKind string, q CatalogQuery) ([]string, error)
}
ContentCatalog supplies the content "universe" for Unseen: live, non-deleted content ids of a kind, read from the host's own tables. The host owns visibility and gating (premium, region, ...) — ContentKit never interprets them. Order defines Unseen order (recommended: newest first).
type ContentCatalogFunc ¶
type ContentCatalogFunc func(ctx context.Context, tenant string, contentKind string, q CatalogQuery) ([]string, error)
ContentCatalogFunc adapts a function to the ContentCatalog interface.
func (ContentCatalogFunc) Universe ¶
func (f ContentCatalogFunc) Universe(ctx context.Context, tenant string, contentKind string, q CatalogQuery) ([]string, error)
type ContentKey ¶
type ContentKey = contentref.ContentKey
ContentKey is the comparable form of a ContentRef.
type ContentRef ¶
type ContentRef = contentref.ContentRef
ContentRef is the tenant-scoped reference to host-owned content (the work or one of its versions). See contentref.
type ContributionTrace ¶
type ContributionTrace struct {
SourceIndex int `json:"source_index"`
SourceRank int `json:"source_rank"`
Weight float32 `json:"weight"`
Contribution float32 `json:"contribution"`
}
ContributionTrace records one exact source contribution to a result score.
type DocumentKey ¶
type DocumentKey = search.DocumentKey
DocumentKey identifies one keyword document: a ContentRef in one language.
type DocumentSink ¶
type DocumentSink = search.DocumentSink
DocumentSink is the optional document port (see search.DocumentSink): the worker delivers every published keyword document to it at least once.
type Eligibility ¶
type Eligibility = search.Eligibility
Eligibility is the host's per-document eligibility join; see search.Eligibility.
type EmbeddedConfig ¶
type EmbeddedConfig struct {
// Content plane (Postgres). PG + PGSchema are required. PGSchema should
// be a dedicated schema (not the host app's schema) to avoid table
// collisions.
PG *pgxpool.Pool
PGSchema string
// Content-plane defaults (as in ClientConfig).
DefaultLanguage string
DefaultLimit int
// DefaultRRFK controls deterministic popularity/discovery fusion (default 60).
DefaultRRFK int
// Signal plane (ClickHouse). Optional: omit CH to run content-only
// (signal/discovery methods return ErrSignalPlaneDisabled). CHDatabase
// is the hub's dedicated ClickHouse database; apply
// migrations.SignalClickHouse and gate startup on signal.CheckSchema.
CH signal.Conn
CHDatabase string
// Tenant is the single tenant of this embedded hub. Required: every
// document, signal, cursor and result carries it.
Tenant string
// Scorers maps content kind → host Scorer. When a signal arrives for a
// registered kind, the scorer's result overwrites Score / Progress /
// ProgressMax / Completed before recording.
Scorers map[string]signal.Scorer
// Catalogs maps content kind → host ContentCatalog (the Unseen universe).
Catalogs map[string]ContentCatalog
}
EmbeddedConfig configures an in-process hub against the shared DB.
type EmbeddedHub ¶
type EmbeddedHub struct {
// contains filtered or unexported fields
}
EmbeddedHub implements Hub in-process. Construct with NewEmbedded.
func NewEmbedded ¶
func NewEmbedded(cfg EmbeddedConfig) (*EmbeddedHub, error)
NewEmbedded builds the embedded hub: in-process, shared DB, one tenant.
func (*EmbeddedHub) Attribution ¶
func (h *EmbeddedHub) Attribution(ctx context.Context, opts signal.AttributionOptions) (signal.AttributionPage, error)
Attribution exports renders at one stage with their clicks joined (see signal.Store.Attribution); the evaluation dataset source.
func (*EmbeddedHub) Client ¶
func (h *EmbeddedHub) Client() *Client
Client returns the underlying content-plane client (advanced use).
func (*EmbeddedHub) Content ¶
func (h *EmbeddedHub) Content(contentKind, contentID string) ContentRef
Content returns a reference to a work of this hub's tenant.
func (*EmbeddedHub) EnforceErasures ¶
func (h *EmbeddedHub) EnforceErasures(ctx context.Context) (signal.ErasureReport, error)
EnforceErasures physically removes residue of every recorded erasure of this tenant (see signal.Store.EnforceErasures): schedule it and run it after every restore.
func (*EmbeddedHub) EraseSubjects ¶
func (h *EmbeddedHub) EraseSubjects(ctx context.Context, subjects []signal.Subject) (signal.ErasureReport, error)
EraseSubjects permanently erases subjects from this tenant's signal plane: see signal.Store.EraseSubjects for the completion contract. Shared accounts exist in several tenants: each host erases its own tenant.
func (*EmbeddedHub) Forget ¶
func (h *EmbeddedHub) Forget(ctx context.Context, subject signal.Subject, contentKind, contentID string) error
Forget erases the subject's signals for one work and its versions (contentID set) or a whole content kind (contentID empty) — host "clear my history" support.
func (*EmbeddedHub) ForgetExposures ¶
ForgetExposures clears a subject's result-list exposures (search history).
func (*EmbeddedHub) History ¶
func (h *EmbeddedHub) History(ctx context.Context, subject signal.Subject, opts signal.HistoryOptions) ([]signal.StateRow, error)
func (*EmbeddedHub) HistoryCount ¶
func (h *EmbeddedHub) HistoryCount(ctx context.Context, subject signal.Subject, opts signal.HistoryOptions) (int64, error)
HistoryCount returns the total row count History would paginate over.
func (*EmbeddedHub) Inventory ¶
func (h *EmbeddedHub) Inventory(ctx context.Context) ([]signal.InventoryRow, error)
Inventory reports canonical event volume per content kind and signal type.
func (*EmbeddedHub) Metrics ¶
func (h *EmbeddedHub) Metrics(ctx context.Context, refs []ContentRef, window signal.Window) (map[ContentKey]signal.ContentMetrics, error)
Metrics returns named window metrics (viewers, views, completions, feedback, ...) for the references (works or versions).
func (*EmbeddedHub) Popular ¶
func (h *EmbeddedHub) Popular(ctx context.Context, contentKind string, opts signal.PopularOptions) ([]signal.PopularHit, error)
func (*EmbeddedHub) PopularityFor ¶
func (h *EmbeddedHub) PopularityFor(ctx context.Context, contentKind string, ids []string, window signal.Window) (map[string]float64, error)
PopularityFor scores a fixed candidate set (work ids of one kind) by the popularity ranking, returning content_id -> score. Use to rank a host- filtered universe (e.g. "galleries of artist X by popularity").
func (*EmbeddedHub) PurgeContentKinds ¶
func (h *EmbeddedHub) PurgeContentKinds(ctx context.Context, contentKinds []string) error
PurgeContentKinds irreversibly deletes whole content kinds from this tenant's signal plane (see signal.Store.PurgeContentKinds).
func (*EmbeddedHub) Recommend ¶
func (h *EmbeddedHub) Recommend(ctx context.Context, subject signal.Subject, opts RecommendOptions) ([]RecHit, error)
Recommend returns "for you" recommendations for a subject: co-engagement seeded from the subject's high-signal works ("subjects who engaged with your favorites also engaged with..."), fused across seeds (RRF), excluding already-seen, with a popularity fallback for cold start. Returns ranked references; the host hydrates.
func (*EmbeddedHub) RecordExposures ¶
RecordExposures logs one row per result list and stage (served, rendered, visible) so clicks can be attributed to what was actually exposed. Hosts call it once per list per stage, never per item.
func (*EmbeddedHub) RecordSignals ¶
RecordSignals applies each content kind's registered Scorer, then records the batch (see signal.Store.RecordSignals). A scorer error records nothing.
func (*EmbeddedHub) RefreshCoEngagement ¶
func (h *EmbeddedHub) RefreshCoEngagement(ctx context.Context, opts signal.RefreshCoEngagementOptions) error
RefreshCoEngagement (re)materializes the content_pairs co-engagement rollup for this tenant (see signal.Store.RefreshCoEngagement). Run periodically.
func (*EmbeddedHub) RepairProjections ¶
func (h *EmbeddedHub) RepairProjections(ctx context.Context, opts signal.RepairOptions) (signal.RepairResult, error)
RepairProjections is the bounded, host-scheduled projection repair (see signal.Store.RepairProjections): run it periodically with IngestedSince for crash repair, and with Rebuild over a window after projection changes.
func (*EmbeddedHub) Search ¶
func (h *EmbeddedHub) Search(ctx context.Context, userText string, opts HubSearchOptions) (SearchResult, error)
func (*EmbeddedHub) SeenIDs ¶
func (h *EmbeddedHub) SeenIDs(ctx context.Context, subject signal.Subject, contentKind string) (map[string]struct{}, error)
SeenIDs returns the subject's seen-set for one content kind (the signal-plane half of the unseen anti-join). Use when the host wants to run its own diff against a custom-filtered universe instead of Unseen's registered catalog.
func (*EmbeddedHub) SimilarTo ¶
func (h *EmbeddedHub) SimilarTo(ctx context.Context, ref ContentRef, opts SimilarOptions) ([]RecHit, error)
func (*EmbeddedHub) States ¶
func (h *EmbeddedHub) States(ctx context.Context, subject signal.Subject, refs []ContentRef) (map[ContentKey]signal.State, error)
func (*EmbeddedHub) Tenant ¶
func (h *EmbeddedHub) Tenant() string
Tenant returns the pinned tenant value.
func (*EmbeddedHub) Typeahead ¶
func (h *EmbeddedHub) Typeahead(ctx context.Context, userText string, opts TypeaheadOptions) ([]TypeaheadHit, error)
func (*EmbeddedHub) Unseen ¶
func (h *EmbeddedHub) Unseen(ctx context.Context, subject signal.Subject, opts UnseenOptions) ([]string, error)
Unseen returns catalog ids the subject has not seen (max_progress > 0 defines "seen"): host universe MINUS the subject's seen-set. The host catalog applies its own visibility/premium gating against its own tables.
type EmptyReason ¶
type EmptyReason string
EmptyReason explains a successful empty response.
const ( EmptyReasonNormalizedQuery EmptyReason = "normalized_query_empty" EmptyReasonNoCandidates EmptyReason = "no_candidates" )
type Hub ¶
type Hub interface {
// Tenant returns the tenant this hub instance is scoped to.
Tenant() string
// Content plane.
Search(ctx context.Context, userText string, opts HubSearchOptions) (SearchResult, error)
Typeahead(ctx context.Context, userText string, opts TypeaheadOptions) ([]TypeaheadHit, error)
SimilarTo(ctx context.Context, ref ContentRef, opts SimilarOptions) ([]RecHit, error)
// Signal plane.
RecordSignals(ctx context.Context, signals []signal.Signal) error
RecordExposures(ctx context.Context, exposures []signal.Exposure) error
ForgetExposures(ctx context.Context, subject signal.Subject) error
Attribution(ctx context.Context, opts signal.AttributionOptions) (signal.AttributionPage, error)
Forget(ctx context.Context, subject signal.Subject, contentKind, contentID string) error
EraseSubjects(ctx context.Context, subjects []signal.Subject) (signal.ErasureReport, error)
EnforceErasures(ctx context.Context) (signal.ErasureReport, error)
// Discovery plane.
History(ctx context.Context, subject signal.Subject, opts signal.HistoryOptions) ([]signal.StateRow, error)
HistoryCount(ctx context.Context, subject signal.Subject, opts signal.HistoryOptions) (int64, error)
SeenIDs(ctx context.Context, subject signal.Subject, contentKind string) (map[string]struct{}, error)
Unseen(ctx context.Context, subject signal.Subject, opts UnseenOptions) ([]string, error)
States(ctx context.Context, subject signal.Subject, refs []ContentRef) (map[ContentKey]signal.State, error)
Metrics(ctx context.Context, refs []ContentRef, window signal.Window) (map[ContentKey]signal.ContentMetrics, error)
Popular(ctx context.Context, contentKind string, opts signal.PopularOptions) ([]signal.PopularHit, error)
PopularityFor(ctx context.Context, contentKind string, ids []string, window signal.Window) (map[string]float64, error)
Recommend(ctx context.Context, subject signal.Subject, opts RecommendOptions) ([]RecHit, error)
// Maintenance.
RefreshCoEngagement(ctx context.Context, opts signal.RefreshCoEngagementOptions) error
RepairProjections(ctx context.Context, opts signal.RepairOptions) (signal.RepairResult, error)
Inventory(ctx context.Context) ([]signal.InventoryRow, error)
PurgeContentKinds(ctx context.Context, contentKinds []string) error
}
Hub is the single surface host apps program against: content-plane queries (search/typeahead), the signal plane (RecordSignals), and the discovery plane (reads over content × signals). All methods return ranked content references (+ per-subject State); the host hydrates them into cards from its own DB. Every method is scoped to the tenant pinned at construction; a reference of another tenant is an error.
type HubSearchOptions ¶
type HubSearchOptions struct {
SearchOptions
Personalize *Personalization
}
HubSearchOptions extends content SearchOptions with optional signal-aware personalization.
type KeywordDocument ¶
type KeywordDocument = search.KeywordDocument
KeywordDocument is the host's canonical search input for one document.
type LanguageMode ¶
type LanguageMode string
const ( // LanguageModeExact uses only the requested language. LanguageModeExact LanguageMode = "exact" // LanguageModeFallbackEnglish uses requested language first, then English. LanguageModeFallbackEnglish LanguageMode = "fallback_en" )
type MigrateConfig ¶
type MigrateConfig struct {
// DB holds DDL credentials for the host Postgres. Required.
DB *sql.DB
// Schema is the host schema: the social lineage lands here. Required.
Schema string
// SearchSchema receives the keyword lineage; "" = Schema.
SearchSchema string
// SearchApp is the keyword lineage's ledger label; "" = "contentkit".
// Existing keyword installations keep the label they were created with.
SearchApp string
// LegacySearch applies migrations.LegacyPostgres (existing installations
// created from the pre-ContentKit combined lineage; docs/migration.md).
LegacySearch bool
// Taxonomy applies the optional catalog lineage in SearchSchema after the
// keyword lineage it depends on. Its ledger app is contentkit_taxonomy.
Taxonomy bool
// ClickHouse applies the signal lineage when set; PostgresDB defaults to DB.
ClickHouse *chmigrate.Config
}
MigrateConfig names the stores contentkit.Migrate applies the lineages to.
type Personalization ¶
type Personalization struct {
Subject signal.Subject
// PopularityWeight is the RRF weight of the candidate-set popularity
// list blended with the content ranking. Defaults to 0.25.
PopularityWeight float32
// PopularityWindow bounds candidate popularity (zero = all time).
PopularityWindow signal.Window
// AffinityWeight boosts works the subject already engaged with by
// (1 + AffinityWeight·last_score/100). 0 = off.
AffinityWeight float32
// DemoteSeen demotes already-seen / completed works.
DemoteSeen bool
// SeenPenalty multiplies seen-but-not-completed scores (default 0.85).
SeenPenalty float32
// CompletedPenalty multiplies completed scores (default 0.6).
CompletedPenalty float32
// DislikePenalty multiplies works the subject has net-negative explicit
// feedback for (default 0.3). Always applied when view context is loaded
// (i.e. AffinityWeight > 0 or DemoteSeen).
DislikePenalty float32
}
Personalization fuses signal aggregates into search ranking. Recall is unchanged — this is a ranking-only layer over the candidate set. A per-request toggle the host flips (e.g. only for logged-in users).
type PublishedDocument ¶
type PublishedDocument = search.PublishedDocument
PublishedDocument is one keyword document as delivered to a DocumentSink.
type RecHit ¶
type RecHit struct {
ContentRef
Score float32
}
RecHit is one ranked work from co-engagement or recommendations.
type RecommendOptions ¶
type RecommendOptions struct {
// ContentKinds are the candidate kinds to recommend. Required.
ContentKinds []string
// Limit caps results (default: client default limit).
Limit int
// SeedLimit is how many of the subject's highest-signal works seed
// co-engagement candidates (default 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 ResultTrace ¶
type ResultTrace struct {
Key TraceKey `json:"key"`
Rank int `json:"rank"`
Score float32 `json:"score"`
ScoreKind ScoreKind `json:"score_kind"`
Contributions []ContributionTrace `json:"contributions"`
}
ResultTrace records one returned item and its best document's contributions.
type RetrievalBackend ¶
type RetrievalBackend string
RetrievalBackend identifies one candidate source.
const (
BackendKeyword RetrievalBackend = "keyword"
)
type Runtime ¶
type Runtime struct {
*EmbeddedHub
Content *content.Runtime
}
Runtime is the one surface a host wires: the Hub (search, typeahead, signals, discovery) plus the content module and its HTTP routes.
func NewRuntime ¶
func NewRuntime(ctx context.Context, cfg RuntimeConfig) (*Runtime, error)
NewRuntime builds the hub and the content module over the host pool.
func (*Runtime) DeliverPreferences ¶
func (r *Runtime) DeliverPreferences(ctx context.Context, after content.PreferenceKey, pageSize, maxRows int) (content.PreferenceDelivery, error)
DeliverPreferences runs one bounded sweep of the tenant's pending preference snapshots into the signal plane (see content.Runtime.DeliverPreferences). Schedule it from the host's worker; with the signal plane disabled it returns ErrSignalPlaneDisabled and every row stays pending.
func (*Runtime) EraseSubjects ¶
func (r *Runtime) EraseSubjects(ctx context.Context, subjects []signal.Subject) (signal.ErasureReport, error)
EraseSubjects erases every configured runtime plane: signals, preference obligations, and C4 private-source/provider data. Current approved authored content remains under host retention policy (content.EraseSubjects). ContentKit-owned reactions, favorites, poll votes, preference obligations and private submissions are removed atomically behind the source fence. EmbeddedHub.EraseSubjects is the explicit analytics-only lower-level API.
AuthKit ACK means durable acceptance by the host's deletion ledger, not this downstream completion. Retry while error != nil or !report.Complete(). A disabled signal plane is intentionally absent. Remaining may include pending plane markers content_plane or signal_plane when a plane could not complete; these are not estimates of retained provider rows.
func (*Runtime) Handler ¶
Handler returns the content routes (comments, reactions, favorites, polls, posts). Mount it under a prefix after the host's auth middleware.
func (*Runtime) ReplayPreferences ¶
func (r *Runtime) ReplayPreferences(ctx context.Context, after content.PreferenceKey, pageSize, maxRows int) (content.PreferenceDelivery, error)
ReplayPreferences replays every snapshot from after into the signal plane (acknowledged rows and zeros included): the repair for sink loss, resumable from the returned Next.
func (*Runtime) WorkerOptions ¶
WorkerOptions returns the host's keyword worker options extended with ContentKit's own documents: posts (content.KindPost) are listed and built by the content module, every other kind by the host callbacks.
type RuntimeConfig ¶
type RuntimeConfig struct {
EmbeddedConfig
Content content.Options
}
RuntimeConfig configures one tenant's full ContentKit: the search and signal planes (EmbeddedConfig) and the interaction module (Content). Pool, tenant and keyword schema are shared: Content.Pool, Content.Tenant and Content.SearchSchema are filled from the hub configuration when empty.
type ScoreKind ¶
type ScoreKind string
ScoreKind identifies the numeric domain of a candidate or result score.
const (
ScoreKeywordMatch ScoreKind = "keyword_match"
)
type SearchHit ¶
type SearchHit struct {
// ContentRef names the matched document's content: the work, or the
// version when the document was indexed per version.
ContentRef
// Language is the matched document's language.
Language string
// Score ranks the item by its best matching document in any searched
// language, using the keyword match tier.
Score float32
}
SearchHit is one content item, represented by its matched document.
type SearchOptions ¶
type SearchOptions struct {
Language string
// Defaults to LanguageModeExact when omitted.
LanguageMode LanguageMode
// ContentKinds selects the kinds searched. Required.
ContentKinds []string
// Limit is the page size in content items; Offset skips items. Documents
// are grouped per item before either applies.
Limit int
Offset int
// CandidateLimit is the document window requested from each retrieval
// source (per language) before grouping. It defaults to twice Offset+Limit
// (at least 100) and is clamped to at least Offset+Limit. Pass the same
// value on every page when a truncated window must stay identical.
CandidateLimit int
// Eligibility maps each document to the host's access, publication and
// version-trait rules on that one document. Without it every document of
// a work is eligible.
Eligibility *Eligibility
FilterSQL string
FilterArgs map[string]any
}
type SearchResult ¶
type SearchResult struct {
Hits []SearchHit
// HasMore is true when items follow this page in the grouped retrieval, or
// when Truncated: documents beyond the window were never ranked, so the
// next page may still be non-empty.
HasMore bool
// Truncated reports that a candidate window filled. Raise CandidateLimit
// for complete deep pagination.
Truncated bool
}
SearchResult is one page of items.
type SearchTrace ¶
type SearchTrace struct {
NormalizedQuery string `json:"normalized_query"`
RequestedLanguage string `json:"requested_language,omitempty"`
RequestedLanguageMode LanguageMode `json:"requested_language_mode,omitempty"`
Languages []string `json:"languages,omitempty"`
RequestedResultLimit int `json:"requested_result_limit"`
ResultLimit int `json:"result_limit"`
RequestedCandidateLimit int `json:"requested_candidate_limit"`
CandidateLimit int `json:"candidate_limit"`
Sources []SourceTrace `json:"sources,omitempty"`
Results []ResultTrace `json:"results,omitempty"`
EmptyReason EmptyReason `json:"empty_reason,omitempty"`
ErrorCategory string `json:"error_category,omitempty"`
}
SearchTrace contains opt-in effective configuration and retrieval provenance.
type SimilarOptions ¶
type SimilarOptions struct {
Limit int
// ContentKinds limits result kinds (default: any).
ContentKinds []string
// Window bounds the co-engagement scan (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 SimilarTo: "more like this" from co-engagement, subjects who engaged with the anchor also engaged with the result.
type SourceStatus ¶
type SourceStatus string
SourceStatus records whether an attempted retrieval source succeeded.
const ( SourceStatusSucceeded SourceStatus = "succeeded" SourceStatusFailed SourceStatus = "failed" )
type SourceTrace ¶
type SourceTrace struct {
Backend RetrievalBackend `json:"backend"`
Language string `json:"language"`
ScoreKind ScoreKind `json:"score_kind"`
Limit int `json:"limit"`
Status SourceStatus `json:"status"`
ErrorCategory string `json:"error_category,omitempty"`
Candidates []CandidateTrace `json:"candidates,omitempty"`
}
SourceTrace records one language-specific keyword retrieval and its candidates.
type TaxonomyID ¶
type TaxonomyID = contentref.TaxonomyID
TaxonomyID identifies a generic ContentKit catalog record (tag, artist, series, creator, character, voice actor).
type TraceKey ¶
type TraceKey struct {
ContentRef
Language string `json:"language"`
}
TraceKey identifies a document in retrieval provenance.
type TypeaheadHit ¶
type TypeaheadHit struct {
ContentRef
Language string
Score float32
}
TypeaheadHit is one suggested content item and its matched document.
type TypeaheadOptions ¶
type TypeaheadOptions struct {
Language string
// Defaults to LanguageModeExact when omitted.
LanguageMode LanguageMode
ContentKinds []string
Limit int
MinSimilarity float32
FilterSQL string
FilterArgs map[string]any
// Eligibility groups suggestions per content item; see SearchOptions.
Eligibility *Eligibility
}
type UnseenOptions ¶
type UnseenOptions struct {
// ContentKind selects which catalog universe to diff against. Required.
ContentKind string
// Limit caps the returned ids (default 50). Order follows the host
// catalog's Universe order.
Limit int
// CatalogLimit is passed through to the host catalog's Universe call
// (0 = host default).
CatalogLimit int
}
UnseenOptions controls Unseen reads.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package content is ContentKit's interaction module: posts, comments, reactions, favorites and polls over tenant-scoped content references, stored in the host schema's social_* tables.
|
Package content is ContentKit's interaction module: posts, comments, reactions, favorites and polls over tenant-scoped content references, stored in the host schema's social_* tables. |
|
Package contentref defines the reference vocabulary every ContentKit package and port shares: a tenant-scoped reference to host-owned content and the identity of a generic taxonomy record.
|
Package contentref defines the reference vocabulary every ContentKit package and port shares: a tenant-scoped reference to host-owned content and the identity of a generic taxonomy record. |
|
Package eval provides dependency-free golden-query evaluation, aggregate search-quality metrics, versioned reports, baseline comparison, and score-domain-safe threshold sweeps.
|
Package eval provides dependency-free golden-query evaluation, aggregate search-quality metrics, versioned reports, baseline comparison, and score-domain-safe threshold sweeps. |
|
internal
|
|
|
normalize
Package normalize cleans user query text before retrieval.
|
Package normalize cleans user query text before retrieval. |
|
pgtest
Package pgtest provisions disposable keyword-profile schemas on the CONTENTKIT_TEST_URL Postgres for integration tests.
|
Package pgtest provisions disposable keyword-profile schemas on the CONTENTKIT_TEST_URL Postgres for integration tests. |
|
signaltest
Package signaltest provisions disposable signal-plane ClickHouse databases for integration tests by applying the real migration lineage.
|
Package signaltest provisions disposable signal-plane ClickHouse databases for integration tests by applying the real migration lineage. |
|
Package migrations embeds ContentKit's migratekit lineages: the keyword Postgres profile, the pre-ContentKit combined Postgres lineage that converges on it, the taxonomy and social Postgres lineages, and the ClickHouse signal plane.
|
Package migrations embeds ContentKit's migratekit lineages: the keyword Postgres profile, the pre-ContentKit combined Postgres lineage that converges on it, the taxonomy and social Postgres lineages, and the ClickHouse signal plane. |
|
Package popularity ranks host content by a named, bounded policy over the signal plane's canonical window metrics (docs/popularity-policy.md).
|
Package popularity ranks host content by a named, bounded policy over the signal plane's canonical window metrics (docs/popularity-policy.md). |
|
Package search is ContentKit's keyword retrieval over content_search_documents: exact names and aliases, native-script prefixes and bounded typos for every language, with the host's eligibility join applied inside every route.
|
Package search is ContentKit's keyword retrieval over content_search_documents: exact names and aliases, native-script prefixes and bounded typos for every language, with the host's eligibility join applied inside every route. |
|
Package signal implements ContentKit's signal plane: an append-only stream of host-defined interaction signals plus a durable per-(subject, content) current-state projection, both stored in ClickHouse.
|
Package signal implements ContentKit's signal plane: an append-only stream of host-defined interaction signals plus a durable per-(subject, content) current-state projection, both stored in ClickHouse. |
|
Package taxonomy is ContentKit's generic catalog: tenant-scoped nodes (tags, artists, creators, characters, series, seasons, voice actors, ...) with localized names and aliases, typed node relationships and typed assignments of host content (a work or one of its versions) to nodes.
|
Package taxonomy is ContentKit's generic catalog: tenant-scoped nodes (tags, artists, creators, characters, series, seasons, voice actors, ...) with localized names and aliases, typed node relationships and typed assignments of host content (a work or one of its versions) to nodes. |
|
Package worker maintains one tenant's keyword documents: it drains the dirty queue, runs a bounded cursor backfill and delivers every published document to the optional DocumentSink.
|
Package worker maintains one tenant's keyword documents: it drains the dirty queue, runs a bounded cursor backfill and delivers every published document to the optional DocumentSink. |