[docs]defget_collection(self,name:str,create_if_not_exists=True,**kwargs)->"Collection":ifnotself._collections:self.init_collections()ifnamenotinself._collections.keys():ifcreate_if_not_exists:self._collections[name]=self.create_collection(name)else:raiseKeyError(f"Collection {name} does not exist")returnself._collections[name]
[docs]defcreate_collection(self,name:str,alias:Optional[str]=None,metadata:Optional[CollectionConfig]=None,**kwargs)->Collection:ifnotname:raiseValueError(f"Collection name must be provided: alias: {alias} metadata: {metadata}")collection_cls=self.collection_classcollection=collection_cls(name=name,alias=alias,parent=self,metadata=metadata)ifnotself._collections:self._collections={}ifnotalias:alias=nameself._collections[alias]=collectionreturncollection