Skip to content

The SparseGrams function

YouTube Video: K5LzKT4geq8

Mark Needham

Learn about ClickHouse's sparse grams function and how it improves upon traditional n-grams to build better search solutions. This tutorial walks through the concept step-by-step, explaining how sparse grams work by using weighted substrings to filter out common patterns that would otherwise return too many search results. We'll explore the algorithm with practical examples and show you how to use it in ClickHouse.

What You'll Learn:

  • The limitations of traditional n-grams for search indexing at scale
  • How GitHub's sparse grams algorithm solves the "too many results" problem
  • Step-by-step walkthrough of the sparse grams weighting system
  • How to use ClickHouse's sparseGrams() function with practical examples
  • Understanding the crc32 hash function for weight calculations
  • Comparing n-grams vs sparse grams output side-by-side

➡️ SparseGrams docs

Recent videos

YouTube Video: e-NnqMTY_3A

How to

Inspect incoming data with INSERT … RETURNING in ClickHouse

Use INSERT … RETURNING in ClickHouse 26.11 to inspect generated values, sample incoming rows, find invalid ratings, and summarise an ingestion batch.

YouTube Video: BsmTK-pa5ks

How to

Reading and writing Vortex files with ClickHouse (26.11)

Query and export Vortex files with ClickHouse 26.11, using a FineWeb dataset containing just over a million web pages.

Follow us

XBlueskySlackGithubTelegramMeetupRSS