+91 99301 12627
RAG & AI Applications

What Are Embeddings? Vector Embeddings Explained for AI and RAG

By Mehul Prajapati

Milky Way stars representing points in an embedding vector space
On this page

Short answer: Embeddings are lists of numbers (vectors) that represent the meaning of text, images or other data, so that similar things end up close together in vector space. For example, “How do I reset my password?” and “I forgot my login” get similar embeddings even though they share few words. Embedding models create these vectors, and similarity measures such as cosine similarity compare them. Embeddings power semantic search, RAG, recommendations, clustering and duplicate detection.

Key takeaways

  • An embedding turns meaning into a vector of numbers.
  • Close vectors = similar meaning.
  • Embeddings are the core of semantic search and RAG retrieval.
  • Use the same embedding model for documents and queries.

An intuitive example

Imagine every sentence placed on a map where distance reflects meaning. “Python course in Borivali” sits near “Learn Python near Borivali West” and far from “weather in Delhi”. Real embeddings use hundreds or thousands of dimensions instead of two, but the idea is the same.

How similarity is measured

Measure Idea
Cosine similarity Angle between vectors; most common for text
Dot product Equivalent to cosine for normalised vectors
Euclidean distance Straight-line distance between points

Create embeddings in Python

from sentence_transformers import SentenceTransformer, util

model = SentenceTransformer('all-MiniLM-L6-v2')
sentences = ['How do I reset my password?',
             'I forgot my login details',
             'What are your batch timings?']

emb = model.encode(sentences)
print(emb.shape)                       # (3, 384)
print(util.cos_sim(emb[0], emb[1]))   # high
print(util.cos_sim(emb[0], emb[2]))   # lower

This small open-source model produces 384-dimensional vectors. Hosted embedding APIs from LLM providers work the same way. See Hugging Face for beginners.

Where embeddings are used

  • Semantic search: find documents by meaning, not exact keywords
  • RAG: retrieve relevant chunks to ground an LLM’s answer
  • Recommendations: “similar products” or “similar courses”
  • Clustering: group support tickets or feedback by topic
  • Deduplication: find near-duplicate questions or records
  • Classification: embeddings as features for a simple classifier

Embeddings in a RAG pipeline

  1. Split documents into chunks (see RAG chunking strategies)
  2. Embed each chunk and store vectors in a vector database
  3. Embed the user’s question with the same model
  4. Retrieve the nearest chunks and pass them to the LLM

How to choose an embedding model

  • Language: multilingual models for Hindi, Marathi or mixed text
  • Quality: test on your own queries; public benchmarks such as MTEB are a starting point
  • Dimensions: more dimensions can capture more detail but cost more storage
  • Cost and privacy: hosted APIs vs self-hosted open-source models
  • Max input length: must fit your chunk size

Common mistakes

  • Mixing embeddings from different models in one index
  • Changing models without re-embedding existing documents
  • Chunks too long or too short for the model
  • Relying only on vectors when exact terms (codes, names) matter; hybrid search helps

Frequently asked questions

Are embeddings the same as tokens?

No. Tokens are pieces of text; embeddings are vectors representing meaning. Inside a transformer, tokens are first converted into embeddings.

What is a word embedding?

An older approach (Word2Vec, GloVe) giving one vector per word. Modern sentence embeddings represent whole sentences or passages using context.

Do embeddings need a GPU?

Small models run fine on a CPU for modest volumes; GPUs help when embedding millions of chunks.

Is this asked in GenAI interviews?

Yes. See RAG interview questions.

Conclusion

Embeddings turn meaning into vectors so machines can compare ideas, not just words. Understand embeddings and cosine similarity, and you understand the retrieval engine behind semantic search and RAG.

Build embedding-powered RAG apps in our Generative AI App Developer course.

Learn with Mehul Prajapati in Borivali West

At Mehul Prajapati’s institute, you get 100% practical, hands-on training by industry experts with a minimum of 5+ years of experience, plus job-oriented programmes with placement support. Weekday and weekend batches are available, with multiple 2-hour slots between 8 am and 6 pm.

Address: 12th Floor, 1214, Gold Crest Business Centre, LT Rd, Above Westside Showroom, Borivali West, Mumbai, Maharashtra 400092
Call: +91 99301 12627 / +91 96645 45072

Visit the centre or call us to choose the right course and batch and to know the current fee structure.