Skip to content

Query options

Control ranking, filtering, and compare behavior for Search().

interface GlyphQueryOptions {
limit?: number;
threshold?: number;
normalize?: boolean;
aggregate?: GroupResultAggregator;
compare?: GlyphComparisonOptions;
}

Maximum number of results returned after sort.

Value Behavior
omitted Return all results that pass threshold
N Return top N hits

Minimum raw similarity (before normalize) to include a result.

Value Default
omitted 0 (include all non-negative scores)

Use a higher threshold to drop weak matches. Short queries against long documents often produce low absolute scores; threshold: 0 with normalize: true is common for ranking demos.

After sort (and limit), divide each similarity by the top score.

Value Behavior
false (default) Raw MinHash estimate
true Best hit → 1.0; others scaled proportionally

Skipped when:

  • No results remain, or
  • Top score is 0

comparison.similarity inside each result is updated to match.

GroupResultAggregator used when an index entry (or the probe) is a GlyphGroup. Default: GroupResultAggregatorMax (max pairwise similarity).

import { index, query } from "@koda.oss/glyph";
const idx = index.New();
query.New(idx).Search(probe, {
aggregate: ({ scores }) =>
scores.reduce((a, b) => a + b, 0) / scores.length,
});

See Groups.

Extra options forwarded to Compare() for each entry.

query.New(idx).Search(probe, {
compare: {
aggregate: GroupResultAggregatorMax,
},
});

If both aggregate and compare.aggregate are set, the top-level aggregate wins.

Order Step
1 Compare each entry (apply aggregate / compare)
2 Filter by threshold
3 Sort descending
4 Apply limit
5 Apply normalize (if true)

Related links ranked by Glyph.