Query options

August 2, 2026 ยท View on GitHub

Glyph Query

Query options

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

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

limit

Maximum number of results returned after sort.

ValueBehavior
omittedReturn all results that pass threshold
NReturn top N hits

threshold

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

ValueDefault
omitted0 (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.

normalize

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

ValueBehavior
false (default)Raw MinHash estimate
trueBest 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.

aggregate

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.

compare

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.

Option interaction table

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

Related links ranked by Glyph.