Deletes a collection and its associated HNSW index, handling metadata synchronization issues.
(self, collection_name: str)
| 226 | self.set_collection(collection_name, replace=replace) |
| 227 | |
| 228 | def delete_collection(self, collection_name: str) -> None: |
| 229 | """ |
| 230 | Deletes a collection and its associated HNSW index, handling metadata |
| 231 | synchronization issues. |
| 232 | """ |
| 233 | with self.engine.connect() as connection: |
| 234 | connection.execute(text("COMMIT")) |
| 235 | index_name = f"hnsw_index_{collection_name}_embedding" |
| 236 | drop_index_query = text( |
| 237 | f"DROP INDEX CONCURRENTLY IF EXISTS {_quote_ident(index_name)}" |
| 238 | ) |
| 239 | connection.execute(drop_index_query) |
| 240 | |
| 241 | # 3. Now, drop the table using SQLAlchemy |
| 242 | table = Table(collection_name, self.metadata) |
| 243 | table.drop(self.engine, checkfirst=True) |
| 244 | |
| 245 | # 4. Refresh metadata again after dropping the table |
| 246 | self.metadata.clear() |
| 247 | self.metadata.reflect(bind=self.engine) |
| 248 | |
| 249 | def clear_all_collections(self, really: bool = False, prefix: str = "") -> int: |
| 250 | if not really: |