xb

Vector Diversity & Qdrant (English)

English remake of xb/doc/VECTOR_DIVERSITY_QDRANT.md. It explains how xb balances recommendation diversity using Qdrant helpers.


Diversity strategies

Strategy Builder helper Description
Hash diversity WithHashDiversity(func(*HashDiversity)) Spreads results across payload buckets
Score floor WithMinDistance(float32) Drops items below a similarity threshold
Payload projection WithPayloadSelector Controls fields returned for downstream rerankers

Example

custom := xb.NewQdrantBuilder().
    WithHashDiversity(func(h *xb.HashDiversity) {
        h.Field = "category"
        h.Modulo = 4
    }).
    WithMinDistance(0.35).
    Build()

json, _ := xb.Of(&ProductVector{}).
    Custom(custom).
    VectorSearch("embedding", vec, 12).
    Build().
    JsonOfSelect()

Best practices