all-mpnet-base-v2 is a general-purpose sentence-embedding model for semantic search and clustering. It maps sentences and short passages to 768-dimensional vectors whose dimensions encode learned latent features. section 9.4.1
A search pipeline uses the model to:
- Encode product names or other text into embeddings. section 9.4.1
- Compare vectors to estimate semantic similarity. section 9.4.1
- Cache generated embeddings when processing a larger product collection. section 9.4.1
Listing 9.12 Generating product embeddings
from sentence_transformers import SentenceTransformer #1
transformer = SentenceTransformer("all-mpnet-base-v2") #1
... #2
def get_embeddings(texts, model, cache_name, ignore_cache=False):
... #2
embeddings = model.encode(texts) #3
... #2
return embeddings
product_embeddings = get_embeddings(product_names,
transformer, cache_name="all_product_embeddings")
The implementation shows how SentenceTransformers loads the model and encodes product names into reusable embedding vectors. section 9.4.1
