Aug 25, 2023

Semantic Search in WordPress Part II: Harnessing Hooks for Streamlined Search Results

In our previous article, Leveraging Semantic Search in WordPress: Creating Embeddings with Convoworks, Pinecone, and OpenAI GPT, we delved into the intricacies of semantic search, showcasing how to index your WordPress data in a vector database. In this continuation, we’ll guide you through integrating that indexed data into your website, effectively replacing the default WordPress search with a more advanced semantic search. This lets users query using full sentences and still receive pertinent results.

Benefits of Semantic Search

Semantic search represents a notable shift from the traditional keyword-centric searches. Rather than just matching keywords, it comprehends the intent and contextual significance of queries, delivering more accurate results. This significantly enhances the user experience. For example, instead of inputting “WordPress SEO tips”, a user could phrase it as “How can I optimize my WordPress site’s SEO?” and expect relevant articles in return.

Streamlining with WordPress Hooks

We’ve optimized search results in WordPress using its built-in hooks coupled with the Convoworks WordPress Hooks Package. For this guide, we’re focusing on the posts_search and pre_get_posts hooks.

Setting Up the Convoworks Service

Below is a service definition you can effortlessly import to your website. Remember, for this to function, your data should be indexed in Pinecone as outlined in our previous article.

GPT Embeddings Search Filter (JSON)

  1. First, install and activate the Convoworks WP plugin (available on WordPress.org), as well as the Convoworks GPT Package plugin (found on GitHub).
  2. In the wp-admin dashboard, head over to Convoworks WP, click on Create new service, choose Import from file, then upload the service definition and hit Submit.
  3. After importing, go to the Variables view to provide your Pinecone API key, Pinecone base URL (which you can find in your Pinecone Index dashboard), and the OpenAI API key.

To activate, access the Configuration view and turn on the WordPress Hooks platform for your new Convoworks service.

How Does It Work?

This service interfaces with the posts_search filter and the pre_get_posts action. While the former cancels the ongoing search, the latter, via the WP Hook Processor, conducts the bulk of the work: generating embeddings from the search query using OpenAI and then executing a search on the Pinecone vector database. Once the results are retrieved, the service sets search results based on a list of post IDs from Pinecone. Furthermore, it modifies the orderby attribute to post__in, ensuring results adhere to relevance.

Updating wp query search request

We’ve also implemented the ONLY_IF_PARAM_EXISTS variable, offering you the flexibility to enable semantic search conditionally. By default, it’s always active. However, you can add an “Semantic Search” checkbox to your search form, allowing users to compare traditional and semantic search results. If you opt for this, ensure the checkbox’s form name is used as the value for the ONLY_IF_PARAM_EXISTS variable.

Enabling custom search only if parameter exists

Give it a Go!

Witness this augmented system in action on the Convoworks Blog. Engage with our semantic search and observe its transformative effects firsthand.

Conclusion

With this setup, the search functionality of your WordPress website undergoes not just an enhancement, but a revolution. The integration can be effortlessly extended to platforms like WooCommerce, ensuring that your users enjoy a richer and more contextually precise search experience. The content you choose to index and search can vary, and achieving truly remarkable results will require experimentation in data preparation for indexing. Fortunately, Convoworks offers the perfect blend of flexibility you need.
Embrace the future of search with Convoworks and its semantic capabilities!

Tihomir Dmitrović

Tihomir Dmitrović

Full stack developer with 20+ years of professional experience, specialized in solving complex problems in a scalable manner. Founded Convoworks, which is a GUI based tool for creating voice and chatbot applications through WordPress.

Oct 31, 2023  | 

The GPT Site Admin: A New Era of AI Integration with WordPress

We are already witnessing various AI integrations with WordPress, primarily in terms of generating content or other limited application…

VIEW FULL POST

Sep 8, 2023  |  ,

Step-by-Step: Building a GPT-Enhanced Twitter Bot with WordPress and Convoworks

In our previous article, we introduced you to the basic usage of the Twitter API in conjunction with Convoworks….

VIEW FULL POST