MCPcopy
hub / github.com/langroid/langroid / clear_empty_collections

Method clear_empty_collections

langroid/vector_store/postgres.py:268–287  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

266 return deleted_count
267
268 def clear_empty_collections(self) -> int:
269 inspector = inspect(self.engine)
270 table_names = inspector.get_table_names()
271
272 with self.SessionLocal() as session:
273 deleted_count = 0
274 for table_name in table_names:
275 table = Table(table_name, self.metadata, autoload_with=self.engine)
276
277 # Efficiently check for emptiness without fetching all rows
278 if session.query(table.select().limit(1).exists()).scalar():
279 continue
280
281 # Use delete_collection to handle index and table deletion
282 self.delete_collection(table_name)
283 deleted_count += 1
284
285 session.commit() # Commit is likely not needed here
286 logger.warning(f"Deleted {deleted_count} empty tables.")
287 return deleted_count
288
289 def _parse_embedding_store_record(self, res: Any) -> Dict[str, Any]:
290 metadata = res.cmetadata or {}

Callers

nothing calls this directly

Calls 3

delete_collectionMethod · 0.95
get_table_namesMethod · 0.80
selectMethod · 0.80

Tested by

no test coverage detected