sqlrank

package
v1.163.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package sqlrank ranks a candidate set of rows in one PostgreSQL statement (#2500): every row whose stored full-text column matches the query, and every row whose blended semantic score reaches opranking.ScoreFloor, scored the way every hybrid ranker on the platform scores and paged with a count of all results.

The candidates are a statement the caller builds, which is how a caller's own filter (an owner, a producer, a person's reach) decides what can be ranked: a row is ranked exactly when that statement would return it. They are materialized and scored by exact distance, because an HNSW scan filters after its nearest-neighbor step and a narrow candidate set would keep few or none of the rows it returned.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRanked

func BuildRanked(r Ranking) (query string, args []any)

BuildRanked renders a ranked statement over the candidates. Every candidate whose text matches is a result, and so is one whose blended semantic score reaches opranking.ScoreFloor: where the embedding model stops telling related text from unrelated. The candidates are materialized and scored by exact distance, because an HNSW scan filters after its nearest-neighbor step and a narrow reach would keep few or none of the rows it returned. Rows come back as (id, score, total).

Types

type Ranked

type Ranked struct {
	IDs    []string
	Scores map[string]float64
	Total  int
}

Ranked is one ranked page: ids in rank order, each one's score, and how many results there are in all.

func Rank

func Rank(ctx context.Context, db *sql.DB, r Ranking) (Ranked, error)

Rank runs a ranked statement.

type Ranking

type Ranking struct {
	// Candidates is a statement selecting id, name, embedding and the stored
	// full-text column named FTS, and its arguments ($-numbered).
	Candidates string
	Args       []any
	FTS        string
	QueryText  string
	Embedding  []float32 // nil ranks lexically
	Limit      int
	Offset     int
}

Ranking is what a ranked statement scores a candidate set by.

Jump to

Keyboard shortcuts

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