Every other WooCommerce site now has a “Chat with your Store” box bolted on, built on the assumption that one API call to OpenAI is the whole job. Then the RAG (Retrieval-Augmented Generation) pipeline starts returning nonsense, and the LLM turns out not to be the part that is broken. Embedding models are, or more precisely the way they map your text is.
I have spent a decade pulling apart search logic built on crude SQL LIKE queries. Vector search feels like magic for about a week, right up until you notice the map it built has very little to do with your actual business data. That gap is what separates a search box that helps customers from one that invents price points.
Coordinates instead of keywords
An embedding model is a neural network that maps words or sentences into a continuous vector space. Every piece of text ends up with a set of coordinates, and unlike a keyword index those coordinates have nothing to do with spelling. They come from meaning.
In a decently trained model, “cat” and “kitten” land next to each other while “quantum physics” sits nowhere near either. Ask a question and the model turns your query into a vector, then looks for the stored documents closest to that point.
My earlier write-up on Gemini Embeddings 2 covers the multi-modal side of this.
How embedding models process a query
Three things happen between the request hitting your backend and a match coming back:
- Tokenization, which breaks the text into the smallest units the model works with.
- Chunking, which splits long text into pieces of roughly 512 tokens so nothing overflows the context window.
- Vector search, which turns the query into a vector and scores it against the database, usually with cosine similarity.
Here it is with a BERT (Bidirectional Encoder Representations from Transformers) tokenizer in Python. In WordPress you would trigger this through WP-CLI or a remote API, but the logic is the same:
from transformers import BertTokenizer
# Load the pre-trained tokenizer
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
text = "Embedding models are the backbone of AI search."
# Step 1: Tokenize
tokens = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
print(tokens['input_ids'])
Fine-tuning: reorganizing the map
The default map is often wrong for a narrow catalog. Sell specialized medical equipment and “monitor” should not sit next to “computer screen”, it should sit next to “vital signs”. Rearranging it is what contrastive learning does.
You teach it with triplets:
- An anchor, the reference item, say “Brand A Cola”.
- A positive, a similar item the model should pull closer, like “Brand B Cola”.
- A negative, something it should push away, like “Diet Cola Zero Sugar”.
Two things get better as you do this: alignment, meaning related items stay together, and uniformity, meaning the model uses the whole space instead of crowding everything into one corner. If your problem is speed rather than relevance, you probably need to optimize your vector search for scale.
Integrating with a vector database
On a production WordPress box you do not run these models locally. Try it and you will meet a 504 Gateway Timeout. The vectors go to a database built for them, such as Qdrant or Pinecone:
from qdrant_client import QdrantClient, models
from sentence_transformers import SentenceTransformer
# Load model and initialize client
model = SentenceTransformer('all-MiniLM-L6-v2')
client = QdrantClient(":memory:")
# 3. Create and store vectors
docs = ["refund policy", "pricing", "cancellation"]
vectors = model.encode(docs).tolist()
client.upload_collection(
collection_name="wp_docs",
vectors=vectors,
payload=[{"text": d} for d in docs]
)
If embedding models are eating hours you would rather spend elsewhere, I can take that on. I have been working with WordPress since the 4.x days, and I know where API performance usually goes wrong.
Where to spend your effort
Computers do not read language, they do arithmetic on it, and the embedding model is what does the converting. When that conversion is off, the feature sitting on top of it is worse than no feature at all. So sort out your data quality and your chunking before you start rewording prompts.
The Sentence Transformers documentation is where I send anyone who wants to train their own. Dry reading, but accurate.