Repository navigation
fix(clickhouse): apply ef at search time and select only ids - #913
Merged
jamesgao-jpg merged 2 commits intoNov 26, 2026
Merged
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: serhiizghama The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Collaborator
|
reveiwed and found no immediate actionable items :) Thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Clickhouse client never used
ef.--ef-runtimeends up inClickhouseHNSWConfig.efand insearch_param(), butsearch_embeddingdidn'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
embeddingcolumn, which the client throws away (onlyrow[0]is used). With the vector column in the select list, recall stayed flat no matter whathnsw_candidate_list_size_for_searchwas set to. Selecting onlyidgives 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
efashnsw_candidate_list_size_for_searchwhen it's set. Whenefis 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):
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, stubsclickhouse_connectthe same way the SeekDB tests stubmysql.connector) and hooked it intomake unittest. Not sure the Makefile line is where you want new tests to go, happy to move it.