@@ -39,10 +39,14 @@ def populate_vector_db() -> None:
3939 collection_name = doc_store ._collection_name
4040
4141 # Clear existing collection if any
42- if doc_store .count_documents () > 0 :
42+ if ( doc_count := doc_store .count_documents () ) > 0 :
4343 try :
4444 # Don't delete collection since it's referenced by existing pipelines upon their startup
45- logger .info ("Clearing out existing vector DB collection=%r" , collection_name )
45+ logger .info (
46+ "Clearing out existing vector DB collection=%r with %d docs" ,
47+ collection_name ,
48+ doc_count ,
49+ )
4650 # recreate_index=True results in a new id for the collection, which breaks existing pipelines
4751 doc_store .delete_all_documents (recreate_index = False )
4852 except DocumentStoreError as e :
@@ -65,7 +69,6 @@ def populate_vector_db() -> None:
6569 pipeline = _create_ingest_pipeline (doc_store )
6670 pipeline .run ({"converter" : {"sources" : files_to_ingest }})
6771 logger .info ("Ingested documents doc_count=%d" , doc_store .count_documents ())
68-
6972 logger .info ("ChromaDB collections: %s" , chroma_client .list_collections ())
7073
7174
@@ -78,16 +81,18 @@ def download_s3_folder_to_local(s3_folder: str = "files_to_ingest_into_vector_db
7881 except PermissionError as e :
7982 logger .error ("Error creating directories for %s: %s" , s3_folder , e )
8083 local_folder = f"/tmp/{ s3_folder } " # nosec B108
81- logger .info ("Downloading s3://%s/%s to local folder %s" , bucket , s3_folder , local_folder )
8284
8385 if config .environment == "local" :
8486 assert os .path .exists (
8587 local_folder
8688 ), f"Local folder { local_folder } should exist with manually downloaded files from S3"
8789 return local_folder
8890
91+ logger .info ("Downloading s3://%s/%s to local folder %s" , bucket , s3_folder , local_folder )
8992 s3 = file_util .get_s3_client ()
9093 paginator = s3 .get_paginator ("list_objects_v2" )
94+ if not s3_folder .endswith ("/" ):
95+ s3_folder += "/"
9196 try :
9297 for result in paginator .paginate (Bucket = bucket , Prefix = s3_folder ):
9398 for obj in result .get ("Contents" , []):
0 commit comments