Skip to content

Added store_many_vectors on Mongo Storage - #87

Open
etudor wants to merge 8 commits into
pixelogik:masterfrom
etudor:master
Open

Added store_many_vectors on Mongo Storage#87
etudor wants to merge 8 commits into
pixelogik:masterfrom
etudor:master

Conversation

@etudor

@etudoretudor commented Nov 20, 2019

Copy link
Copy Markdown

Because I found this method to be very useful on Redis storage, I've added it to the mongo storage as well.

I haven't done a benchmark to compare what is the speed increase vs single inserts.

@amorgunamorgun left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some tests for store_many_vectors to the mongo test suite?

self.mongo_object.insert_one(val_dict)

def _get_vector(self, hash_name, bucket_key, v, data):
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring belongs to store_vector method

def store_many_vectors(self, hash_name, bucket_keys, vs, data):
requests = []

for v, d, bk in zip(vs, data, bucket_keys):

@amorgunamorgunNov 20, 2019

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using from future.builtins import zip because it is more efficient in python2.7.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code, thanks

def store_many_vectors(self, hash_name, bucket_keys, vs, data):
requests = []

for v, d, bk in zip(vs, data, bucket_keys):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code, thanks


else:
vector = numpy.fromstring(val_dict['vector'],
vector = numpy.frombuffer(val_dict['vector'],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this because I got some deprecation warnings

Comment threadnearpy/storage/storage_mongo.py Outdated
Removes all buckets from all hashes and their content.
"""
self.mongo_object.remove(
self.mongo_object.delete_many(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove method is deprecated so I replaced it with the suggested delete_many. It avoids annoying deprecation warnings

@etudoretudor left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amorgun I added tests for the store_many_vectors method

@amorgun

Copy link
Copy Markdown
Collaborator

@etudor The test is broken because it cannot import InsertOne. You should add pymongo to test requirements.

@etudor

Copy link
Copy Markdown
Author

@amorgun I have updated this

@amorgun

Copy link
Copy Markdown
Collaborator

@etudor It looks like a lot of mongo tests are broken now in python2.7. Please, check if it is related to your changes. Maybe you should pin an older version of pymongo.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@etudor@amorgun