class

DataDungeon::MatchIndex

Inherits DataDungeon::Matcher < Reference < Object

Best matches for registered types: the assets whose traits come closest to what was asked, even when none matches every pick, ranked by

score = Σ weight × similarity, over the traits asked for

where a word trait is alike only when equal, a scale's values are alike by how near they sit on it, colors by how alike they look (CIE76 ΔE in Lab), and sets by the members they share. See DESIGN-best-match.md.

Each asset gets a controlled vector built from its tags (no model, no API calls): one block per trait, so its inner product with a query's vector approximates the score. USearch finds the nearest candidates in one file per type, beside the database, and they are then scored exactly from their traits. Weights travel with the query, so changing them rebuilds nothing; changing a type's traits, scales or colors rebuilds its file from the tags.

One process owns a store's match files (a lock). Before each query it catches up on every process's writes from the database's change log; a checkpoint beside each file means a restart replays only what changed.

Constants

ANCHOR_LABS = ANCHORS.map do |rgb| MatchIndex.lab(rgb) end
ANCHOR_SIGMA = 35.0
ANCHORS = [0, 16777215, 8421504, 16711680, 16753920, 16776960, 32768, 65535, 255, 8388736, 16761035, 9127187]

Colors that place the others by appearance: a color's block holds how close it is to each.

COLOR_SIGMA = 25.0
ENCODING = 3
FALLBACK_DIMS = 8
SHORTLIST = 200
WORD_DIMS = 16
YIELD_EVERY = 256

Constructors

new(db : DB, dir : String | Nil = nil)

Owns the match files in dir (by default beside the database).

Source

Class methods

closeness(delta_e : Float64, sigma : Float64) : Float64

1 for the same color, falling off with distance: about 0.6 at sigma.

Source
color(value : String) : Int32 | Nil

A color value's RGB: a CSS name (with or without dashes) or a hex code (stored values lose the #).

Source

CIE Lab* (D65) of an sRGB color.

Source
named(name : String) : Tuple(Float64, Float64, Float64)

The middle of a named direction's sector (Direction#name).

Source
vector(value : String) : Tuple(Float64, Float64, Float64)

A field value x,y,z as its vector.

Source

Instance methods

best_matches(asset_type : String, picks : Hash(String, String), *, require required_traits : Array(String) = [] of String, weights : Hash(String, Float64) = {} of String => Float64, limit : Int32 = 10) : Array(BestMatch)

The assets of a registered type closest to picks (trait => value), best first, with their scores; flagged ones are left out, and equal scores go to the highest rating, then the newest. Traits in require must equal their picks. weights give this query's emphasis; others come from the registration, else 1.

Source
close

Saves every file and releases the lock.

Source
similar(id : Int64, *, require required_traits : Array(String) = [] of String, weights : Hash(String, Float64) = {} of String => Float64, limit : Int32 = 10) : Array(BestMatch)

The assets closest to this one, by its own traits.

Source

Nested types