Repository navigation
Real testcontainers tests for pgvector + redis (fixes 7 mock-hidden bugs) — #829 - #832
Merged
Merged
Conversation
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.
Co-authored-by: Dhruv Garg <[email protected]>
Closed
18 of 19 tasks
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.
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:
embeddings.dimensionregister_vector(vectors wouldn't adapt)cosine_opsvsvector_cosine_ops)RedisVectorStore (#831):
UnicodeDecodeErroron every search (decoded raw FLOAT32 embedding bytes)[]after reconnect (short-circuited on missing cached dim)Test isolation —
test_redis_memory.pyinstalled asys.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.integrationjob.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 teardownci(test): add pgvector/redis to the integration group and CI job (#829)Tracked under #829; remaining backends (Elasticsearch, Mongo, Qdrant, …) follow in subsequent PRs.