Skip to content

feat: Add Personalized Recommendations (experimental)#174

Merged
raed667 merged 26 commits intonextfrom
feat-personalized-recommend-v2
Feb 1, 2024
Merged

feat: Add Personalized Recommendations (experimental)#174
raed667 merged 26 commits intonextfrom
feat-personalized-recommend-v2

Conversation

@raed667
Copy link
Copy Markdown
Collaborator

@raed667 raed667 commented Jan 16, 2024

Personalized recommendations

We want to add experimental support for personalized recommendations, using Algolia Personalization "Classic"

This is an experimental UI library implementation that stitches together existing APIs.

A reference guide will also be shared for users who want to implement this in the flavor of their choice.

How to use

To enable personalisation with recommend, you'll need to import from /experimental-personalization like the following:

JavaScript

import { trendingItems } from '@algolia/recommend-js/dist/esm/experimental-personalization';

trendingItems({
  region: 'eu', // "eu" | "us"
  userToken: 'user_token',
  indexName: "indexName"
  // ...

Or by using a standalone endpoint:

<script src="https://cdn.jsdelivr.net/npm/@algolia/recommend-js/dist/umd/experimental-personalization/index.js"></script>

React

import { TrendingItems } from '@algolia/recommend-react/dist/esm/experimental-personalization';

<TrendingItems
  region="eu" // "eu" | "us"
  userToken="user_token"
  indexName="indexName"
  // ...

Or by using a standalone endpoint:

<script src="https://cdn.jsdelivr.net/npm/@algolia/recommend-react/dist/umd/experimental-personalization/index.js"></script>

We avoid using the pre-existing queryParameters for userToken to avoid unexpected side-effects as well as possible semantic-versioning headaches if/when personalized recommendations is supported by the Recommend API and the experimental parameter is removed.

Parameters

The following parameters are all required for personalization:

  • region : Personalization data is stored and processed in a specific region. You can check the region for your account in the Algolia dashboard.
  • userToken : Associates a certain user token with the current query learn more
  • suppressExperimentalWarning: (optional) boolean parameter to disable the experimental console warning message.

Notes

  • When using recommend-react: if the Recommend context is used for batching, the userToken passed to the component take precedence over the one passed to the context. (ie if you pass 2 different user-tokens between the context provider and the recommend component, the one from the component is used)

  • When using the <Recommend> React context provider, you will need to import all the components from /experimental-personalization.

  • Caching is proposed in a stacked PR feat: Add Personalized Recommendations (cache) #175

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 16, 2024

PR Preview Action v1.4.6
Preview removed because the pull request was closed.
2024-02-01 10:14 UTC

Copy link
Copy Markdown
Contributor

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

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

We gonna need some tests for all components to make sure that

  • the correct search parameters are sent
  • the correct warnings trigger
  • the correct errors trigger

Comment thread packages/recommend-core/src/personalization/__tests__/index.test.ts Outdated
Comment thread packages/recommend-core/src/personalization/getAffinities.ts
Comment thread packages/recommend-core/src/personalization/getPersonalizationFilters.ts Outdated
Comment thread packages/recommend-core/src/personalization/getPersonalizationFilters.ts Outdated
Comment thread packages/recommend-core/src/personalization/getPersonalizationFilters.ts Outdated
Comment thread packages/recommend-core/src/personalization/getStrategy.ts Outdated
Comment thread packages/recommend-core/src/personalization/isPersonalized.ts Outdated
Comment thread packages/recommend-core/src/personalization/isPersonalized.ts Outdated
Comment thread packages/recommend-core/src/personalization/index.ts
Comment thread packages/recommend-core/src/getTrendingItems.ts
);

function useFrequentlyBoughtTogether<TObject>(
export function useFrequentlyBoughtTogether<TObject>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just bringing awareness that this will now be exported from the package, which isn't part of the contract. (Could be fine as long as we don't document it, so we can remove it after the experimental package is removed.)

Comment thread packages/recommend-react/src/Recommend.tsx Outdated
Comment on lines +32 to +34
if (queries.length === 0) {
return Promise.resolve({ recommendations: [] });
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess that's fine but there's no way back after we release it this way. What used to be an API error now fails silently.

Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

interesting approach, I think it works overall

Comment thread examples/demo/src/routes/HomePage.tsx Outdated
TrendingItems,
RecommendedForYou,
} from '@algolia/recommend-react';
} from '@algolia/recommend-react/dist/esm/experimental-personalization';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
} from '@algolia/recommend-react/dist/esm/experimental-personalization';
} from '@algolia/recommend-react/experimental-personalization';

this would be possible with exports in package.json (but not sure if it's worth it of course)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, i thought about adding some config for it, but for a beta feature where we will guide the initial clients during the setup, i don't think it is really needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

alternatively if you put it directly in a experimental-personalization folder instead of inside dist/esm, that should work too, but again, same considerations apply.

@@ -0,0 +1,45 @@
import { PersonalizationProps } from '@algolia/recommend-core';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what do you think about adding a readme to this folder that explains what to remove once it's done?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Theoretically everything will be removed, as this will be part of the regular API calls, and the userToken will be part of queryParameters

Comment on lines -27 to +25
<Recommend recommendClient={recommendClient}>
<>
<TrendingFacets
recommendClient={recommendClient}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this have a reason to move the client out of the provider? Can you not mix Recommend from regular RecommendReact with the experimental one? Is there a good error message if it's mixed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I just wanted to show 2 ways to use Recommend with the Context Provider (PDP) and without (HomePage).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

And yes if you're using the Recommend Context (like the PDP), you will need to import all components from /experimental-personalization

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So is there a clear error if you use the regular provider with the experimental components? I didn't see it in the files.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I just added a note in the PR description (that will go also in the release note). Again this is something we can guide the beta clients through their implementation.

@raed667 raed667 merged commit 9ed2bfc into next Feb 1, 2024
@raed667 raed667 deleted the feat-personalized-recommend-v2 branch February 1, 2024 10:12
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

Successfully merging this pull request may close these issues.

4 participants