xb

向量多样性与 Qdrant

本文档是 xb/doc/VECTOR_DIVERSITY_QDRANT.md 的中文版本。它解释了 xb 如何使用 Qdrant 辅助方法平衡推荐多样性。


多样性策略

策略 构建器辅助方法 描述
Hash 多样性 WithHashDiversity(func(*HashDiversity)) 将结果分散到 payload 桶中
分数下限 WithMinDistance(float32) 丢弃低于相似度阈值的项目
Payload 投影 WithPayloadSelector 控制为下游重排序器返回的字段

示例

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()

最佳实践


相关文档