ID mapping support: The base index must be wrapped with IDMap or IDMap2 to enable ID-based operations
Valid ID format: IDs must be provided as a numpy array of integers
Existing IDs: Only IDs that exist in the index can be removed; attempting to remove non-existent IDs may result in warnings or errors
Implementation Example
import faiss
import numpy as np
# Create base index and wrap with IDMap
dimension = 128
base_index = faiss.IndexFlatL2(dimension)
index = faiss.IndexIDMap(base_index)
# Add vectors with specific IDs
vectors = np.random.random((100, dimension)).astype('float32')
ids = np.arange(100)
index.add_with_ids(vectors, ids)
# Remove specific vectors by their IDs
ids_to_remove = np.array([5, 10, 15, 20])
index.remove_ids(ids_to_remove)
print(f"Vectors remaining: {index.ntotal}")