Skip to content

refactor: remove dto dependency from ranking sub-package #57

@Anthony-Bible

Description

@Anthony-Bible

Problem

internal/application/service/ranking/ranking_utils.go imports codechunking/internal/application/dto to implement ApplyRRFRanks:

func ApplyRRFRanks(results []dto.SearchResultDTO) {
    for i := range results {
        score := CalculateRRFScore(i + 1)
        results[i].EngineScore = score
        results[i].SimilarityScore = score
    }
}

This creates an upward dependency: a utility sub-package that should be purely mathematical reaches into the application DTO layer. It makes the ranking package untestable in isolation and couples it to the DTO schema.

Suggested Fix

Move ApplyRRFRanks (or an equivalent inline loop) into the service layer (search_service.go) where dto is already imported. Keep ranking package limited to CalculateRRFScore(rank int) float64 — a pure math function with no dependencies.

// ranking/ranking_utils.go — only this remains:
func CalculateRRFScore(rank int) float64 {
    const k = 60.0
    return 1.0 / (k + float64(rank))
}
// search_service.go — caller handles application:
for i := range results {
    score := ranking.CalculateRRFScore(i + 1)
    results[i].EngineScore = score
    results[i].SimilarityScore = score
}

Files

  • internal/application/service/ranking/ranking_utils.go
  • internal/application/service/search_service.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions