1

While searching a product_set using command line, we can set a parameter features.max Results to limit the number of items returned in the response.

Field-specific considerations:

features.maxResults - The maximum number of results to be returned.

But how can I pass this parameter while running the python script provided here?

Also, does this parameter affect the response time?

loadbox
  • 646
  • 14
  • 34
  • have you tried to define the parameter in `max_results` inside `ProductSearchParams` ? – ewertonvsilva Oct 20 '21 at 08:19
  • @ewertonvsilva No. Could you share the link to the documentation or GitHub? – loadbox Oct 23 '21 at 01:43
  • The `max_results` is a `feature` parameter. As I could understand from the [documentation on GitHub](https://github.com/googleapis/python-vision) and [here](https://pypi.org/project/google-cloud-vision/) (also checking the functions signatures) the following should work: `#add this line for the create feture:# feature = vision.Feature(max_results = 4) # change the response for this:# response = image_annotator_client.product_search(image, image_context=image_context, features = [feature])` tell me if it works so I can post the final answer. – ewertonvsilva Oct 25 '21 at 14:48
  • @ewertonvsilva Getting the error: ``` File "/opt/conda/lib/python3.7/site-packages/google/cloud/vision_helpers/decorators.py", line 111, in inner request = dict(image=image, features=[copied_features], **kwargs) TypeError: type object got multiple values for keyword argument 'features' ``` – loadbox Oct 26 '21 at 16:13

1 Answers1

1

The documentation is really not very well written, but I found that you just have to add the parameter max_results=<max> inside the method product_search as following:

response = image_annotator_client.product_search(
        image, image_context=image_context,max_results=2)

To confirm that it works, I've added the an debug line inside the file on the google library /usr/local/lib/python3.7/dist-packages/google/cloud/vision_helpers/decorators.py

And when I run the code, I get the printout of the request made to the api, and as you can see, the parameter is correctly defined:

# python3 search.py 

Result:

#BEGIN DEBUG:
{'image': source {
  image_uri: "gs://<bucket>/short-blue.jpeg"
}
, 'features': [{'type_': <Type.PRODUCT_SEARCH: 12>, 'max_results': 2}], 'image_context': product_search_params {
  product_set: "projects/<project>/locations/us-west1/productSets/product-set-name"
  product_categories: "apparel-v2"
  filter: "color:blue"
}
}
#END DEBUG:

Product set index time: 
None
Search results:
ewertonvsilva
  • 1,795
  • 1
  • 5
  • 15
  • Thanks for the solution, @ewertonvsilva. Although this question is for python, could you help fo GoLang too on where to specify this parameter maxResults? – loadbox Nov 08 '21 at 07:03