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

Add a Smart 404 Feature #801

Merged
merged 8 commits into from
Sep 13, 2024
Merged

Add a Smart 404 Feature #801

merged 8 commits into from
Sep 13, 2024

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Sep 12, 2024

Description of the Change

Adding in a new Feature, Smart 404, that uses the power of embeddings, combined with vector search capabilities in Elasticsearch, to recommend content when users land on a 404 page, with the hope of recommending the actual item they were hoping to reach.

As mentioned, this Feature requires two services in order to function:

  1. A Provider that can generate embeddings (right now we support OpenAI and Azure OpenAI)
  2. A data storage engine that can also run vector queries (currently only support Elasticsearch powered by ElasticPress)

Once both are in place, all of your existing content (and any new content added in the future) is automatically sent off to the embeddings Provider. This vector information is then stored in elasticsearch and we can then run vector queries on this data. In particular, we've introduced new helper methods that can be dropped into a site's 404 template that will render these results.

At a high level, here's how the process works:

  1. When an item is saved, the content is broken down into smaller chunks. Each chunk is then sent off to an embeddings Provider (like OpenAI)
  2. The returned vector data is synced over to elasticsearch using ElasticPress
  3. When a user lands on a 404 page, we pull the last slug out of the URL. For instance, if someone is trying to go to example.com/news/interesting-news-article, we take the slug interesting-news-article
  4. This slug is then sent off to the embeddings Provider and the returned vector data is used to make a vector query against elasticsearch
  5. There are multiple configuration options here that can be used to modify this query but we eventually end up with results back which are then rendered to the user

Closes #794

How to test the Change

  1. Follow the instructions in the README to get things set up. This will include setting up an embeddings Provider and ElasticPress + Elasticsearch
  2. Run an ElasticPress sync from scratch. This can be done in the admin or using the WP-CLI command that ElasticPress provides. Important to run this from scratch so the proper mapping is sent
  3. Utilize one of the new helper functions to output results on your 404 template. Ensure this renders properly and that all various settings work as expected

Note it's helpful to install Query Monitor and the ElasticPress Debugging Add-On to see the actual elasticsearch queries and results

Changelog Entry

Added - New Feature, Smart 404, which provides the ability to render recommended content on a 404 page

Credits

Props @dkotter, @iamdharmesh, @berkod

Checklist:

@dkotter dkotter added this to the 3.2.0 milestone Sep 12, 2024
@dkotter dkotter self-assigned this Sep 12, 2024
@dkotter dkotter marked this pull request as ready for review September 12, 2024 21:31
@dkotter dkotter requested review from jeffpaul and a team as code owners September 12, 2024 21:31
@github-actions github-actions bot added the needs:code-review This requires code review. label Sep 12, 2024
@dkotter dkotter requested review from iamdharmesh and removed request for a team and jeffpaul September 12, 2024 21:31
@dkotter
Copy link
Collaborator Author

dkotter commented Sep 12, 2024

Note there are a couple other things we could consider doing here, either in this PR or in follow up PRs:

  1. Right now we check if ElasticPress is active before we allow the Feature to be configured (and we show an error message if not). But we never check to see if ElasticPress is actually configured properly and connected to elasticsearch. There may be a helper function we can utilize in ElasticPress for this
  2. We have a couple helper functions that can be used to render the results on a 404 page but this does require someone to manually add those to their template. May be worth adding a Smart 404 block that can be used in FSE themes to add this functionality directly to their 404 template

iamdharmesh
iamdharmesh previously approved these changes Sep 13, 2024
Copy link
Member

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

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

Thanks for the Great work here @dkotter. The code looks great and it tests well. Just added one minor suggestion otherwise this is ready for merge.

Note there are a couple other things we could consider doing here, either in this PR or in follow up PRs:

I think better to handle it in separate follow up PRs.

includes/Classifai/Features/Smart404EPIntegration.php Outdated Show resolved Hide resolved
@dkotter dkotter merged commit a5332d1 into develop Sep 13, 2024
14 checks passed
@dkotter dkotter deleted the feature/smart-404 branch September 13, 2024 19:29
@dkotter dkotter mentioned this pull request Oct 9, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-review This requires code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to craft "Smart 404" pages
2 participants