Table of contents :

How to (Easily) Configure Weaviate (AI search) on WordPress

Add Weaviate AI search to your Wordpress

Table of contents :

What if you wanted to have an AI search for your WordPress websites ? Thanks to WPSolr and Weaviate, you can set it up.

 

Weaviate vector search stack for WPSOLR

You can install our fully functional Weaviate vector search stack from GitHub, ready to work with WPSOLR.

Image wpsolr-stack-weaviate-1024x713.png of How to (Easily) Configure Weaviate (AI search) on WordPress

What is Weaviate ?

Weaviate is an open-source vector database. It is free to download (and install) and you can use it as an AI search engine to upgrade your WordPress search. AI search offers multiple benefits and uses :

  • Semantic search : This type of search uses a vector database and works by matching meanings and contexts instead of literal words. For example, “something to sleep on” would return beds even if the results don’t contain the word “sleep”. The advantages of this search is that it needs less fine-tuning than keyword search and it is multilingual.
  • Image search : Return results that contain matching images to the query the user entered in the search bar.

Integrate a locally installed Weaviate server into your WordPress

1. Install Weaviate

We are going to use docker containers to host the different applications. To install the docker engine, use the following link : https://docs.docker.com/engine/install/.

Also, don’t forget to install docker-compose.

For more detailed Weaviate installation and configuration instructions, you could check out our guide.

Create the following “docker-compose.yml” file :

version: '3.9'

services:
  weaviate:
    command:
    - --host
    - 0.0.0.0
    - --port
    - '8080'
    - --scheme
    - http
    image: cr.weaviate.io/semitechnologies/weaviate:1.25.2
    ports:
    - 8080:8080
    - 50051:50051
    restart: on-failure:0
    environment:
      TRANSFORMERS_INFERENCE_API: 'https://t2v-transformers:8080'
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'text2vec-transformers'
      ENABLE_MODULES: 'text2vec-transformers'
      CLUSTER_HOSTNAME: 'node1'
  t2v-transformers:
    image: cr.weaviate.io/semitechnologies/transformers-inference:baai-bge-small-en-v1.5
    environment:
      ENABLE_CUDA: '0'

And start the container using :

docker-compose up -d

You can check if the the container was correctly created using :

docker ps

You can now connect to the Weaviate service :

curl https://localhost:8080

If it works it should return something like the following :

{
   "links":{
      "href":"/v1",
      "name":"api v1",
      "documentationHref":"https://weaviate.io/developers/weaviate/current/"
   }
}

Setup WordPress (Optional)

If you don’t already have an active WordPress server, you can set it up locally.

Simply edit the previously created “docker-compose.yml” file with the following modifications :

version: '3.9'

services:
  wp:
    image: wordpress:php8.2-apache
    ports:
      - 80:80
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - backend-wpd
      - frontend-wpd
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - backend-wpd
  weaviate:
    command:
    - --host
    - 0.0.0.0
    - --port
    - '8080'
    - --scheme
    - http
    image: cr.weaviate.io/semitechnologies/weaviate:1.25.2
    ports:
    - 8080:8080
    - 50051:50051
    restart: on-failure:0
    environment:
      TRANSFORMERS_INFERENCE_API: 'https://t2v-transformers:8080'
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'text2vec-transformers'
      ENABLE_MODULES: 'text2vec-transformers'
      CLUSTER_HOSTNAME: 'node1'
    networks:
      - frontend-wpd
  t2v-transformers:
    image: cr.weaviate.io/semitechnologies/transformers-inference:baai-bge-small-en-v1.5
    environment:
      ENABLE_CUDA: '0'
    networks:
      - frontend-wpd

networks:
  frontend-wpd:
  backend-wpd:

Make sure that the WordPress & Weaviate server are in the same network so they can communicate with eachother.

If this is a production configuration, you should use volumes or bind mounts to save the data on your host machine. This ensures that there will be no critical data loss if anything happened to the container.

2. Add locally hosted Weaviate to your WordPress using WPSolr Free

WPSolr is a WordPress search plugin that powers up WordPress search using fast, accurate and scalable search engines. This means it can integrate Weaviate into any WordPress website.

Since this is a locally installed Weaviate server, you can use the free version : WPSolr Free.

You can search for WPSolr in the WordPress plugins catalogue.

Activate WPSolr Free in the "Add Plugins page" page

Click on the install and activate buttons for the WPSolr plugin.

Click on the "WPSolr Free" button to access the settings

Once you have installed and activated the WPSolr Free plugin, you can configure it.

To do that you first need to open the WPSolr settings page.

Open the indexes page in WPSolr dashboard.

Create the Weaviate index

To add your WordPress data to your Weaviate server, you first need to create an index. You can do that directly from WPSolr.

This portion will teach you how to create your index on your locally installed Weaviate server.

Open the indexes tab in the WPSolr dashboard.

Create a new Elasticsearch index in the WPSolr dashboard.

Create a new index.

Weaviate index from the WPSolr settings page.

Create the index by doing the following :

  • Select Weaviate search engine.
  • Enter the name of the index that will be displayed in the WPSolr settings.
  • Set the name of the index in the Weaviate server.
  • Set the Weaviate host url :
    • if the WordPress server is a container in the same docker network as Weaviate, you need to enter the name of the service (the one in the docker-compose.yml file). For this example, it should be “https://weaviate:8080”.
    • if the WordPress is on a separate server than Weaviate, you need to enter the ip address or hostname of the Weaviate server.

You can now save your index.

Index your data

Once you have created your index, you can click on “2. Define your search” tab.

 

WPSolr open data tab

Click on the “2.2 Data” tab.

WPSolr select data to index

Select the data types you want to index. You can do that by simply checking the boxes.

Open "Send your data"

Click on the “3. Send your data” tab.

Click on the "Index the data button"

 

Check the boxes of the data you selected previously. You can then click on the “Index selected post types” button to index the data.

Configure your search

This section will focus on replacing the WordPress search with WPSolr search powered by your Weaviate server.

Click on the 2.1 tab

Click on the “2. Define your search” tab.

Select the Weaviate index from the drop--down list.

 

Select the index you created previously. In this example, “local_weaviate”.

Select the archives to replace with WPSolr search

 

Select the archives to replace with WPSolr search. This means that the filtering sorting, etc… of content in the search pages and homepage will be handled by WPSolr and Weaviate.

Since you have selected “Search archive”, it should now be used whenever your use a search bar.

3. Add Facets and Ajax search to your WordPress

WPSolr Free can also add Ajax (live) search and facets powered by Weaviate to your WordPress websites.

Learn how to add ajax search using WPSolr.

Learn how to add facets using WPSolr.

 

Conclusion

It is a good idea to integrate search engines like Weaviate into WordPress have a AI search. You can do precisely that using WPSolr which can integrate a host of search engines into your WordPress and Woocommerce websites.

Trending posts
You might also like