Skip to content

Commit

Permalink
EES-4727 Rename get_collection to ensure_collection_exists and inspec…
Browse files Browse the repository at this point in the history
…t client error for 404
  • Loading branch information
benoutram committed Dec 7, 2023
1 parent 314f0b4 commit 0ebfd80
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions data_ingestion/services/vector_db_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@


def upsert_data(records: list[dict[str, str]], batch_size: int = 100) -> None:
# Make sure the collection exists
get_collection()
ensure_collection_exists()

chunks = list(chain.from_iterable(map(create_url_text_map, records)))

Expand Down Expand Up @@ -59,12 +58,15 @@ def recreate_collection() -> bool:
)


def get_collection() -> None:
def ensure_collection_exists() -> None:
try:
client.get_collection(collection_name=settings.qdrant_collection)
except UnexpectedResponse:
logger.debug("Collection doesn't exist - recreating collection")
recreate_collection()
except UnexpectedResponse as e:
if e.status_code == 404:
logger.debug("Collection doesn't exist - recreating collection")
recreate_collection()
else:
raise


def delete_url(url: str) -> None:
Expand Down

0 comments on commit 0ebfd80

Please sign in to comment.