Negative ANN delete IDs remove unrelated vectors in NumPy and Torch
Problem
The shared NumPy/Torch ANN delete implementation filters IDs above the row count, but accepts negative IDs. Array indexing interprets -1 as the last row, so deleting an invalid internal vector ID silently deletes an unrelated live vector. An ID below -row_count instead raises IndexError. This is about internal ANN row IDs; it does not claim that an Embeddings document ID of -1 is invalid.
Reproduced on current master f3ceece76a8b0f1103d736aa18f77fb10a269969 with both numpy and torch backends:
import numpy as np
from txtai.ann import ANNFactory
ann = ANNFactory.create({"backend": "numpy", "dimensions": 2})
ann.index(np.array([[1, 0], [0, 1], [0.6, 0.8]], dtype=np.float32))
ann.delete([-1])
print(ann.count()) # 2, expected 3Using torch produces the same result. On a fresh three-row index, delete([-4]) raises IndexError; delete([0, -1, 99]) deletes both row 0 and row 2 rather than only the valid row 0.
Expected behavior
Treat negative internal row IDs as out of range, consistently with the existing handling of IDs >= row_count. Valid IDs in a mixed request should still be deleted. I plan to add the missing lower bound in the shared NumPy implementation and regression coverage for NumPy and Torch, including quantized vectors and persistence.
This is distinct from #1201, which fixed scoring of rows that had already been deleted. AI assistance was used to investigate and reproduce this issue.
Source: neuml/txtai