Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:666ghj BettaFish Diversity Sampling

From Leeroopedia
Knowledge Sources
Domains Machine_Learning, Information_Retrieval, NLP
Last Updated 2026-10-08 00:00 GMT

Overview

Technique that uses semantic clustering to select diverse, representative items from a large set of search results, ensuring coverage of all topical sub-themes rather than only the most frequent ones.

Description

Diversity Sampling addresses the problem of redundant search results: when a database search returns hundreds of results, many will be near-duplicates or cover the same sub-topic. Simply taking the top-N by popularity leads to topical bias. By clustering results semantically (using sentence embeddings) and sampling from each cluster, the system ensures that all distinct sub-topics are represented in the final set.

This approach combines semantic similarity (SentenceTransformer embeddings) with importance ranking (hotness score within each cluster), producing a set that is both diverse and high-quality.

Usage

Use this principle when processing large result sets (>50 items) before passing them to an LLM for summarization. It prevents context window overflow while ensuring the LLM sees representative coverage of all sub-topics.

Theoretical Basis

The diversity sampling process:

E=Encode(R);C=KMeans(E,k) S=⋃i=1kTopm(Ci,hotness)

Where:

  • R = raw results, E = embeddings, C = clusters
  • k=max⁡(2,⌊nmax/m⌋) clusters
  • Topm selects the top-m items by hotness from each cluster

Pseudo-code Logic:

# Abstract pattern (NOT real implementation)
embeddings = sentence_transformer.encode(texts)
clusters = kmeans.fit_predict(embeddings, k=n_clusters)
sampled = []
for cluster in clusters:
    top_by_hotness = sorted(cluster, key=hotness, reverse=True)[:m]
    sampled.extend(top_by_hotness)
return sampled[:max_results]

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment