ranking

package
v1.36.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WeightSymbol = 5.0 // symbol name matches are most important
	WeightPath   = 3.0 // file path matches are moderately important
	WeightDoc    = 2.0 // doc-comment matches (more verbose, less specific than symbol names)
)

Field weight constants for BM25F scoring.

Variables

This section is empty.

Functions

func FusionRank deprecated

func FusionRank(signals []Signal) map[string]float64

FusionRank combines ranking signals into a single score per file. Each signal is min-max normalized to [0,1] before weighted combination.

Deprecated: prefer rerank.WeightedRRF (rank-based fusion) over min-max + weighted sum. Min-max is outlier-sensitive and not scale-invariant across corpora — see plan 2026-04-29-go-code-retrieval-quality-lift.md §Stream 3. Kept as the default ANALYZE_RANK_FUSION_MODE=minmax path until the offline harness validates rrf with no per-repo regression >2%; remove next sprint after the default flip.

func Louvain

func Louvain(graph map[string][]string) map[string]int

Louvain performs community detection on an undirected graph using the Louvain modularity optimization algorithm. Input is an adjacency list (same format as PageRank). Returns a map from node to community ID (0-indexed). Returns nil for empty input. Uses multi-level graph contraction for better cluster separation.

func LouvainWeighted

func LouvainWeighted(graph map[string]map[string]int) map[string]int

LouvainWeighted performs community detection on a weighted undirected graph. Input: node → neighbor → edge weight. Uses γ = 1.0.

func LouvainWithResolution

func LouvainWithResolution(graph map[string][]string, gamma float64) map[string]int

LouvainWithResolution performs community detection with a resolution parameter γ. γ > 1.0 produces more (smaller) communities; γ < 1.0 produces fewer (larger) communities. γ = 1.0 is standard modularity (equivalent to Louvain()).

func PageRank

func PageRank(graph map[string][]string, iterations int, damping float64) map[string]float64

PageRank computes PageRank scores for nodes in a directed graph. graph maps each node to the list of nodes it links TO (outgoing edges). iterations controls convergence (20 is typical), damping is usually 0.85. Returns normalized scores (sum ≈ 1.0).

func PersonalizedPageRank

func PersonalizedPageRank(
	graph map[string][]string,
	seeds map[string]float64,
	iterations int,
	damping float64,
) map[string]float64

PersonalizedPageRank computes PageRank with a personalization vector. Seeds maps node names to personalization weights (higher = more bias). When seeds is nil, falls back to uniform (standard PageRank).

func WeightedPersonalizedPageRank

func WeightedPersonalizedPageRank(
	graph map[string]map[string]float64,
	seeds map[string]float64,
	iterations int,
	damping float64,
) map[string]float64

WeightedPersonalizedPageRank computes PageRank with personalization on a weighted directed graph. graph maps src→dst→weight. Seeds bias the personalization vector; iterations/damping control convergence.

Types

type BM25F

type BM25F struct {
	// contains filtered or unexported fields
}

BM25F implements field-weighted BM25 scoring.

func NewBM25F

func NewBM25F(docs []Document) *BM25F

NewBM25F creates a BM25F scorer from a corpus of documents.

func (*BM25F) Score

func (b *BM25F) Score(term string, doc Document) float64

Score computes the BM25F score for a single query term against a document.

func (*BM25F) ScoreTerms

func (b *BM25F) ScoreTerms(terms []string, doc Document) float64

ScoreTerms computes total BM25F score for multiple query terms.

type Document

type Document struct {
	Path    string   // relative file path
	Symbols []string // symbol names in the file
	Docs    []string // doc-comments / leading comments per symbol
}

Document represents a file for BM25F scoring. Only Path, Symbols, and Docs are used — file content is scored via LLM, not BM25F.

type RefGraph

type RefGraph struct {
	// contains filtered or unexported fields
}

RefGraph is a weighted directed graph of file-to-file reference edges.

func BuildRefGraph

func BuildRefGraph(input RefGraphInput) *RefGraph

BuildRefGraph constructs a file-level reference graph by resolving call sites to target symbol files and merging with import edges.

func (*RefGraph) Adjacency

func (g *RefGraph) Adjacency() map[string]map[string]float64

Adjacency returns the internal weighted adjacency map.

func (*RefGraph) Len

func (g *RefGraph) Len() int

Len returns total directed edge count.

func (*RefGraph) ToUnweighted

func (g *RefGraph) ToUnweighted() map[string][]string

ToUnweighted converts to the format used by PageRank.

func (*RefGraph) Weight

func (g *RefGraph) Weight(src, dst string) float64

Weight returns edge weight from src to dst (0 if no edge).

type RefGraphInput

type RefGraphInput struct {
	Symbols     []*parser.Symbol
	Calls       []parser.CallSite
	ImportEdges map[string][]string // file→[]file from import resolution
}

RefGraphInput provides data for building the file-level reference graph.

type Signal

type Signal struct {
	Name   string
	Weight float64
	Scores map[string]float64
}

Signal represents a single ranking signal with weight and per-file scores.

Jump to

Keyboard shortcuts

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