Skip to content

formation-res/querylight-ts

Repository files navigation

Querylight TS

npm version build status

Pure TypeScript port of the Kotlin querylight library, packaged for browsers and Node.js.

Querylight TS is an in-process search toolkit for static sites, browser apps, and Node.js projects that need more than fuzzy matching but do not want a separate search server. It is positioned as the most feature-rich local search library in this category: BM25 and TF-IDF ranking, structured queries, aggregations, highlighting, geo search, dense vector search, sparse vector search, and hybrid reranking behind one API.

The vector story is a first-class part of the library:

  • dense vector search with VectorFieldIndex for semantic retrieval, ANN lookup, related-content features, and vector rescoring
  • sparse vector search with SparseVectorFieldIndex for learned token-weight retrieval in the style of OpenSearch neural sparse search
  • hybrid search patterns that combine lexical retrieval with dense or sparse vector ranking

That makes it practical to ship lexical, dense, sparse, and hybrid search locally in one package instead of stitching together multiple narrower tools.

Project links:

Use Cases

Querylight TS can cover a wide range of local search problems without forcing you into a backend search stack.

Use Case Description Features
Text search Find the right page, document, or product from normal keyword queries. TF-IDF and BM25 Ranking, Term, Terms, Prefix, Exists, and Match Queries, BoolQuery for Must, Should, Filter, MustNot, and MinimumShouldMatch, Highlighting with Querylight TS
Search as you type Show useful matches while somebody is still typing. SimpleTextSearch for Plain JSON Documents, Trie-Backed Prefix Expansion, How To Build Autocomplete
Did you mean Recover from typos, partial words, and slightly wrong queries. SimpleTextSearch for Plain JSON Documents, Approximate Nearest Neighbor Vector Search, Reciprocal Rank Fusion
Related documents Show similar articles, products, help pages, or records. Approximate Nearest Neighbor Vector Search, Document Chunking Strategies, Vector Rescoring for Faster Hybrid Search
Ask the docs Answer natural-language questions by retrieving the most relevant chunks first. Approximate Nearest Neighbor Vector Search, Document Chunking Strategies, Vector Rescoring for Faster Hybrid Search, Ask the Docs End to End
Sparse neural search Run learned token-weight retrieval when your model emits sparse vectors instead of dense embeddings. Sparse Vector Search, Reciprocal Rank Fusion, Ask the Docs End to End
Faceting Let users narrow results by tags, sections, categories, ranges, or counts. Terms Aggregation, Significant Terms Aggregation, Range Aggregation, Histogram Aggregation, Date Histogram Aggregation, How To Build Faceted Navigation
Filtered search Combine full-text queries with hard constraints such as section, product type, date, or status. BoolQuery for Must, Should, Filter, MustNot, and MinimumShouldMatch, NumericFieldIndex and DateFieldIndex for Structured Features, RangeQuery Over Lexical Fields
Dashboards Slice and explore local data with counts, buckets, and ranked result lists. Using Querylight TS as a Local Analytics Engine, From Raw API Payloads to Browser Dashboards, Build Interactive ECharts Dashboards from Plain JSON, Terms Aggregation, Stats Aggregation
Hybrid search Blend lexical ranking with dense or sparse vectors instead of picking one retrieval model. Reciprocal Rank Fusion, Vector Rescoring for Faster Hybrid Search, Sparse Vector Search, Approximate Nearest Neighbor Vector Search
Geo-aware search Find results inside a point radius, map area, or polygon. Geo Indexing with Points and Polygons, BoolQuery for Must, Should, Filter, MustNot, and MinimumShouldMatch
Static-site search shipped to the browser Build indexes ahead of time and ship them with your site or app. Portable JSON Index State, Serialization, Hydration, and Shipping Indexes, Getting Started with Browser Search

Try The Demo

Open the live documentation portal and demo on Cloudflare Pages:

It is both the main documentation site and the live product demo. Use it to read the docs, inspect the indexed content, and compare lexical, dense vector, sparse vector, and hybrid retrieval in the browser.

Workspace Layout

  • packages/querylight: the library package (@tryformation/querylight-ts)
  • apps/demo: a Hugo-based static demo site with generated docs content and bundled client-side enhancements

Features

  • In-memory reverse index for structured documents
  • TF-IDF and BM25 ranking
  • Reciprocal rank fusion for combining lexical, geo, filter, and vector results
  • Dense vector retrieval with VectorFieldIndex
  • Sparse vector retrieval with SparseVectorFieldIndex
  • Hybrid retrieval with vector rescoring and rank fusion
  • Boolean, term, terms, wildcard, regex, exists, range, phrase, prefix, multi-match, dis-max, boosting, and match-all queries
  • Numeric/date field indexes plus distance-feature, rank-feature, and JS script scoring queries
  • Beginner-friendly plain JSON indexing with simpleTextSearch
  • Offset-based exact, phrase, prefix, and fuzzy highlighting
  • Analyzer/tokenizer/token-filter pipeline
  • Trie-backed prefix expansion
  • Aggregations and significant terms
  • Approximate nearest-neighbour dense vector search
  • Basic geo point/polygon queries
  • Portable JSON-serializable index state

Dense And Sparse Vector Search

Querylight TS supports two different vector retrieval models.

  • Dense vectors use VectorFieldIndex. This is the right fit for embeddings, semantic similarity, related-content features, ANN lookup, and lexical-first reranking with VectorRescoreQuery.
  • Sparse vectors use SparseVectorFieldIndex. This is the right fit when your model produces token-weight maps and you want a retrieval path closer to an inverted index.
  • Hybrid search works with both. You can fuse lexical and vector result sets with reciprocalRankFusion(...), or retrieve lexically first and rescore a smaller candidate window with vectors.

Start here if vector search is the reason you are evaluating the library:

Documentation

Browse the canonical documentation source in docs/ or open the published documentation portal and live demo at https://querylight.tryformation.com/.

Install

Install the published package in another project with:

npm install @tryformation/querylight-ts

For local development in this repository:

npm install

Beginner Path

If you want a reasonable default without composing your own queries, use createSimpleTextSearchIndex and simpleTextSearch:

import { createSimpleTextSearchIndex, simpleTextSearch } from "@tryformation/querylight-ts";

const search = createSimpleTextSearchIndex({
  documents: [
    {
      id: "intro",
      title: "Querylight TS",
      description: "Portable browser and Node.js search",
      body: "A compact search toolkit with BM25, phrase search, and fuzzy recovery."
    }
  ],
  primaryFields: ["title"],
  secondaryFields: ["description", "body"]
});

const hits = simpleTextSearch(search, { query: "portble sear", limit: 5 });

If you need highlight fragments, run highlighting as a second step on the returned ids:

import { MatchQuery } from "@tryformation/querylight-ts";

const query = new MatchQuery("title", "range filters");
const hits = search.documentIndex.searchRequest({ query, limit: 5 });
const highlight = search.documentIndex.highlight(hits[0]![0], query, {
  fields: ["title", "body"]
});

Commands

npm install
npm test
npm run build
npm run dev

Positioning

This is intended as a broader client-side search toolkit than fuzzy-match-only libraries such as fuse.js: it combines ranking, boolean logic, multi-field search, phrase search, prefixes, aggregations, dense vector search, sparse vector search, and geo support behind one small pure TypeScript API. For a fuller comparison with fuse.js, Lunr, MiniSearch, FlexSearch, Pagefind, and Orama, see the comparison article.

Project Notes

Parts of this project were developed with AI-assisted agentic coding tools, with design, review, and release decisions still made manually.

Most of the documentation was also AI-generated. That makes broad docs coverage easier to maintain, and it provides a large enough corpus for the demo application to showcase lexical, dense-vector, sparse-vector, and hybrid search modes.

About

Search library for static websites. Bm25, faceting, Sparse & dense vector search, reciprocal rank fusion for hybrid search. Perfect for small sites and blogs.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors