---
title: "Vector Search with ClickHouse - Part 2"
description: "ClickHouse can serve as a vector store by keeping embeddings in Array(Float32) columns and computing distance functions in SQL."
url: "https://swe.quest/articles/vector-search-with-clickhouse-part-2-3f7737e1f27114da"
canonical: "https://clickhouse.com/blog/vector-search-clickhouse-p2"
source: "ClickHouse"
published: "2023-05-31"
difficulty: "medium"
kind: "How-to"
reading_minutes: 36
tags: ["vector-search","analytics","databases","sql"]
---

# Vector Search with ClickHouse - Part 2

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-05-31, 36 min read, How-to. Original: [https://clickhouse.com/blog/vector-search-clickhouse-p2](https://clickhouse.com/blog/vector-search-clickhouse-p2)

## Summary

ClickHouse can serve as a vector store by keeping embeddings in Array(Float32) columns and computing distance functions in SQL. The walkthrough uses the 2.2-billion-row English LAION dataset of CLIP ViT-L/14 image and caption embeddings, covering schema design, loading from S3 Parquet, compression, and exact linear-scan search combined with metadata filtering and aggregation. It also covers the experimental Annoy ANN index, UDFs for generating query vectors, and codec tuning. ClickHouse fits best when vector matching needs SQL filtering, joins or aggregation over datasets too large for memory. Dedicated vector databases or in-memory indexes suit small, very high-QPS workloads better.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- vector embeddings ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- ClickHouse MergeTree tables ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, LAION, CLIP, Annoy, Parquet, Hugging Face, OpenCLIP

## Related posts

- [Vector Search with ClickHouse - Part 1](https://swe.quest/articles/vector-search-with-clickhouse-part-1-c538ccf9d6af206b.md): ClickHouse · 2023-05-31 · Easy · 14 min read · Vector search, Search, Machine learning
  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.
- [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.
- [We built a vector search engine that lets you choose precision at query time](https://swe.quest/articles/we-built-a-vector-search-engine-that-lets-you-choose-precision-at-query-time-dd6e891f552187e7.md): ClickHouse · 2025-10-28 · Hard · 20 min read · Vector search, Analytics & OLAP, Storage engines, Performance engineering
  QBit is a new ClickHouse column type that stores BFloat16, Float32 or Float64 vectors as transposed bit planes, each held in a FixedString subcolumn.
- [SQLite Retrieval Augmented Generation and Vector Search](https://swe.quest/articles/sqlite-retrieval-augmented-generation-and-vector-search-f6665825b9a1cb47.md): Turso · 2024-06-21 · Medium · 5 min read · Vector search, SQLite, RAG & retrieval
  Retrieval-augmented generation fixes stale or hallucinated LLM answers by retrieving relevant data, typically via embeddings and vector similarity search, and injecting it into the prompt. libSQL adds native vector search to SQLite: embeddings are stored in an F32\_BLOB column (SQLite treats column types as hints), inserted with a vector() function, and queried with vector\_distance\_cos() plus ORDER BY/LIMIT for exact top-k results.
- [ClickHouse Release 25.5](https://swe.quest/articles/clickhouse-release-25-5-1e2d09f989621f0d.md): ClickHouse · 2025-06-02 · Medium · 9 min read · Analytics & OLAP, Vector search, Databases
  ClickHouse 25.5 ships 15 new features, 23 performance optimizations and 64 bug fixes.

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)
