Documentation
¶
Overview ¶
Package result 提供检索结果的融合、去重、压缩与重排能力。
本包基于 Hit 容器结构(持有 Chunks/Nodes/Edges 三类集合)实现:
- RRF:按 Chunks/Nodes/Edges 三类分别 Reciprocal Rank Fusion,返回融合后的 *Hit
- Dedup:对 hit.Chunks 做语义去重(MinHash + Jaccard 相似度)
- Compress:对 hit.Chunks 调用 LLM 压缩 Content
- Rerank:用查询向量与 hit.Chunks 的 Content 向量做余弦相似度重排
Index ¶
- func Compress(limit int, llm goChatCore.Client, hit *core.Hit) (*core.Hit, error)
- func Dedup(hit *core.Hit) (*core.Hit, error)
- func RRF(sources ...*FusionSource) (*core.Hit, error)
- func RRFWithK(k int, sources ...*FusionSource) (*core.Hit, error)
- func Rerank(q core.Query, embedder core.Embedder, hit *core.Hit) (*core.Hit, error)
- type FusionSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compress ¶
Compress 先按分数排序取 top N,再对每条 ChunkHit 的 Content 调用 LLM 压缩。
入参 hit 不会被修改,返回新的 *Hit(Chunks 已压缩,Nodes/Edges 保持不变)。 压缩后的 ChunkHit 会创建新的 Chunk 副本(不共享原 Chunk 指针),避免副作用。
func Dedup ¶
Dedup 对检索结果中的 Chunks 做语义去重。
使用 MinHash 算法估算文本 Jaccard 相似度,对同 DocID 下相似度超过阈值的 ChunkHit 进行合并:同 DocID 下,内容相似度 >= threshold 的保留分数最高的,丢弃其余。
仅对 hit.Chunks 做去重,hit.Nodes 和 hit.Edges 保持不变。 返回新的 *Hit(不修改入参 hit),其 Chunks 已去重并按分数降序排序。
func RRF ¶
func RRF(sources ...*FusionSource) (*core.Hit, error)
RRF 使用默认平滑参数 k=60 执行 Reciprocal Rank Fusion。
融合规则:
- 按 Chunks/Nodes/Edges 三类分别 RRF 融合
- 同类内按 ID 去重,相同 ID 的分数累加
- 每类内部按融合后分数降序排序
- Hit.Score = topChunkScore + topNodeScore + topEdgeScore(缺失类别贡献 0)
参数:
- sources: 多个 FusionSource 输入(Hit 为 nil 的源会被跳过)
返回:
- *core.Hit: 融合后的检索结果容器
- error: 仅当 sources 为空或全部为 nil 时返回 (nil, nil)
func RRFWithK ¶
func RRFWithK(k int, sources ...*FusionSource) (*core.Hit, error)
RRFWithK 使用自定义平滑参数 k 执行 RRF 融合。 推荐 k 范围:5-100,k 越大对低排名结果越宽容。
RRF 公式:score(doc) = Σ weight_s / (k + rank_s)
Types ¶
Click to show internal directories.
Click to hide internal directories.