From ef8f441e115c2d974c6380a0febc22328426265f Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Thu, 2 Nov 2023 09:53:06 -0700 Subject: [PATCH 1/2] Fix #42: Update the collection naming routine --- astrapy/__init__.py | 2 +- astrapy/db.py | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) 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..7056704d 100644 --- a/astrapy/db.py +++ b/astrapy/db.py @@ -348,17 +348,26 @@ 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 and "dimension" not in options["vector"]: + options["vector"]["dimension"] = dimension + + # Check the metric parameter + if metric and "metric" not in options["vector"]: + options["vector"]["metric"] = metric + + # 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}", From a305f8bb0befa423d38dd44176b3e49585fb61ed Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Thu, 2 Nov 2023 10:23:18 -0700 Subject: [PATCH 2/2] Update db.py --- astrapy/db.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/astrapy/db.py b/astrapy/db.py index 7056704d..002b3d2d 100644 --- a/astrapy/db.py +++ b/astrapy/db.py @@ -357,12 +357,22 @@ def create_collection( options["vector"] = {} # Now check the remaining parameters - dimension - if dimension and "dimension" not in options["vector"]: - options["vector"]["dimension"] = 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 and "metric" not in options["vector"]: - options["vector"]["metric"] = metric + 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}