result

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package result provides result fusion and re-ranking capabilities for multi-source search results. It implements Reciprocal Rank Fusion (RRF) for combining results from different indexers and cosine similarity-based re-ranking for improving result quality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(limit int, llm goChatCore.Client, hits []core.Hit) ([]core.Hit, error)

Compress 先按分数排序取 top N,再对每条 Content 调用 LLM 压缩。

func Dedup

func Dedup(hits []core.Hit) ([]core.Hit, error)

Dedup 对搜索结果语义去重 使用 MinHash 算法估算文本 Jaccard 相似度,对同 DocID 下相似度超过阈值的 chunk 进行合并 合并规则:同 DocID 下,内容相似度 >= threshold 的保留分数最高的,丢弃其余

func RRF

func RRF(sources ...FusionSource) ([]core.Hit, error)

RRF performs Reciprocal Rank Fusion on multiple sources using default k=60.

The RRF formula: score(doc) = Σ weight_s / (k + rank_s)

Parameters:

  • sources: variable number of FusionSource inputs

Returns:

  • []core.Hit: fused results sorted by score in descending order
  • error: non-nil only if sources is empty (returns nil, nil)

func RRFWithK

func RRFWithK(k int, sources ...FusionSource) ([]core.Hit, error)

RRFWithK performs RRF fusion with a custom smoothing parameter k. Recommended k range: 5-100. Larger values are more tolerant of lower-ranked results.

func Rerank

func Rerank(query *query.SemanticQuery, hits []core.Hit) ([]core.Hit, error)

Rerank re-ranks search results using cosine similarity between query vector and content vectors.

In RAG systems, Re-Ranking refers to re-scoring initial retrieval results using a more precise method rather than simply ordering by initial retrieval scores.

This implementation uses the pre-computed query vector from SemanticQuery.Vector() and computes cosine similarity with each hit's content vector (encoded on-the-fly). Results are returned in descending order of cosine similarity score.

Types

type FusionSource

type FusionSource struct {
	Name   string     // 源标识(如 "vector"、"keyword"、"graph")
	Hits   []core.Hit // 该源的搜索结果,顺序 = 排名
	Weight float32    // 源权重,0 表示 1.0
}

FusionSource represents search results from a single source (e.g., vector, keyword, graph indexer). The Hits field maintains the internal ranking order from that source.

func NewSource

func NewSource(name string, weight float32, hits []core.Hit) *FusionSource

NewSource creates a new FusionSource with the given name, weight, and hits.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL