Using the frontier models to generate vectors for semnatic search might be expensive for the beginner who wants to learn about vector search and create embedding using low power laptops or PC. This posts discuss about a few simple but useful techniques to vectorize texts for semantic searches.
Here’s a breakdown:
1. Practical Libraries/Frameworks
Python dominates this space. The most relevant libraries include:
- Sentence Transformers (
sentence-transformers)- Based on HuggingFace Transformers, simplifies everything.
- HuggingFace Transformers
- Direct use for more custom workflows.
- spaCy
- Good for general NLP pipelines, includes some embedding features.
- Gensim
- Traditional word embeddings (Word2Vec, FastText), less powerful than transformer-based models, but resource-light.
- fastText
- Fast and simple word-level embedding.
2. Models (for English and more)
Transformer models:
all-MiniLM-L6-v2(from Sentence Transformers)—fast, ~80MB, great qualityparaphrase-MiniLM-L12-v2(slightly bigger, more accurate)distiluse-base-multilingual-cased-v2(good for multiple languages)
Classic embeddings (hardware-light):
glove-wiki-gigaword-50(for Gensim)fasttext-wiki-news-subwords-300
3. Hardware Requirements
- CPU only: Most small or distilled transformer models run fine on modern CPUs.
- RAM: At least 4GB, ideally 8GB+ for smoother use.
- GPU: Only needed for big models (not required for most sentence transformers).
4. Minimal Example — Using Sentence Transformers
Here is an end-to-end example you can run on your laptop (CPU only):
# Install first:
# pip install sentence-transformers
from sentence_transformers import SentenceTransformer
# Choose a small, fast model
model = SentenceTransformer('all-MiniLM-L6-v2')
# Your texts
sentences = ["This is a test sentence.", "Embeddings make text machine-understandable."]
# Get the embeddings (vectors)
embeddings = model.encode(sentences)
print(embeddings.shape) # (2, 384)
print(embeddings[0][:10]) # Print first 10 vector values for the first sentence
5. Alternative: spaCy Example
# pip install spacy
# python -m spacy download en_core_web_md
import spacy
nlp = spacy.load("en_core_web_md")
doc = nlp("This is an example sentence.")
print(doc.vector[:10]) # First 10 dimensions
6. Summary Table
| Approach | Library | Hardware | Typical Vector Size | Notes |
| Sentence Transformers | sentence-transformers |
CPU/GPU, 4-8GB RAM | 384 or 768 | Best quality/performance |
| spaCy | spacy + models |
CPU | 300-500 | Fastest, mid-quality |
| Gensim/fastText | gensim, fasttext |
CPU, low RAM | 100-300 | Classic, word-level only |
- Best current solution:
sentence-transformerswithall-MiniLM-L6-v2—small, fast, good quality, CPU-friendly. - Minimal example provided above.
- Hardware: Any modern laptop with 4GB+ RAM suffices for small models.
Is Sentence Transformer will give you the best result?
Sentence Transformers are usually the best starting point for local text embeddings, especially for semantic search, clustering, recommendations, and RAG. But the model you choose matters more than the library itself.
Practical recommendations
| Need | Suggested model |
|---|---|
| Fast and lightweight English | sentence-transformers/all-MiniLM-L6-v2 |
| Better English retrieval quality | BAAI/bge-base-en-v1.5 |
| Multilingual text | intfloat/multilingual-e5-small |
| Very limited laptop resources | sentence-transformers/all-MiniLM-L6-v2 |
all-MiniLM-L6-v2 gives an excellent speed/quality balance, but it does not necessarily produce the highest-quality embeddings. Larger BGE or E5 models can perform better while requiring more memory and processing time.
Installation command:
pip install sentence-transformers
For a normal CPU laptop, you can start with all-MiniLM-L6-v2, measure its results on your own text, and only move to BGE or E5 if retrieval quality is insufficient. “Best” ultimately depends on your language, document types, and whether you prioritize accuracy or speed.
