← All news

News / Learn / Embeddings & vector search

What are embeddings?

You'll be able to explain what an embedding is and use one to find text with similar meaning.

An embedding is a list of numbers that stands for the meaning of a piece of text, image, or other data. Texts with similar meanings get lists of numbers that sit close together. A computer can then compare meanings by comparing numbers, not by matching exact words.

Users rarely type the exact words that appear in your data. Embeddings let your product match a question like "how do I cancel?" with a help article titled "ending your subscription." They are the base of semantic search, retrieval for AI apps, recommendations, and clustering.

A model called an embedding model reads an input and outputs a fixed-length vector, often a few hundred to a few thousand numbers. The model learns during training to place related inputs near each other in this space. The exact size and training details differ between models, so treat each one as its own system.

To compare two inputs, you embed both and measure how close their vectors are. Cosine similarity is the most common measure. It compares the direction of two vectors and ignores their length. A score near 1 means very similar, and a score near 0 means unrelated.

You embed your documents once and store the vectors. At query time you embed the user's question and find the stored vectors nearest to it. This lookup is the core of semantic search and of retrieval for AI systems.

Embeddings are only as good as the model that made them and the text you feed it. Long passages can dilute meaning, so many systems split documents into smaller chunks before embedding.

Embed two sentences and compare them with cosine similarity. The function below is generic. Substitute any embedding provider's client.

import numpy as np

def cosine_similarity(a, b):
    a = np.asarray(a, dtype=float)
    b = np.asarray(b, dtype=float)
    return float(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)))

# vec_a = embed("How do I cancel my plan?")
# vec_b = embed("Ending your subscription")
# score = cosine_similarity(vec_a, vec_b)
# A higher score means the meanings are closer.

A short sketch to show the idea. Check the official docs of the tool you use.

  • Mixing embedding models Vectors from different models live in different spaces and cannot be compared. Use one model for both documents and queries, and re-embed everything if you switch.
  • Embedding whole documents at once Long inputs blur into a general topic. Split content into smaller, meaningful chunks and embed each one.
  • Assuming high scores mean a true match Similarity is a ranking signal, not proof. Set a threshold on your own test data and check results by hand.
  • Ignoring exact terms Embeddings can miss product codes, names, or rare words. Consider combining semantic search with keyword search.

Learn how chunking affects retrieval quality, how to build a small test set of queries with known answers, and how hybrid search combines keyword and vector results.

Is an embedding the same as a token?

No. A token is a small piece of text a language model reads or writes. An embedding is a vector of numbers that represents the meaning of an input as a whole.

Do I need a special database for embeddings?

Not always. For small collections you can store vectors in memory or in a regular database. Dedicated vector databases help when you have many vectors and need fast search.

Can embeddings work with images or audio?

Yes. Some models embed images, audio, or mixed content into the same kind of vector. Check that a model supports the data type you need.

Do embeddings store the original text?

No. An embedding is a numeric summary. You usually store the original text alongside the vector so you can show it to users.

Why do my similarity scores look different from another project's?

Each model produces its own score range and distribution. Set thresholds using your own data, not numbers from another system.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.