MCPcopy
hub / github.com/langroid/langroid / delete_collection

Method delete_collection

langroid/vector_store/postgres.py:228–247  ·  view source on GitHub ↗

Deletes a collection and its associated HNSW index, handling metadata synchronization issues.

(self, collection_name: str)

Source from the content-addressed store, hash-verified

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:

Callers 4

_setup_tableMethod · 0.95
clear_all_collectionsMethod · 0.95
vecdbFunction · 0.95

Calls 3

_quote_identFunction · 0.85
connectMethod · 0.80
clearMethod · 0.45

Tested by 1

vecdbFunction · 0.76