diff --git a/sqlite-vec.c b/sqlite-vec.c index 53c4635..d12e25d 100644 --- a/sqlite-vec.c +++ b/sqlite-vec.c @@ -3074,6 +3074,9 @@ int vec0_parse_vector_column(const char *source, int source_length, if (rc != SQLITE_OK) { return SQLITE_ERROR; } + if (ivfConfig.quantizer == VEC0_IVF_QUANTIZER_BINARY && (dimensions % 8) != 0) { + return SQLITE_ERROR; + } #else return SQLITE_ERROR; // IVF not compiled in #endif diff --git a/tests/test-ivf-quantization.py b/tests/test-ivf-quantization.py index 9790680..b4d6ae3 100644 --- a/tests/test-ivf-quantization.py +++ b/tests/test-ivf-quantization.py @@ -253,3 +253,20 @@ def test_ivf_quantized_delete(db): db.execute("DELETE FROM t WHERE rowid = 5") # _ivf_vectors should have 9 rows assert db.execute("SELECT count(*) FROM t_ivf_vectors00").fetchone()[0] == 9 + + +def test_ivf_binary_rejects_non_multiple_of_8_dims(db): + """Binary quantizer requires dimensions divisible by 8.""" + with pytest.raises(sqlite3.OperationalError): + db.execute( + "CREATE VIRTUAL TABLE t USING vec0(" + " v float[12] indexed by ivf(quantizer=binary)" + ")" + ) + + # Dimensions divisible by 8 should work + db.execute( + "CREATE VIRTUAL TABLE t2 USING vec0(" + " v float[16] indexed by ivf(quantizer=binary)" + ")" + )