Skip to content

馃敶 [ARCH] SearchMatch.similarity is a Frankenstein - needs separated scores聽#10

Closed

Description

@FullFran

Problem

SearchMatch.similarity currently represents THREE different things:

  • text search: ts_rank (PostgreSQL relevance)
  • semantic search: cosine similarity

This is a contract lie that breaks:

  • Debugging (why did a chunk win?)
  • Threshold tuning (can't set per-channel thresholds)
  • Reranking pipelines
  • Evaluation metrics

Current Anti-Pattern

# In RRF - MUTATING the original object
match.similarity = scores[cid]  # Overwrites original score!

Solution: Separated Scores Model

Create a new SearchHit model with explicit scores:

class SearchHit(BaseModel):
    chunk: Chunk
    document_title: str
    document_source: str
    
    # Explicit scores - None if not computed
    semantic_score: float | None = None
    text_score: float | None = None
    fusion_score: float | None = None
    
    @property
    def best_score(self) -> float:
        return self.fusion_score or self.semantic_score or self.text_score or 0.0

Files to Change

  • src/core/schemas/search.py - New SearchHit model
  • src/infrastructure/database/supabase_repository.py - Return proper scores
  • src/services/rag_service.py - Don't mutate, create new objects

Acceptance Criteria

  • SearchMatch replaced with SearchHit
  • RRF creates new objects instead of mutating
  • Each score type is traceable

Activity

  1. FullFran commented on Jan 26, 2026

    @FullFran
    OwnerAuthor

    Resuelto. tiene , y en , y crea nuevos hits en RRF sin mutar scores originales. Cierro la issue.

  2. FullFran commented on Jan 26, 2026

    @FullFran
    OwnerAuthor

    Corrijo comentario anterior (el backtick se interpret贸 en shell).

    Resuelto. SearchHit tiene semantic_score, text_score y fusion_score en src/core/schemas/search.py, y src/services/rag_service.py crea nuevos hits en RRF sin mutar scores originales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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