Closed
Description
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
If needed, we can create a minimum reproduction.
Client
Recommend
Version
5.7.0
Relevant log output
No response