#1281·txtai

SQLite binary ANN search returns zero or negative scores for similar vectors

Author: LimbC-CCreated Sep 28, 2026Updated Sep 28, 2026

SQLite ANN binary quantization returns 1 - distance, but sqlite-vec's BIT distance is a count of differing bits, not cosine distance. As a result, all non-identical binary vectors score zero or below and are removed by Embeddings' score > 0 filter.

Reproduced on current master (97ee7e0), Windows, sqlite-vec 0.1.9:

python
import numpy as np
from txtai.ann import ANNFactory

ann = ANNFactory.create({'backend': 'sqlite', 'dimensions': 8,
                         'sqlite': {'quantize': 1}})
vectors = np.ones((3, 8), dtype=np.float32)
vectors[1, 0] = -1
vectors[2, :4] = -1
ann.index(vectors)
print(ann.search(vectors[:1], 3))
ann.close()

Actual: [(0, 1.0), (1, 0.0), (2, -3.0)]. Expected normalized Hamming similarity: [(0, 1.0), (1, 0.875), (2, 0.5)].

I plan to normalize binary distances by the configured bit-vector dimensions, consistent with the other binary ANN backends and the intent of #838, while leaving FLOAT32/INT8 cosine scores unchanged. I found no existing SQLite-specific fix. This is separate from #1249 (save/copy) and #1234 (disabled quantization). Investigation and proposed implementation are AI-assisted.