Explain Vector Embeddings

SUPRABHATSUPRABHAT
5 min read

When humans read a sentence, we instantly understand the meaning, context, and relationships between words. Computers, however, don’t “understand” language in the same way. They work with numbers, not words. This is where vector embeddings come in a way to represent text as numbers so that machines can process and compare meanings.

What Are Vector Embeddings?

A vector embedding is a way of turning text (or any other type of data) into a list of numbers called a vector. Each word, sentence, or even document can be converted into a vector. These numbers are arranged in such a way that they capture the semantic meaning, meaning that similar words or sentences end up having similar vectors.

For example:

  • The words "king" and "queen" will have vectors that are close to each other.

  • "king" - "man" + "woman" might result in a vector close to "queen".

Why Do We Need Embeddings?

Raw words in their original form can’t be directly understood by computers. If we used simple IDs (like cat = 1, dog = 2), the computer wouldn’t know that “cat” and “dog” are more related than “cat” and “banana.”
Embeddings solve this by:

  • Placing similar meanings closer together in vector space.

  • Allowing models to find patterns and relationships in text.

  • Making it possible to perform tasks like search, clustering, translation, and sentiment analysis effectively.

How Are Embeddings Created?

Embeddings are created by converting words, sentences, or other data into dense numerical vectors that capture their meaning in a way machines can understand. This process is done through training on large datasets, where the goal is to place similar meanings close together in a high-dimensional space.

1. Prepare the Data- Before creating embeddings, the text or data is cleaned and tokenized (split into smaller pieces like words, subwords, or characters). Each token is then assigned an initial numerical representation, often randomly at the start.

2. Training with Neural Networks - A neural network learns these vector values during training.

  • Word embeddings such as Word2Vec, GloVe, and FastText are created by training on very large collections of text. These models use patterns in the data for example, if “king” often appears near “queen” and “man” appears near “woman,” the network adjusts the vectors so that the relationships between these words are reflected in the geometry of the space.

For example:
Vector("king") - Vector("man") + Vector("woman") ≈ Vector("queen")

3. Contextual Embeddings- Modern models like GPT create contextual embeddings, meaning the vector for a word changes depending on the sentence. For instance, "bank" in “river bank” and "bank" in “money bank” will have different embeddings because the model understands the surrounding context.

4. Dimensionality and Representation- Each embedding is a list of numbers (e.g., 300, 512, or 1536 dimensions).

  • A dimension doesn’t correspond to a direct human concept like “color” or “size” instead, it’s a learned feature that collectively helps the model understand relationships.

  • These embeddings live in a vector space, where the distance between vectors indicates similarity in meaning.

5. Fine-Tuning for Specific Tasks- Once a base embedding model is trained, it can be fine-tuned for specific applications like sentiment analysis, search engines, or recommendation systems. The fine-tuning process slightly adjusts the vectors to better fit the new task while keeping the general meaning intact.

Note: You don’t need to do all of this, there are many embedding models available like

  1. OpenAI Embeddings

  2. Gemini Embeddings

How do we save the Vector Embeddings?

When you create vector embeddings, you usually need a way to store and search them efficiently, and that’s where vector databases come in.

What is a Vector Database?

A vector database is designed specifically to store high-dimensional vectors and quickly find the most similar ones.
Examples: Pinecone, Weaviate, Qdrant, Vespa.

These databases allow you to:

  • Store embeddings alongside metadata (e.g., original text, image ID, timestamp).

  • Search using similarity metrics (e.g., cosine similarity, dot product).

  • Scale to millions or billions of vectors while keeping search fast.

How It Works

  1. Store the Embeddings
    After generating embeddings (e.g., from OpenAI, etc.), each embedding is stored as a vector in the database, usually along with an ID and any extra information you want.

  2. Indexing for Speed
    The database creates special indexes (like HNSW graphs or IVF-Flat) that allow it to find similar vectors without comparing every single one, making searches much faster.

  3. Searching for Similarity
    When you search (e.g., "find articles similar to this one"), the query text is converted into an embedding, and the database finds the nearest vectors in its space using similarity metrics.

Why Not Just Use a Normal Database?

Traditional databases (like MySQL or MongoDB) are great for storing text or numbers but aren’t optimized for finding “which vectors are most similar” to a given one.

  • A vector embedding can have hundreds or thousands of dimensions.

  • Finding the closest match means doing a lot of mathematical comparisons (like cosine similarity or Euclidean distance) something normal databases don’t do efficiently.

Conclusion

Vector embeddings are the bridge between human language and computer understanding. They capture the meaning of words, sentences, and even larger text pieces in a mathematical form that allows algorithms to find patterns, similarities, and relationships. For beginners in natural language processing, understanding embeddings is a key step toward building smarter and more context-aware applications.

Want to learn more

here are some more articles related to AI

  1. How ChatGPT Understands you

  2. Tokenization for LLMs

  3. What is RAG

  4. Parallel Query Retrieval (Fan Out)

  5. Chain of Thought

  6. Step-Back Prompting

  7. Reciprocal Rank Fusion

  8. Hypothetical Document Embeddings

  9. How to Trace/Monitor an AI application

A bit about me

Hi there! I’m Suprabhat, a curious mind who loves learning how things work and explaining them in simple ways. As a kid, I was fascinated by the internet and all its secrets. Now, I enjoy writing guides like this to help others understand our digital world. Thanks for reading, and keep exploring!

  1. Linkedin

  2. X(Twitter)

  3. GitHub

  4. Peerlist

4
Subscribe to my newsletter

Read articles from SUPRABHAT directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

SUPRABHAT
SUPRABHAT

Ex. Structures Engineer | CSE 2nd year Student | Web. Dev. in JavaScript Environment | MERN STACK | AI Application developer | Python