Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """Script to clean up ChromaDB collections and cache.""" | |
| import shutil | |
| import os | |
| from pathlib import Path | |
| def cleanup_chroma_db(): | |
| """Clean up ChromaDB collections and cache.""" | |
| print("=" * 60) | |
| print("ChromaDB Cleanup Utility") | |
| print("=" * 60) | |
| # First, forcefully delete the chroma_db directory | |
| chroma_path = Path("./chroma_db") | |
| if chroma_path.exists(): | |
| print(f"\nποΈ Removing chroma_db directory: {chroma_path}") | |
| try: | |
| shutil.rmtree(chroma_path) | |
| print(f"β Deleted directory: {chroma_path}") | |
| except Exception as e: | |
| print(f"β Error deleting directory: {e}") | |
| else: | |
| print(f"\nβ chroma_db directory not found: {chroma_path}") | |
| # Also check for ChromaDB in .chroma directory (alternative location) | |
| chroma_alt_path = Path("./.chroma") | |
| if chroma_alt_path.exists(): | |
| print(f"\nποΈ Removing .chroma directory: {chroma_alt_path}") | |
| try: | |
| shutil.rmtree(chroma_alt_path) | |
| print(f"β Deleted directory: {chroma_alt_path}") | |
| except Exception as e: | |
| print(f"β Error deleting directory: {e}") | |
| # Clear HuggingFace dataset cache (optional) | |
| response = input("\nποΈ Clear HuggingFace dataset cache? (y/n): ").lower() | |
| if response == 'y': | |
| cache_path = Path.home() / ".cache" / "huggingface" / "datasets" | |
| if cache_path.exists(): | |
| print(f"ποΈ Removing HF cache: {cache_path}") | |
| try: | |
| shutil.rmtree(cache_path) | |
| print(f"β Deleted HF cache: {cache_path}") | |
| except Exception as e: | |
| print(f"β Error deleting HF cache: {e}") | |
| else: | |
| print("βΉοΈ HuggingFace cache not found") | |
| # Clear ChromaDB chroma cache directory | |
| response = input("\nποΈ Clear ChromaDB chroma cache? (y/n): ").lower() | |
| if response == 'y': | |
| chroma_cache = Path.home() / ".chroma" | |
| if chroma_cache.exists(): | |
| print(f"ποΈ Removing ChromaDB cache: {chroma_cache}") | |
| try: | |
| shutil.rmtree(chroma_cache) | |
| print(f"β Deleted ChromaDB cache: {chroma_cache}") | |
| except Exception as e: | |
| print(f"β Error deleting ChromaDB cache: {e}") | |
| # Try to use ChromaDBManager if possible | |
| print("\nπ Attempting to connect to ChromaDB...") | |
| try: | |
| from vector_store import ChromaDBManager | |
| manager = ChromaDBManager(persist_directory="./chroma_db") | |
| # List existing collections | |
| collections = manager.list_collections() | |
| print(f"π Found {len(collections)} collection(s):") | |
| for col in collections: | |
| print(f" - {col}") | |
| # Clear all collections | |
| if collections: | |
| print("\nποΈ Clearing all collections...") | |
| deleted = manager.clear_all_collections() | |
| print(f"β Deleted {deleted} collection(s)") | |
| else: | |
| print("\nβ No collections to delete") | |
| except Exception as e: | |
| print(f"β οΈ Could not connect to ChromaDB via manager: {e}") | |
| print("βΉοΈ This is OK - the directory has been deleted already.") | |
| print("\n" + "=" * 60) | |
| print("β Cleanup completed! You can now start fresh.") | |
| print("=" * 60) | |
| if __name__ == "__main__": | |
| cleanup_chroma_db() | |