---
title: "Vector Search with ClickHouse - Part 1"
description: "Vector search replaces term-based inverted indexes, which use TF/IDF or BM25 scoring and can't capture meaning or handle vocabulary mismatch, with embeddings: arrays of floats where semantically similar text, images or audio sit close together under cosine or Euclidean distance."
url: "https://swe.quest/articles/vector-search-with-clickhouse-part-1-c538ccf9d6af206b"
canonical: "https://clickhouse.com/blog/vector-search-clickhouse-p1"
source: "ClickHouse"
published: "2023-05-31"
difficulty: "easy"
kind: "Deep dive"
reading_minutes: 14
tags: ["vector-search","search","machine-learning"]
---

# Vector Search with ClickHouse - Part 1

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-05-31, 14 min read, Deep dive. Original: [https://clickhouse.com/blog/vector-search-clickhouse-p1](https://clickhouse.com/blog/vector-search-clickhouse-p1)

## Summary

Vector search replaces term-based inverted indexes, which use TF/IDF or BM25 scoring and can't capture meaning or handle vocabulary mismatch, with embeddings: arrays of floats where semantically similar text, images or audio sit close together under cosine or Euclidean distance. Exact KNN linear search compares the query against every vector in O(n) and rarely scales past ~100M vectors without heavy parallelism or GPUs. Approximate nearest neighbour methods such as HNSW and Annoy give up some recall for speed. Annoy, for example, recursively partitions space into a tree and only scans the leaf nearest the query. ClickHouse stores vectors as Array(Float32) columns with distance functions, and embeddings are typically generated by transformer models such as BERT or by CNNs and ViTs for images.

Written by swe.quest, not by the author.

**Difficulty:** Easy: no special background needed; explains what something is and why it matters

## Topics

- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [Search](https://swe.quest/tags/search.md) (Backend & APIs)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)

## Keywords

ClickHouse, TF/IDF, BM25, HNSW, Annoy, BERT, pgvector, Elasticsearch

## Related posts

- [ANN Vector Search with SQL-powered LSH & Random Projections](https://swe.quest/articles/ann-vector-search-with-sql-powered-lsh-random-projections-ab84d00f3cdada4d.md): ClickHouse · 2023-12-05 · Medium · 29 min read · Vector search, Analytics & OLAP, SQL, Algorithms
  Approximate nearest neighbor search can be built in pure ClickHouse SQL using locality-sensitive hashing with random projections.
- [Vector Search with ClickHouse - Part 2](https://swe.quest/articles/vector-search-with-clickhouse-part-2-3f7737e1f27114da.md): ClickHouse · 2023-05-31 · Medium · 36 min read · Vector search, Analytics & OLAP, Databases, SQL
  ClickHouse can serve as a vector store by keeping embeddings in Array(Float32) columns and computing distance functions in SQL.
- [pgvector v0.5.0: Faster semantic search with HNSW indexes](https://swe.quest/articles/pgvector-v0-5-0-faster-semantic-search-with-hnsw-indexes-d1e5c38ac44f551e.md): Supabase · 2023-09-06 · Medium · 6 min read · Vector search, PostgreSQL, Performance engineering, Algorithms
  pgvector v0.5.0 adds HNSW indexes, which combine skip-list-style layering with navigable small world proximity graphs to do approximate nearest-neighbor search over embeddings.
- [Understanding vector search and HNSW index with pgvector](https://swe.quest/articles/understanding-vector-search-and-hnsw-index-with-pgvector-db3498f2e1e5486e.md): Neon · 2023-09-20 · Medium · 10 min read · Vector search, PostgreSQL, LLMs
  pgvector 0.5.0 adds an HNSW (Hierarchical Navigable Small Worlds) index for approximate nearest neighbor search in Postgres, replacing O(N) sequential exact scans with a multi-layer graph traversal that trades a little accuracy for much faster queries.
- [20x faster than pgvector: introducing pg\_embedding extension for vector search in Postgres and LangChain](https://swe.quest/articles/20x-faster-than-pgvector-introducing-pg-embedding-extension-for-vector-search-058737fc9388f495.md): Neon · 2023-07-11 · Medium · 7 min read · Vector search, PostgreSQL, Performance engineering
  pg\_embedding brought HNSW graph-based approximate nearest neighbor indexing to Postgres.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
