@@ -386,10 +386,9 @@ def get_database_object(self, api_endpoint: str | None = None):
386
386
token = self .token ,
387
387
keyspace = self .get_keyspace (),
388
388
)
389
- except Exception as e : # noqa: BLE001
390
- self .log (f"Error getting database: { e } " )
391
-
392
- return None
389
+ except Exception as e :
390
+ msg = f"Error fetching database object: { e } "
391
+ raise ValueError (msg ) from e
393
392
394
393
def collection_data (self , collection_name : str , database : Database | None = None ):
395
394
try :
@@ -447,61 +446,63 @@ def _initialize_database_options(self):
447
446
}
448
447
for name , info in self .get_database_list ().items ()
449
448
]
450
- except Exception as e : # noqa: BLE001
451
- self .log (f"Error fetching databases: { e } " )
452
-
453
- return []
449
+ except Exception as e :
450
+ msg = f"Error fetching database options: { e } "
451
+ raise ValueError (msg ) from e
454
452
455
453
def _initialize_collection_options (self , api_endpoint : str | None = None ):
454
+ # Retrieve the database object
456
455
database = self .get_database_object (api_endpoint = api_endpoint )
457
- if database is None :
458
- return []
459
456
460
- try :
461
- collection_list = list (database .list_collections (keyspace = self .get_keyspace ()))
457
+ # Get the list of collections
458
+ collection_list = list (database .list_collections (keyspace = self .get_keyspace ()))
459
+
460
+ # Return the list of collections and metadata associated
461
+ return [
462
+ {
463
+ "name" : col .name ,
464
+ "records" : self .collection_data (collection_name = col .name , database = database ),
465
+ "provider" : (
466
+ col .options .vector .service .provider if col .options .vector and col .options .vector .service else None
467
+ ),
468
+ "icon" : "" ,
469
+ "model" : (
470
+ col .options .vector .service .model_name if col .options .vector and col .options .vector .service else None
471
+ ),
472
+ }
473
+ for col in collection_list
474
+ ]
462
475
463
- return [
464
- {
465
- "name" : col .name ,
466
- "records" : self .collection_data (collection_name = col .name , database = database ),
467
- "provider" : (
468
- col .options .vector .service .provider
469
- if col .options .vector and col .options .vector .service
470
- else None
471
- ),
472
- "icon" : "" ,
473
- "model" : (
474
- col .options .vector .service .model_name
475
- if col .options .vector and col .options .vector .service
476
- else None
477
- ),
478
- }
479
- for col in collection_list
480
- ]
481
- except Exception as e : # noqa: BLE001
482
- self .log (f"Error fetching collections: { e } " )
476
+ def reset_build_config (self , build_config : dict ):
477
+ # Reset the list of databases we have based on the token provided
478
+ build_config ["api_endpoint" ]["options" ] = []
479
+ build_config ["api_endpoint" ]["options_metadata" ] = []
480
+ build_config ["api_endpoint" ]["value" ] = ""
481
+ build_config ["api_endpoint" ]["name" ] = "Database"
483
482
484
- return []
483
+ # Reset the list of collections and metadata associated
484
+ build_config ["collection_name" ]["options" ] = []
485
+ build_config ["collection_name" ]["options_metadata" ] = []
486
+ build_config ["collection_name" ]["value" ] = ""
487
+
488
+ return build_config
485
489
486
490
def update_build_config (self , build_config : dict , field_value : str , field_name : str | None = None ):
487
- # TODO: Remove special astra flags when overlays are out
488
- # TODO: Better targeting of this field
489
- dslf = os .getenv ("AWS_EXECUTION_ENV" ) == "AWS_ECS_FARGATE"
491
+ # When the component first executes, this is the update refresh call
492
+ first_run = field_name == "collection_name" and not field_value
493
+
494
+ # If the token has not been provided, simply return
495
+ if not self .token or field_name == "environment" :
496
+ return self .reset_build_config (build_config )
490
497
491
498
# Refresh the database name options
492
- if not dslf and (field_name in ["token" , "environment" ] or not build_config ["api_endpoint" ]["options" ]):
499
+ if first_run or field_name == "token" :
500
+ # Reset the build config to ensure we are starting fresh
501
+ build_config = self .reset_build_config (build_config )
502
+
493
503
# Get the list of options we have based on the token provided
494
504
database_options = self ._initialize_database_options ()
495
505
496
- # Reset the collection values selected
497
- build_config ["collection_name" ]["options" ] = []
498
- build_config ["collection_name" ]["options_metadata" ] = []
499
- build_config ["collection_name" ]["value" ] = ""
500
-
501
- # Scenario #1: We have database options from the provided token
502
- build_config ["api_endpoint" ]["value" ] = ""
503
- build_config ["api_endpoint" ]["name" ] = "Database"
504
-
505
506
# If we retrieved options based on the token, show the dropdown
506
507
build_config ["api_endpoint" ]["options" ] = [db ["name" ] for db in database_options ]
507
508
build_config ["api_endpoint" ]["options_metadata" ] = [
@@ -521,6 +522,8 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:
521
522
] = self.map_cloud_providers()[cloud_provider]["regions"]
522
523
"""
523
524
525
+ return build_config
526
+
524
527
# Refresh the collection name options
525
528
if field_name == "api_endpoint" :
526
529
# Reset the selected collection
@@ -537,7 +540,7 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:
537
540
538
541
# Reload the list of collections and metadata associated
539
542
collection_options = self ._initialize_collection_options (
540
- api_endpoint = build_config ["d_api_endpoint" ]["value" ] if not dslf else None
543
+ api_endpoint = build_config ["d_api_endpoint" ]["value" ]
541
544
)
542
545
543
546
# If we have collections, show the dropdown
@@ -546,31 +549,20 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:
546
549
{k : v for k , v in col .items () if k not in ["name" ]} for col in collection_options
547
550
]
548
551
552
+ return build_config
553
+
549
554
# Hide embedding model option if opriona_metadata provider is not null
550
555
if field_name == "collection_name" and field_value :
551
556
# Set the options for collection name to be the field value if its a new collection
552
557
if field_value not in build_config ["collection_name" ]["options" ]:
553
- # If this is running in DSLF, we may need to initialize the options again
554
- if dslf :
555
- # Reload the list of collections and metadata associated
556
- collection_options = self ._initialize_collection_options (
557
- api_endpoint = build_config ["d_api_endpoint" ]["value" ] if not dslf else None
558
- )
559
-
560
- # If we have collections, show the dropdown
561
- build_config ["collection_name" ]["options" ] = [col ["name" ] for col in collection_options ]
562
- build_config ["collection_name" ]["options_metadata" ] = [
563
- {k : v for k , v in col .items () if k not in ["name" ]} for col in collection_options
564
- ]
565
- else :
566
- # Add the new collection to the list of options
567
- build_config ["collection_name" ]["options" ].append (field_value )
568
- build_config ["collection_name" ]["options_metadata" ].append (
569
- {"records" : 0 , "provider" : None , "icon" : "" , "model" : None }
570
- )
571
-
572
- # Ensure that autodetect collection is set to False, since its a new collection
573
- build_config ["autodetect_collection" ]["value" ] = False
558
+ # Add the new collection to the list of options
559
+ build_config ["collection_name" ]["options" ].append (field_value )
560
+ build_config ["collection_name" ]["options_metadata" ].append (
561
+ {"records" : 0 , "provider" : None , "icon" : "" , "model" : None }
562
+ )
563
+
564
+ # Ensure that autodetect collection is set to False, since its a new collection
565
+ build_config ["autodetect_collection" ]["value" ] = False
574
566
else :
575
567
build_config ["autodetect_collection" ]["value" ] = True
576
568
0 commit comments