chatbot / app /fix_collection.py
Tahasaif3's picture
Create fix_collection.py
c231ecc verified
import asyncio
from app.services.vector_store import vector_store
from app.services.document_ingestion import initialize_knowledge_base_async
async def fix_collection():
print("=" * 60)
print("πŸ”§ FIXING QDRANT COLLECTION DIMENSIONS")
print("=" * 60)
try:
# Step 1: Delete the old collection
print("\n1️⃣ Deleting old collection (1536 dimensions)...")
vector_store.delete_collection()
print(" βœ“ Old collection deleted")
except Exception as e:
print(f" β„Ή Collection delete: {e}")
try:
# Step 2: Create new collection
print("\n2️⃣ Creating new collection (768 dimensions for Gemini)...")
vector_store.create_collection(force_recreate=True)
print(" βœ“ New collection created")
except Exception as e:
print(f" βœ— Error creating collection: {e}")
return
try:
# Step 3: Re-ingest all documents
print("\n3️⃣ Re-ingesting documents with Gemini embeddings...")
print(" (This may take a few minutes...)")
doc_ids = await initialize_knowledge_base_async()
print(f" βœ“ Successfully ingested {len(doc_ids)} documents")
except Exception as e:
print(f" βœ— Error ingesting documents: {e}")
import traceback
traceback.print_exc()
return
print("\n" + "=" * 60)
print("βœ… MIGRATION COMPLETE!")
print("=" * 60)
print(f"βœ“ Collection: book_documents (768 dimensions)")
print(f"βœ“ Documents: {len(doc_ids)} chunks")
print(f"βœ“ Embedding model: Gemini text-embedding-004")
print(f"βœ“ LLM model: Gemini 2.0 Flash")
print("\nYou can now start your application! πŸš€")
print("=" * 60)
if __name__ == "__main__":
asyncio.run(fix_collection())