If you’re looking to improve product discoverability and boost conversions in your Magento store, vector search is one of the most impactful upgrades you can make. Instead of relying only on exact keyword matches, vector search understands the meaning behind a query, so when a shopper searches for “lightweight trail shoes for flat feet,” your store can finally return products that match the intent, not just the words.
This article walks you through what vector search is, how it works with Elasticsearch 8.x, and how you can implement it in Magento 2 in a structured and low-risk way.
Key Concepts Behind Modern Search
Before we dive deeper, here are a few core search concepts referenced throughout this article:
BM25 (Best Match 25)
A proven keyword-based ranking algorithm used by Elasticsearch. It evaluates how closely a document matches a query based on term frequency and relevance.
k-NN (k-Nearest Neighbors)
A method used to find items whose vector embeddings are closest in meaning to the user’s query.
HNSW (Hierarchical Navigable Small World)
A high-performance graph-based indexing structure inside Elasticsearch that makes k-NN searches extremely fast, even on large catalogs.
RRF (Reciprocal Rank Fusion)
A simple and effective technique that blends results from keyword search and vector search, making hybrid search more balanced and reliable.
What is Vector Search?
Vector search represents text - product names, descriptions, attributes, and even customer queries, as numerical vectors called embeddings. Instead of checking whether words match, Elasticsearch checks whether the meanings are close.
To support this, Elasticsearch stores embeddings in a dense_vector field and retrieves the most relevant products using a fast k-NN algorithm powered by HNSW.
Why It Matters for E-Commerce (Magento)
Vector search brings a significant leap in search experience for Magento users. It helps stores surface more relevant and intuitive results, especially when shoppers use conversational or vague queries. This directly improves product discovery, reduces search abandonment, and increases conversions.
Here’s why Magento merchants benefit from vector search:
- Understands search intent and synonyms (e.g., “sneakers” ≈ “running shoes”).
- Handles long, conversational queries far better than traditional keyword search.
- Works seamlessly with merchandising rules such as category, stock, price, and brand filters.
- Can be combined with BM25 in a hybrid setup, with RRF blending the strengths of both approaches.
How Vector Search Works in Elasticsearch (8.x)
Elasticsearch 8.x includes native support for vector fields, making it possible to compare embeddings and return results based on meaning rather than exact text matches. When the dense_vector field is indexed, Elasticsearch can perform fast k-NN searches using HNSW. The similarity method you choose - cosine, dot product, or L2 - determines how relevance is calculated.
Key steps involved:
- Store embeddings inside a dense_vector field.
- Enable k-NN indexing so Elasticsearch can use HNSW for fast similarity search.
- Query using _knn_search or via the knn parameter within _search, combined with filters.
- Blend results with BM25 using RRF for strong, consistent hybrid ranking.
Prerequisites for Implementing Vector Search in Magento 2
To implement vector search, you’ll need:
- Elasticsearch 8.x with vector support enabled.
- An embedding model (OpenAI, Cohere, or a self-hosted model).
- Magento 2 (Open Source or Adobe Commerce) with product and attribute access.
Implementation Overview (Magento 2 + Elasticsearch)
Setting up vector search in Magento involves a few structured steps. Each step helps build a reliable foundation for semantic search.
- Choose your embedding model
Prefer multilingual models if your store supports multiple locales. - Prepare the product text
Combine the product name, important attributes, and description - per store view—to form clean, meaningful text for embedding. - Generate and store embeddings
Use a CLI command or indexer to send text to your embedding model and save the result in Elasticsearch. - Create your Elasticsearch mapping
Add a dense_vector field along with all the usual product fields. - Update the search flow
- Embed the user query.
- Run a k-NN search with filters (store, stock, category).
- Optionally blend with BM25 and apply RRF for hybrid search.
Elasticsearch Mapping for Vector Search in Magento 2
To enable semantic search, Elasticsearch needs a mapping that defines both standard product fields and the vector field where embeddings are stored.
PUT magento_products
{
"mappings": {
"properties": {
"sku": { "type": "keyword" },
"store_id": { "type": "keyword" },
"name": { "type": "text" },
"description":{ "type": "text" },
"brand": { "type": "keyword" },
"price": { "type": "float" },
"in_stock": { "type": "boolean" },
"categories": { "type": "keyword" },
"embedding": {
"type": "dense_vector",
"dims": 768,
"index": true,
"similarity": "cosine"
}
}
}
}
k-NN Query with Pre-Filters (Store, Stock, Category)
k-NN search retrieves products based on semantic similarity between the query embedding and product embeddings. Adding filters ensures the results stay aligned with your catalog rules.
POST magento_products/_knn_search
{
"knn": {
"field": "embedding",
"query_vector": [/* 768 floats */],
"k": 50,
"num_candidates": 200
},
"filter": [
{ "term": { "store_id": "1" } },
{ "term": { "in_stock": true } },
{ "terms": { "categories": ["running","shoes"] } }
],
"_source": ["sku","name","price","brand"]
}
Tip: Pre-filters reduce the number of candidates, improving speed and relevance.
Hybrid Search (BM25 + Vector) with RRF
Hybrid search combines keyword matching with semantic similarity, giving you the strengths of both approaches. RRF merges the results into one final ranking that stays robust across misspellings, jargon, and short or long-tail queries.
POST magento_products/_search
{
"sub_searches": [
{
"query": {
"multi_match": {
"query": "lightweight trail shoes",
"fields": ["name^4", "description"]
}
},
"size": 100
},
{
"knn": {
"field": "embedding",
"query_vector": [/* ... */],
"k": 100,
"num_candidates": 300
},
"size": 100
}
],
"rank": {
"rrf": { "window_size": 100, "rank_constant": 60 }
}
}
Magento 2 Integration Patterns for Vector Search
Magento offers several ways to integrate vector search without affecting your existing catalog or search workflows. Below are the common integration approaches:
- Sidecar API (fastest approach)
A separate endpoint receives the query, calls Elasticsearch, and returns SKUs to the frontend. - Adapter/Plugin integration
Replace or decorate Magento’s default search adapter so catalog search uses hybrid Elasticsearch. - Failover handling
Automatically fall back to BM25 if vector search or embeddings are temporarily unavailable.
Relevance Tuning
Fine-tuning relevance ensures search results closely match shopper expectations. Here are key areas to focus on:
- Title and name boosts
- Business-driven boosts (in-stock, margin, new-in, priority brands)
- Locale-specific embeddings and synonyms
- Choice of similarity metric (cosine or dot product)
Performance & Sizing Tips
Keeping vector search fast and efficient is essential, especially with large catalogs. Consider the following:
- Start with 384 - 768 embedding dimensions.
- Adjust k and num_candidates for the right balance of speed and accuracy.
- Cache query embeddings for popular searches.
- Use pre-filters to limit the search space.
Common Challenges & How to Fix Them
Vector search comes with its own set of challenges, but most are easy to address:
- Cold start: Use BM25 until embeddings are fully indexed.
- Weak long-tail queries: Increase num_candidates or strengthen synonym rules.
- Latency issues: Tighten filters or scale your Elasticsearch nodes.
- Multistore setups: Use separate indices for cleaner results.
Quick Magento Indexer Sketch (pseudo-PHP)
The example below illustrates how to generate embeddings for products and store them in Elasticsearch.
foreach ($products as $p){
$text = buildText($p, $storeId); // name + attrs + description
$vec = $embedService->embed($text); // array of floats
$doc = [
'sku' => $p->getSku(),
'store_id' => (string)$storeId,
'name' => $p->getName(),
'description'=> $p->getDescription(),
'brand' => $p->getAttributeText('brand') ?? null,
'price' => (float)$p->getFinalPrice(),
'in_stock' => $stock->isInStock($p),
'categories' => $catIds,
'embedding' => $vec
];
$client->index(['index'=>'magento_products','id'=>$p->getId()."_$storeId",'body'=>$doc]);
}
Conclusion
Vector search transforms Magento 2 from basic keyword lookups to truly intent-driven search. When powered by Elasticsearch’s k-NN, BM25, and RRF, your store delivers faster, smarter, and more relevant product results. Start small, evaluate performance, and roll out gradually for the best results.
Need help implementing vector search in Magento 2?
PIT Solutions has delivered Magento 2 search upgrades - from embedding pipelines to hybrid ranking and relevance tuning - for multi-store, multilingual catalogs. Contact us to discuss timelines, cost, and a pilot tailored to your catalog.
References
- Elasticsearch dense_vector mapping & k-NN search. Elastic search
- Filtered k-NN (pre-filtering guidance). k-NN filter
- RRF (hybrid ranking) and what’s new in 8.9. Hybrid ranking
- Weighted RRF (2025 update). RRF
- OpenSearch vs Elasticsearch vector types. OpenSearch vs Elasticsearch