---
title: AI Embedding Vectors for WordPress Search
date: 2025-03-06T09:24:10+00:00
modified: 2025-04-18T05:10:42+00:00
image:: https://wpelevator.com/wp-content/uploads/sites/12/2025/03/ai-embedding-vectors.png
permalink: https://wpelevator.com/guides/ai-embedding-search
post_type: page
author:
  name: Kaspars
  avatar: https://secure.gravatar.com/avatar/92bfcd3a8c3a21a033a6484d32c25a40b113ec6891f674336081513d5c98ef76?s=96&d=robohash&r=g
---

# AI Embedding Vectors for WordPress Search

AI embedding vectors is a fancy name for **a list of numbers** or coordinates that represent a piece of content in a space with multiple dimensions (usually 1536 or 3072). And the distance between those vectors represents the similarity between the pieces of content:

![Visualization of AI embeddings as vectors in a space](https://wpelevator.com/wp-content/uploads/sites/12/2025/03/ai-embedding-vectors.png?strip=all&quality=90&resize=2500,1401)This approach enables relevancy search locally using simple math:

1. Get a vector representation of the question from an AI model,
2. Calculate the distance between the question vector and the vectors in your database.

In the most basic implementation this requires looping through all vectors in the database so the search performance is directly related to the amount of content stored in the database.

## Store AI Embedding Vectors for All WordPress Content

The first step is to calculate and store the embedding vectors for all your content:

![How to retrieve and store AI embedding vectors for WordPress content](https://wpelevator.com/wp-content/uploads/sites/12/2025/03/wp-ai-embeddings-db-storage.png?strip=all&quality=90&resize=1935,1222)The MySQL database used by WordPress was not initially designed to perform any vector storage or math so it lacks support for specialized indexing and functionality for vector operations [before version 9.0](https://dev.mysql.com/doc/refman/9.0/en/mysql-nutshell.html#:~:text=MySQL%209.0%20supports%20a%20VECTOR,or%20a%20list%2Dformatted%20string.).

Version 9.0 and above supports both [`VECTOR` column type](https://dev.mysql.com/doc/refman/9.0/en/vector.html) and [`DISTANCE()` function](https://dev.mysql.com/doc/refman/9.0/en/vector-functions.html) for finding the nearest neighbors.

In earlier versions of MySQL it is possible to efficiently store vectors in a `VARBINARY` column and define custom MySQL functions for calculating the vector distance. However, defining custom functions is usually disabled on most hosting providers due to security concerns.

## Search WordPress Content by Embedding Vector Distance

The search happens by retrieving the embedding vector for the search query from an AI model and then finding the relevancy (distance) to all of the vectors stored in the database.

![AI embeddings search for WordPress content](https://wpelevator.com/wp-content/uploads/sites/12/2025/03/wp-ai-embeddings-db-search.png?strip=all&quality=90&resize=2500,1792)## Powering the Retrieval-Augmented Generation (RAG)

The vector search results can be used to retrieve relevant content from your WordPress database that LLMs can use to generate better responses to any question. This is known as retrieval-augmented generation (RAG).

This is a good alternative to training a custom AI model on your content.

## Suggested Reading

- [Google Cloud SQL vector support](https://cloud.google.com/sql/docs/mysql/vector-search)
- [MySQL Vector PHP library](https://github.com/allanpichardo/mysql-vector) using a custom MySQL function for calculating the cosine similarity between vectors stored in `JSON` column type.