mirror of
https://github.com/lukaszraczylo/claude-mnemonic.git
synced 2026-06-23 03:51:31 +00:00
refactor: extract magic numbers to named constants
reranking.DefaultAlpha (was 0.7 duplicated) and scoring.retrievalLogFactor (was inline 0.1).
This commit is contained in:
@@ -34,6 +34,10 @@ const (
|
||||
CrossEncoderAssetURL = "https://huggingface.co/cross-encoder/ms-marco-MiniLM-L6-v2/resolve/main/onnx/model.onnx"
|
||||
// CrossEncoderModelSHA256 is the expected SHA-256 of the cross-encoder model file.
|
||||
CrossEncoderModelSHA256 = "5d3e70fd0c9ff14b9b5169a51e957b7a9c74897afd0a35ce4bd318150c1d4d4a"
|
||||
|
||||
// DefaultAlpha is the default score-combining weight, favoring the
|
||||
// cross-encoder: combined = alpha*rerank + (1-alpha)*original.
|
||||
DefaultAlpha = 0.7
|
||||
)
|
||||
|
||||
// Candidate represents a search result candidate for reranking.
|
||||
@@ -79,7 +83,7 @@ type Config struct {
|
||||
// DefaultConfig returns sensible defaults for reranking.
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
Alpha: 0.7, // Favor cross-encoder by default
|
||||
Alpha: DefaultAlpha, // Favor cross-encoder by default
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +125,7 @@ func NewService(cfg Config) (*Service, error) {
|
||||
|
||||
alpha := cfg.Alpha
|
||||
if alpha <= 0 || alpha > 1 {
|
||||
alpha = 0.7
|
||||
alpha = DefaultAlpha
|
||||
}
|
||||
|
||||
return &Service{
|
||||
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"github.com/lukaszraczylo/claude-mnemonic/pkg/models"
|
||||
)
|
||||
|
||||
// retrievalLogFactor scales the diminishing-returns retrieval boost:
|
||||
// log2(retrieval_count + 1) is multiplied by this factor before applying
|
||||
// the configured retrieval weight.
|
||||
const retrievalLogFactor = 0.1
|
||||
|
||||
// Calculator computes importance scores for observations.
|
||||
type Calculator struct {
|
||||
config *models.ScoringConfig
|
||||
@@ -72,7 +77,7 @@ func (c *Calculator) CalculateComponents(obs *models.Observation, now time.Time)
|
||||
retrievalContrib := 0.0
|
||||
if obs.RetrievalCount > 0 {
|
||||
// log2(count + 1) gives diminishing returns: 1→1, 3→2, 7→3, 15→4, etc.
|
||||
retrievalBoost := math.Log2(float64(obs.RetrievalCount)+1) * 0.1
|
||||
retrievalBoost := math.Log2(float64(obs.RetrievalCount)+1) * retrievalLogFactor
|
||||
retrievalContrib = retrievalBoost * c.config.RetrievalWeight
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user