• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

securitywing

Run AI Embeddings Locally: Turn Text into Vectors Without the Cloud

by wing

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 quality
  • paraphrase-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):

Python
 
# 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

Python
 
# 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-transformers with all-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.

 
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")

texts = [
    "How do I reset my password?",

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.

Related posts:

  1. The Evolving Impact of AI on the IT Risk Landscape
  2. AI Ethics and Security: What You Need to Know

Filed Under: Artificial Intelligence

Primary Sidebar

Please help us sharing

Categories

  • Artificial Intelligence
  • AWS
  • Basics
  • Containers
  • Cryptocurrency
  • Cyber
  • Cyber Insurance
  • Internet Security and Safety
  • IS Audit
  • IT Security Exams
  • Law & Human Rights
  • Network Security Tips
  • Off Track
  • Social Media Governance
  • Tech Comparisons
  • Tech Stack Suitability
  • Telecom
  • Tutorial

CISSP Sample Test

Take a CISSP Sample Test

CISA Sample Test

CISA IT governance Sample test

Please Follow Us

Contact us for Ads

Go to Contact Form

Search

Footer

Copyrights

Protected by Copyscape Duplicate Content Detection Software

Securitywing.com reserves the copyrights of all of its published articles.No contents of this site is permitted to be published to anywhere else in the Internet.If any contents are found in any other websites, securitywing reserves the rights to file a DMCA complaint. But you have the right to use the link of any relevant article of this site to point from your website if you consider that it might improve the quality of your article.

Tags

antivirus audit AWS backup browser check cisco cloud computer cyber data database ddos email encryption firewall home hsrp ids internet it kubernetes linux load balancing malware network protection putty risk router security security tips server social media ssh SSL tools virus vpn vulnerability web webserver website windows wordpress

Copyright © 2010-2026 ·All Rights Reserved · SecurityWing.com