Skip to main content

Module score

Module score 

Source
Expand description

2l: hybrid scoring – the kernel primitive SGQL’s ScoreExpr lowers onto.

A newcomer’s map. Retrieval FINDS candidates (any family: a text search, a vector walk, a spatial radius, a graph traversal). Scoring RANKS them: an arithmetic expression over per-candidate atoms – BM25 relevance, vector similarity, geodesic distance – evaluated in one pass. The structural rule (the contract’s): scoring never re-runs retrieval. Candidates arrive as ids; every atom is a point evaluation against rows those ids name; cost is candidates x atoms, resident state is one f32 column per distinct atom, freed at return.

Atom semantics (documented, not configurable):

  • Bm25: Okapi BM25 (K1=1.2, B=0.75), same math as text_search; a candidate without the term(s) scores 0.0.
  • Bm25Norm: s/(s+k) saturation of the Bm25 score, bounded [0,1] so it blends with cosine on equal footing (e1’s BM25_NORM).
  • VecSim: HIGHER IS BETTER for every metric – cosine and dot as-is, L2/L1 negated. A candidate without a vector IN THAT FIELD scores 0.0.
  • StDistanceM: PostGIS-geography metres (Vincenty). A candidate without geometry is INFINITELY far (it sorts last under any positive distance weighting) – unknown location never ranks near.
  • Extern(i): the caller’s per-candidate column (payload-derived values computed above the kernel; the payload stays opaque here).
  • Division by zero yields 0.0 – a poisoned NaN would make the final ordering depend on sort internals instead of the expression.

Enums§

ScoreExpr
The expression tree. Leaves are atoms or constants; interior nodes are arithmetic. Built once per query, evaluated per candidate.