mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
Store IVFSparse deletes as int (#1241)
This commit is contained in:
@@ -116,10 +116,11 @@ class IVFSparse(ANN):
|
||||
|
||||
def delete(self, ids):
|
||||
# Set index ids as deleted, ignoring ids that were never indexed and ids already marked deleted
|
||||
# Ids are stored as int, the deletes list is serialized with msgpack
|
||||
size = self.size()
|
||||
for x in ids:
|
||||
if x < size and x not in self.deletes:
|
||||
self.deletes.append(x)
|
||||
self.deletes.append(int(x))
|
||||
|
||||
def search(self, queries, limit):
|
||||
results = []
|
||||
|
||||
@@ -8,6 +8,8 @@ import unittest
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import numpy as np
|
||||
|
||||
from scipy.sparse import random
|
||||
from sklearn.preprocessing import normalize
|
||||
|
||||
@@ -100,6 +102,31 @@ class TestSparse(unittest.TestCase):
|
||||
self.assertLessEqual(len(ann.blocks), 15)
|
||||
ann.close()
|
||||
|
||||
def testIVFSparseDeleteArray(self):
|
||||
"""
|
||||
Test IVFSparse with ids deleted using a NumPy array
|
||||
"""
|
||||
|
||||
# Generate test record
|
||||
data = self.generate(50, 30522)
|
||||
|
||||
# Create ANN
|
||||
path = os.path.join(tempfile.gettempdir(), "ivfsparse.deletes")
|
||||
ann = SparseANNFactory.create({"backend": "ivfsparse"})
|
||||
ann.index(data)
|
||||
|
||||
# Test delete with ids passed in as a NumPy array
|
||||
ann.delete(np.array([0, 1]))
|
||||
self.assertEqual(ann.count(), 48)
|
||||
|
||||
# Validate save/load
|
||||
ann.save(path)
|
||||
ann.load(path)
|
||||
self.assertEqual(ann.count(), 48)
|
||||
|
||||
# Close ANN
|
||||
ann.close()
|
||||
|
||||
def testIVFSparseSortOrder(self):
|
||||
"""
|
||||
Test IVFSparse returns results sorted by score descending
|
||||
|
||||
Reference in New Issue
Block a user