Query

August 2, 2026 ยท View on GitHub

Glyph Query

Query

Wrap an index with query.New(idx), then rank entries with Search().

Query is a first-class module that wraps a GlyphIndexInstance. The index owns storage and CandidateKeys; query owns probe โ†’ ranked results.

Signature

query.New(index: GlyphIndexInstance): GlyphQueryInstance

instance.Search(
  probe: Glyph | GlyphSignature | GlyphGroupInput,
  options?: GlyphQueryOptions,
): GlyphQueryResult[]

Example

import { Create, index, query } from "@koda.oss/glyph";

const idx = index.New();
idx.Set("moon", Create("Goodbye moon").glyph);
idx.Set("sun", Create("Goodbye sun").glyph);
idx.Set("pasta", Create("unrelated pasta recipe").glyph);

const results = query.New(idx).Search(Create("Goodbye moon").glyph, {
  limit: 5,
  threshold: 0.1,
  normalize: true,
});

Flow

q = query.New(index)
for each key in index.CandidateKeys(probe):
  value = index.Get(key)
  comparison = Compare(probe, value, compareOptions)
  if comparison.similarity < threshold: skip
  collect { key, similarity, comparison }

sort by similarity descending
apply limit (if set)
if normalize: divide each similarity by top score
return results

Compare routing

Index valueCompare path
Single glyphCompareGlyphs
Map group (or array input, normalized)CompareGroups (default aggregate: max)

Pass aggregate or compare in options. See Query options.

Performance

By default the index uses LSH banding (mode: "bands"). Search scores CandidateKeys from band collisions, not every key. Use index.New({ mode: "direct" }) for an exact full scan. See Index.

Related links ranked by Glyph.