Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hits Array Contains Nil Values in client.get_recommendations Response #507

Open
amin19948 opened this issue Nov 15, 2024 · 1 comment
Open

Comments

@amin19948
Copy link

amin19948 commented Nov 15, 2024

Description

I'm trying to implement Algolia recommendations using the client.get_recommendations method. While the response indicates there are hits (@nb_hits=5), the hits array itself contains only nil values: @hits=[nil, nil, nil, nil, nil].

Here’s the code I’m using to make the recommendations request:

response = client.get_recommendations(
  Algolia::Recommend::GetRecommendationsParams.new(
    requests: [
      Algolia::Recommend::RelatedQuery.new(
        index_name: "my_index_name",
        object_id: "268127",
        model: "related-products",
        threshold: 42.1
      )
    ]
  )
)

This is the response object I’m receiving:

#<Algolia::Recommend::GetRecommendationsResponse:0x00000001114b27a8
 @results=
  [#<Algolia::Recommend::RecommendationsResults:0x00000001114b3360
    @exhaustive=#<Algolia::Recommend::Exhaustive:0x0000000110d56770 @nb_hits=true, @typo=true>,
    @exhaustive_nb_hits=true,
    @exhaustive_typo=true,
    @hits=[nil, nil, nil, nil, nil],
    @hits_per_page=30,
    @index="my_index_name",
    @nb_hits=5,
    @nb_pages=1,
    @page=0,
    @processing_time_ms=3,
    @processing_timings_ms={:_request=>{:roundTrip=>27}, :afterFetch=>{:format=>{:total=>1}}, :rules=>1, :total=>3},
    @rendering_content=#<Algolia::Recommend::RenderingContent:0x0000000110d55348>,
    @server_time_ms=8>]>

Expected Behavior
The hits array should contain actual recommended items instead of nil values.

Actual Behavior
The hits array in the response contains only nil values, even though @nb_hits=5.

Question
Is there something wrong with the way I’ve configured the request? Could the issue be related to the data in my index or the related-products model?

Any guidance on resolving this issue would be greatly appreciated!

Client

Recommend

Version

3.7.1

Relevant log output

No response

@amin19948 amin19948 changed the title [bug]: Hits Array Contains Nil Values in client.get_recommendations Response Hits Array Contains Nil Values in client.get_recommendations Response Nov 15, 2024
@shortcuts
Copy link
Member

Hey @amin19948 thanks for reporting the issue, sorry we did not came back to you earlier!

I can confirm this is a deserialization issue on the API client side, in the meantime of a fix you can append _with_http_info to the methods you are using (e.g. get_recommendations_with_http_info) which should return the raw response and use it like below

res, _, _ = recommend_client.get_recommendations_with_http_info(
  Algolia::Recommend::GetRecommendationsParams.new(
    requests: [
      Algolia::Recommend::RelatedQuery.new(...)
    ]
  )
)

puts res.body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants