Skip to content

Real testcontainers tests for pgvector + redis (fixes 7 mock-hidden bugs) — #829 - #832

Merged
AmitoVrito merged 5 commits into
mainfrom
feat/issue-829-testcontainers-postgres-redis
Jul 21, 2026
Merged

AmitoVrito merged 5 commits into
mainfrom
feat/issue-829-testcontainers-postgres-redis

Conversation

@AmitoVrito

Copy link
Copy Markdown
Collaborator

Summary

First increment of epic #829 (real testcontainers tests for every external backend, replacing MagicMock). Converts the two P0 vector stores — pgvector and redis — to real container-backed tests. Deep testing immediately surfaced 7 real bugs neither backend's mock could catch, plus a test-isolation bug.

Bugs found & fixed (all hidden by MagicMock)

PGVectorStore (#830) — had never worked against a real Postgres:

  • read a nonexistent embeddings.dimension
  • never called register_vector (vectors wouldn't adapt)
  • never committed writes (autocommit off)
  • wrong index opclasses (cosine_ops vs vector_cosine_ops)
  • JSONB insert/read mishandled

RedisVectorStore (#831):

  • UnicodeDecodeError on every search (decoded raw FLOAT32 embedding bytes)
  • returned [] after reconnect (short-circuited on missing cached dim)

Test isolation — test_redis_memory.py installed a sys.modules["redis"] MagicMock at import and never restored it, poisoning later real-redis tests.

Verification (real containers, not mocks)

  • pgvector/pgvector:pg16 — 7/7 pass: true nearest-neighbour ranking, metadata filter, top_k, persistence across reconnect, empty/negative cases.
  • redis/redis-stack — 7/7 pass: same coverage against real RediSearch.
  • Full suite: 4760 passed, 69 skipped locally (all containers booted).
  • Wired into the CI integration job.

Commits (separated by concern)

  • fix(retrieval): make PGVectorStore work against real Postgres (#830)
  • fix(retrieval): make RedisVectorStore work against real RediSearch (#831)
  • test(memory): restore real redis module after mock test teardown
  • ci(test): add pgvector/redis to the integration group and CI job (#829)

Tracked under #829; remaining backends (Elasticsearch, Mongo, Qdrant, …) follow in subsequent PRs.

AmitoVrito and others added 5 commits July 21, 2026 20:05
PGVectorStore had never run against a real database — only a MagicMock — which
hid five breakages: it read a nonexistent embeddings.dimension, never called
register_vector, never committed writes, used invalid index operator classes,
and mishandled JSONB.

Derive the embedding dimension from the first vector (works with any embeddings
backend), create the table/index on first add(), register the pgvector adapters,
use autocommit and correct vector_*_ops HNSW opclasses, and round-trip JSONB via
psycopg Jsonb. search() before any add() returns []; a pre-existing table is
detected for reconnect/persistence.

Adds real pgvector/pgvector testcontainers tests (true nearest-neighbour ranking,
metadata filter, top_k, persistence, negatives) under the CI integration job.

Part of #829. Closes #830.

Co-authored-by: Dhruv Garg <[email protected]>
)

Only ever tested with a MagicMock, which hid two bugs: every real search raised
UnicodeDecodeError (FT.SEARCH returned the raw FLOAT32 embedding bytes, which the
parser then tried to UTF-8 decode), and a reconnected instance returned [] because
search() short-circuited on a missing cached dimension.

Scope FT.SEARCH with `RETURN 3 text metadata score`, and drop the `_dim is None`
guard — `_search_sync` now returns [] only on a genuine missing-index ResponseError,
which also covers search-before-add. Reconnected instances now find persisted vectors.

Adds real redis/redis-stack testcontainers tests and removes the obsolete
MagicMock RedisVectorStore test.

Part of #829. Closes #831.
test_redis_memory.py installs a MagicMock at sys.modules["redis"] on import and
never restored it, so once collected it poisoned every later `import redis` in the
session — breaking real-backend tests like test_redis_vector_integration.py. Add a
teardown_module that drops the mock entries so the real redis is re-imported.

Part of #829.
Add psycopg[binary], pgvector, and redis to the `integration` dependency-group
and run the new pgvector/redis testcontainers tests in the integration CI job.

Part of #829.
@AmitoVrito
AmitoVrito merged commit 10b408f into main Jul 21, 2026
6 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.

1 participant