Skip to content

ClickHouseVectorStore: top_k SQL-interpolation + no reconnect persistence — hidden by MagicMock #844

Closed

Description

@AmitoVrito

Summary

ClickHouseVectorStore (src/synapsekit/retrieval/clickhouse_vector.py), previously only MagicMock-tested, had two bugs found via a real clickhouse-server testcontainer (epic #829). (It correctly offloads via run_in_executor — async is fine.)

Bugs

  1. top_k interpolated into the SQL LIMIT — f"... LIMIT {top_k}" with no validation. A non-int top_k is injected verbatim (ClickHouse rejects multi-statements, but the store shouldn't rely on that). Now cast to a positive int, so a payload like "5; DROP TABLE ..." raises ValueError before hitting the DB.
  2. No reconnect persistence — search() returned [] when not self._table_created, so a reconnected instance never found existing rows. Now _search_sync checks EXISTS TABLE and returns [] only when the table genuinely doesn't exist.

Test

Real clickhouse-server testcontainer: true nearest-neighbour ranking (L2Distance), metadata filter, top_k, reconnect persistence, top_k-injection rejection, empty/negative, async contract. Replaces the MagicMock test; runs in the CI integration job.

Part of epic #829.

Activity

  1. added this to the v2.0.1 milestone on Jul 21, 2026
  2. added
    bug
    retrieval
    v2.0.1
    on Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugretrievalv2.0.1

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions