@recoengine/diversity
v0.1.2
Published
Diversification for recoengine: MMR, attribute quotas, similarity providers and slot blending — so a correct ranking does not become ten songs by one artist.
Downloads
377
Maintainers
Readme
@recoengine/diversity
Diversification and blending for
@recoengine/core: MMR, attribute
quotas, exploration blending, and similarity providers.
npm i @recoengine/diversity @recoengine/coreAlready using
recoengine? These are re-exported from it — no separate install needed.
What it is
Ranking alone gives a correct but samey feed: twenty tracks by one artist, formally perfect and practically useless. These reorder the ranked list toward variety, and mix in exploration.
| Factory | What it does |
| --- | --- |
| mmrDiversifier | Maximal Marginal Relevance — trades relevance against similarity to already-picked items |
| attributeQuotaDiversifier | caps how many items per group (artist, brand, category…) can appear |
| bucketBlender | mixes buckets by slot quota, e.g. reserve N slots for exploration |
| cosineSimilarity / jaccardSimilarity | similarity providers MMR uses to judge "how alike are these two" |
Similarity is a separate port on purpose: how alike are two items is domain-shaped, while MMR is not — keeping them apart is what lets one MMR serve music and e-commerce.
Usage
import { createEngine } from '@recoengine/core'
import { mmrDiversifier, attributeQuotaDiversifier, cosineSimilarity } from '@recoengine/diversity'
const engine = createEngine<Track>()
.use(myProvider)
.use(myStrategies)
.use(cosineSimilarity()) // how MMR measures closeness
.use(mmrDiversifier({ lambda: 0.7 })) // 0.7 relevance / 0.3 variety
// or cap repeats by a group feature instead of / in addition to MMR:
.use(attributeQuotaDiversifier({ feature: 'artist_group', max: 2 }))
.configure({ limits: { maxCandidates: 5_000, maxLimit: 100, timeoutMs: 200 } })
.build()Options: MmrOptions, AttributeQuotaOptions, BucketBlenderOptions,
CosineSimilarityOptions, WeightedJaccardSimilarityOptions.
Links
- Repository & full docs: https://github.com/waleron07/recommendationEngine
MIT
