diff --git a/astrapy/__init__.py b/astrapy/__init__.py index 236e541c..5960bff2 100644 --- a/astrapy/__init__.py +++ b/astrapy/__init__.py @@ -11,4 +11,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.5.2" +__version__ = "0.5.3" diff --git a/astrapy/db.py b/astrapy/db.py index 8242f56f..002b3d2d 100644 --- a/astrapy/db.py +++ b/astrapy/db.py @@ -348,17 +348,36 @@ def get_collections(self): return response def create_collection( - self, dimension=None, options={}, function="", collection_name="" + self, options=None, dimension=None, metric="", collection_name="" ): - if dimension and not options: - options = {"vector": {"dimension": dimension}} - if function: - options["vector"]["function"] = function - if options: - jsondata = {"name": collection_name, "options": options} - else: - jsondata = {"name": collection_name} - + # Initialize options if not passed + if not options: + options = {"vector": {}} + elif "vector" not in options: + options["vector"] = {} + + # Now check the remaining parameters - dimension + if dimension: + if "dimension" not in options["vector"]: + options["vector"]["dimension"] = dimension + else: + raise ValueError( + "dimension parameter provided both in options and as function parameter." + ) + + # Check the metric parameter + if metric: + if "metric" not in options["vector"]: + options["vector"]["metric"] = metric + else: + raise ValueError( + "metric parameter provided both in options as function parameter." + ) + + # Build the final json payload + jsondata = {"name": collection_name, "options": options} + + # Make the request to the endpoitn response = self._request( method=http_methods.POST, path=f"{self.base_path}",