Delete
Usedelete_items(...) to delete records by external ID.
return_not_found=False, the second returned value is None.
Deletes are logical until the index is compacted. Deleted records are filtered out during search, but their storage is reclaimed during compact rebuild.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
external_ids | list[str] | required | List of external IDs to delete |
return_not_found | bool | False | Whether to return IDs that were not found in the index |
Return Value
The method returns a tuple of(deleted_count, not_found):
- deleted_count — The number of items that were successfully deleted
- not_found — A list of IDs that were not found in the index (only populated if
return_not_found=True)
Checking for Not-Found IDs
By default,return_not_found=False for better performance. If you need to know which IDs were not found (perhaps to clean up your source data), set it to True:
After Deletion
After deleting items, the HNSW graph still references the deleted nodes, but they are marked as removed and will not appear in search results. This lazy deletion approach is fast but can reduce search efficiency over time.Checking if Rebuild is Needed
Useneeds_rebuild() to check if the index would benefit from a compact rebuild after deletions:
Optimizing the Graph
For a lighter-weight alternative to a full rebuild, you can optimize the graph in place:optimize_graph() checks whether the index needs rebuilding. If the update or delete ratio crosses the delta_ratio threshold, Brinicle rebuilds the graph. Otherwise, it does nothing.
For unconditional compaction, use rebuild_compact().
Deleting All Data
To completely remove an index and all its data, use thedestroy() method: