Skip to content

PGVectorStore broken against real Postgres (dimension, register_vector, commit, opclass, JSONB) — hidden by MagicMock #830

Closed

Description

@AmitoVrito

Summary

PGVectorStore (src/synapsekit/retrieval/pgvector.py) has never run against a real Postgres — its only test uses MagicMock, which hid multiple breakages. Found while converting to real testcontainers tests (epic #829).

Bugs (all hidden by the mock)

  1. self._embeddings.dimension doesn't exist — no real embeddings backend exposes .dimension (base SynapsekitEmbeddings has none; HashingEmbeddings has .dimensions). Raises AttributeError on first connect.
  2. No register_vector — pgvector.psycopg is imported but register_vector_async(conn) is never called, so Python vectors aren't adapted to the vector type on insert/query.
  3. No commit / not autocommit — AsyncConnection.connect(...) defaults to a transaction that is never committed, so inserts would roll back and never be visible.
  4. Wrong index operator classes — uses cosine_ops / l2_ops / inner_product_ops; pgvector's real opclasses are vector_cosine_ops / vector_l2_ops / vector_ip_ops. CREATE INDEX fails.
  5. JSONB handling — inserts json.dumps(...) text into a jsonb column without a cast, and on read calls json.loads() on what psycopg already returns as a dict.

Fix (per decision on #829)

  • Derive dim from the first embedding vector; create table/index on first add() (no .dimension dependency). search() before any add() returns []; detect a pre-existing table for reconnect/persistence.
  • connect(..., autocommit=True) + register_vector_async(conn) after CREATE EXTENSION.
  • Correct opclass names.
  • Use psycopg Jsonb(...) for metadata; tolerate dict-or-str on read.

Test

Real pgvector/pgvector:pg16 testcontainer: round-trip add/search with true nearest-neighbor ranking, metadata filter, top_k, persistence across reconnect, dimension/empty/negative cases. 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