Skip to content

Commit

Permalink
Merge pull request #71 from datastax/feature/#42-collection-naming
Browse files Browse the repository at this point in the history
Fix #42: Update the collection naming routine
  • Loading branch information
hemidactylus authored Nov 2, 2023
2 parents 9fabd5d + a305f8b commit c866065
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion astrapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
39 changes: 29 additions & 10 deletions astrapy/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down

0 comments on commit c866065

Please sign in to comment.