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

[bug]: RecommendClient has incorrect RecommendationResults type if the recommendations are fallbacks #1560

Closed
Zach-Jaensch opened this issue Oct 10, 2024 · 2 comments
Labels

Comments

@Zach-Jaensch
Copy link

Description

When using the recommendation client with fallbackParameters set, and the object has no recommendations (ie, it is a new object and has not been trained into the engine) the recommendation results have no _score field.

We use validation for all 3rd party apis (implemented with zod) that satisfy the types given by the third party and it has caught this issue for us. We have implemented the following work around, but it would be good to understand if it is expected that _score is missing or not.

import type { RecommendationsResults } from "algoliasearch";
import { z } from "zod";

type TempRecommendationResults = Omit<RecommendationsResults, "_score"> & {
  _score?: number | undefined;
};

export const recommendationSearchResponseSchema = z.object({
  // ... schema ...
}) satisfies z.ZodType<TempGetRecommendationsResponse>;

Link to the docs for the type: https://www.algolia.com/doc/rest-api/recommend/#tag/recommendations/operation/getRecommendations
Responses > 200 > results > hits
image

If needed, we can create a minimum reproduction.

Client

Recommend

Version

5.7.0

Relevant log output

No response

@shortcuts
Copy link
Member

Hey, I totally forgot to answer your issue, this has been fixed here algolia/api-clients-automation#3967 I'll release in the hour

@shortcuts
Copy link
Member

(thanks for reporting!! :D)

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

No branches or pull requests

2 participants