Skip to content

fix(clickhouse): apply ef at search time and select only ids - #913

Merged
jamesgao-jpg merged 2 commits into
zilliztech:mainfrom
serhiizghama:fix/clickhouse-search-ef
Nov 26, 2026
Merged

jamesgao-jpg merged 2 commits into
zilliztech:mainfrom
serhiizghama:fix/clickhouse-search-ef

Conversation

@serhiizghama

Copy link
Copy Markdown
Contributor

The Clickhouse client never used ef. --ef-runtime ends up in ClickhouseHNSWConfig.ef and in search_param(), but search_embedding didn't pass it anywhere, so every run searched with the server default.

Passing it alone wasn't enough, though. The search query also selected the embedding column, which the client throws away (only row[0] is used). With the vector column in the select list, recall stayed flat no matter what hnsw_candidate_list_size_for_search was set to. Selecting only id gives the normal HNSW behaviour, and it also stops shipping k full vectors back on every query.

So the search now selects only ids and sends ef as hnsw_candidate_list_size_for_search when it's set. When ef is None nothing is sent and the server default (256) applies as before. While at it, I folded the four copies of the query (cosine/L2 x filter/no filter) into one.

Checked against a local ClickHouse 26.10 in docker, going through the client itself (30k random 64d vectors, L2, M=8, efConstruction=16, recall@10 on 50 queries):

ef main this branch
16 0.990 0.194
64 0.990 0.426
256 0.990 0.714
1024 0.990 0.890

On 20k normalized 768d vectors with cosine and k=100, a query went from about 25 ms to about 7 ms locally. Worth knowing: Clickhouse recall from earlier runs may come out higher than what this branch gives at the same settings, because the old query wasn't really bounded by the HNSW candidate list.

Added tests/test_clickhouse_client.py (offline, stubs clickhouse_connect the same way the SeekDB tests stub mysql.connector) and hooked it into make unittest. Not sure the Makefile line is where you want new tests to go, happy to move it.

@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: serhiizghama
To complete the pull request process, please assign xuanyang-cn after the PR has been reviewed.
You can assign the PR to them by writing /assign @xuanyang-cn in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jamesgao-jpg

Copy link
Copy Markdown
Collaborator

reveiwed and found no immediate actionable items :) Thanks for the contribution!

@jamesgao-jpg
jamesgao-jpg merged commit d2b7eb2 into zilliztech:main Nov 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants