File size: 1,769 Bytes
7649e72 96fe8d8 7649e72 96fe8d8 7649e72 96fe8d8 27cbb3d 7649e72 96fe8d8 7649e72 96fe8d8 7649e72 96fe8d8 7649e72 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import asyncio
from src.database import engine
from sqlalchemy import text
from src.config import get_settings
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PayloadSchemaType
async def main():
async with engine.begin() as conn:
print('Wiping Postgres data natively...')
await conn.execute(text('DROP SCHEMA public CASCADE'))
await conn.execute(text('CREATE SCHEMA public'))
print('Postgres schema wiped.')
import qdrant_client
settings = get_settings()
try:
q = QdrantClient(url=settings.qdrant_url, api_key=settings.qdrant_api_key)
q.delete_collection(settings.collection_name)
q.create_collection(
collection_name=settings.collection_name,
vectors_config=VectorParams(size=settings.vector_size, distance=Distance.COSINE)
)
# Reinject indices required natively by the pipeline
q.create_payload_index(
collection_name=settings.collection_name,
field_name="session_id",
field_schema=PayloadSchemaType.KEYWORD
)
q.create_payload_index(
collection_name=settings.collection_name,
field_name="years_of_experience",
field_schema=PayloadSchemaType.FLOAT
)
print('Qdrant collection wiped and re-indexed.')
except Exception as e:
print('Qdrant error:', e)
print("\n------------------------------")
print("Database is completely purged but empty.")
print("WARNING: You MUST now run the following command to rebuild the tables:")
print(" alembic upgrade head")
print("------------------------------")
if __name__ == '__main__':
asyncio.run(main())
|