# What are embeddings? Vectors, storage and models, with code

URL: https://sdclabs.com/glossary/embeddings/

> Embeddings turn text into vectors that capture meaning. How they work in search and RAG, what dimensions and int8 or binary storage cost, with runnable code.

# What are embeddings?

[Mikhail Bodnarchuk](https://sdclabs.com/author/bodnarchuk/) 2026-11-30

Definition

Embeddings are fixed-length lists of numbers that a machine learning model produces to represent the meaning of text, images or other data. Similar meanings get nearby vectors, so software can compare them with simple math: search finds passages close to a question, RAG passes them to a language model, and clustering groups related items.

## What does an embedding look like?

An embedding is a fixed-length list of numbers. The small open model we use below, BAAI's bge-small-en-v1.5, returns 384 of them for any input text, whether it is a word or a paragraph. Each number on its own means nothing. What matters is where the whole vector sits relative to other vectors from the same model: texts with similar meaning end up close together.

Cohere's documentation describes embeddings as "a way to represent the meaning of texts, images, or information as a list of numbers", compared with "a simple comparison function" to get a similarity score ([Cohere](https://docs.cohere.com/docs/embeddings) ). It names semantic search, clustering and classification as common uses.

Three properties decide most engineering choices:

| Property | What it means | Why it matters |
|---|---|---|
| Dimensions | How many numbers per vector | Storage, memory and search speed grow with it |
| Number type | 32-bit float, 16-bit float, 8-bit integer or 1 bit per number | A smaller type shrinks storage, at some cost in ranking quality |
| Model | Which model produced the vector | Vectors from different models cannot be compared |

Some models let you choose the dimension count. Cohere's embed-v5.0-pro supports Matryoshka embeddings, so one model can return 256, 512, 768, 1,024, 1,536 or 2,048 numbers through its output_dimension parameter, and its embedding_types parameter returns float, int8, uint8, binary or ubinary values. Cohere notes that binary vectors come packed as bytes, so 1,024 binary dimensions arrive as 128 bytes.

## How are embeddings used in search and RAG?

Passages are embedded once at index time, the question is embedded at query time with the same model, and the nearest passages become the context for an answer.

Some models expect a hint about which side a text is on. Cohere asks for input_type="search_query" on questions and input_type="search_document" on the passages being searched, plus classification or clustering for those tasks. The ranking mechanics are covered under [semantic search](https://sdclabs.com/glossary/semantic-search/) ; this page is about the vectors themselves.

## Example: real embeddings, compressed and compared

This script embeds four help articles and one question with two small open models, running locally through the fastembed library (0.9.1, ONNX on CPU, no API key). It then shrinks the vectors to 8-bit and 1-bit versions and compares the rankings.

# Real embeddings from two small open models (run locally through fastembed, ONNX on CPU). import numpy as np from fastembed import TextEmbedding docs = [ "Refunds are paid to the original card within 5 business days.", "Parcels that have not arrived after 10 days can be reported as lost.", "To change your password, open Settings and choose Security.", "Gift cards cannot be exchanged for cash.", ] query = "how long until I get my money back" def unit(v): v = np.asarray(v, dtype=np.float32) return v / np.linalg.norm(v, axis=-1, keepdims=True) bge = TextEmbedding("BAAI/bge-small-en-v1.5", cache_dir="models") D = unit(list(bge.embed(docs))) q = unit(list(bge.embed([query])))[0] print("dimensions:", D.shape[1], "| bytes per vector as float32:", D[0].nbytes) scores = D @ q for i in np.argsort(-scores): print(f" doc {i} {scores[i]:.3f} {docs[i]}") # Compression: int8 (1 byte per number) and binary (1 bit per number). scale = np.abs(D).max() D8, q8 = np.round(D / scale * 127).astype(np.int8), np.round(q / scale * 127).astype(np.int8) Db, qb = np.packbits(D > 0, axis=1), np.packbits(q > 0) int8_scores = D8.astype(np.int32) @ q8.astype(np.int32) hamming = np.array([np.unpackbits(d ^ qb).sum() for d in Db]) print("float32 ranking:", np.argsort(-scores).tolist(), f"({D[0].nbytes} bytes)") print("int8 ranking: ", np.argsort(-int8_scores).tolist(), f"({D8[0].nbytes} bytes)") print("binary ranking: ", np.argsort(hamming).tolist(), f"({Db[0].nbytes} bytes)") # Same text, same dimension count, different model: the numbers do not line up. mini = TextEmbedding("sentence-transformers/all-MiniLM-L6-v2", cache_dir="models") m0 = unit(list(mini.embed([docs[0]])))[0] print("other model dimensions:", m0.shape[0]) print(f"cosine(bge(doc0), minilm(doc0)) = {float(D[0] @ m0):.3f}")
We ran it with Python 3.11 and numpy 2.4.6. The first run downloads both models from Hugging Face (fastembed uses Qdrant's ONNX exports of them). Output:

dimensions: 384 | bytes per vector as float32: 1536 doc 0 0.739 Refunds are paid to the original card within 5 business days. doc 1 0.621 Parcels that have not arrived after 10 days can be reported as lost. doc 3 0.610 Gift cards cannot be exchanged for cash. doc 2 0.442 To change your password, open Settings and choose Security. float32 ranking: [0, 1, 3, 2] (1536 bytes) int8 ranking: [0, 1, 3, 2] (384 bytes) binary ranking: [0, 3, 1, 2] (48 bytes) other model dimensions: 384 cosine(bge(doc0), minilm(doc0)) = 0.324
What the run shows:

- **The right answer wins without shared words.** "Money back" matched "Refunds are paid" at 0.739.
- **A score is not a probability.** The password article has nothing to do with refunds and still scores 0.442. The model card for this model family (last updated February 2024, an older source) says it directly: "what matters is the relative order of the scores, not the absolute value" ([BAAI model card](https://huggingface.co/BAAI/bge-small-en-v1.5) ). If you need a cut-off, pick it from the score distribution on your own data.
- **int8 kept the order at a quarter of the size.** Binary kept the top result at 1/32 of the size, but swapped second and third place.
- **Same size, different space.** Both models return 384 numbers, yet the same sentence embedded by each scores only 0.324 against itself. Mixing models in one index gives rankings that look valid and are not.

## How much storage do embeddings need?

In PostgreSQL with [pgvector](https://github.com/pgvector/pgvector) , each vector takes 4 * dimensions + 8 bytes and each halfvec takes 2 * dimensions + 8 bytes, per the README. For a million passages at 1,024 dimensions, that works out to roughly 4.1 GB as vector and 2.1 GB as halfvec, before any index.

pgvector also stores bit vectors and has a binary_quantize function, with a two-step pattern in its README: find candidates by Hamming distance on the bits, then re-rank those candidates by the original vectors "for better recall". That pattern fixes exactly the swap our binary ranking made. For sparse vectors, where most values are zero, it has a sparsevec type: up to 16,000 non-zero elements per vector, and up to 1,000 in an HNSW index.

## What should you check before choosing an embedding model?

1. **Your own retrieval test.** Real questions with known correct passages, scored on every candidate model. Public benchmarks are measured on other people's data.
1. **Languages and content types.** A model trained on English prose may do poorly on code, tables or other languages.
1. **Query and document modes.** If the model has input types or query prefixes, use them consistently on both sides.
1. **Dimensions and compression.** Check which sizes and number types the model and your database support before you size the index.
1. **Input length.** Text past the model's limit is cut off or rejected, so chunk size follows the model.
1. **A re-embedding plan.** A model change means embedding every document again. Store the model name and version with each vector, and keep the old index until the new one passes your test.

Embeddings are also a part of a search index that can go stale. In our [AI-ready data engine](https://sdclabs.com/services/ai-ready-data-engine/) work, we build incremental sync from source to vector index, with deletes and updates handled, and monitor freshness. When an agent decides what to retrieve and when, see [agentic RAG](https://sdclabs.com/glossary/agentic-rag/) .

## Sources

1. [Introduction to Embeddings at Cohere](https://docs.cohere.com/docs/embeddings) , Cohere Documentation, 2026-09-29
1. [pgvector](https://github.com/pgvector/pgvector) , pgvector (GitHub README), 2026-11-18
1. [FlagEmbedding](https://huggingface.co/BAAI/bge-small-en-v1.5) , Hugging Face, BAAI/bge-small-en-v1.5 model card, 2024-02-22

## Frequently asked questions

### What is the difference between an embedding and a vector?

A vector is any list of numbers. An embedding is a vector produced by a model so that its position encodes meaning, which is why the same text always needs the same model.

### Are embeddings the same as tokens?

No. Tokens are the pieces a model splits text into before reading it. A typical text embedding model reads those tokens and returns one vector for the whole input.

### Can I use embeddings from different models in one index?

No. Each model places texts in its own space, so scores between vectors from two models are meaningless even when the dimension counts match. Re-embed everything when you switch.

### Do embeddings contain the original text?

Not as readable text, but treat them as derived from it. Store them with the same access rules as the source documents, and delete them when the source is deleted.

Services

- [AI Ready Data Engine](https://sdclabs.com/services/ai-ready-data-engine/)
- [Generative AI](https://sdclabs.com/services/generative-ai/)

Read next

- [88% call their data AI-ready, and 43% call it their biggest obstacle](https://sdclabs.com/blog/ai-ready-data/)
- [Generative AI fails after the demo, not before it](https://sdclabs.com/blog/generative-ai-production/)

Related terms

- [Semantic search](https://sdclabs.com/glossary/semantic-search/)
- [Hybrid search](https://sdclabs.com/glossary/hybrid-search/)
- [Agentic RAG](https://sdclabs.com/glossary/agentic-rag/)
- [Context window](https://sdclabs.com/glossary/context-window/)

[Mikhail Bodnarchuk](https://sdclabs.com/author/bodnarchuk/) Founder of Codeception and CodeceptJSBoth are open-source testing frameworks: Codeception for PHP, CodeceptJS for JavaScript.[LinkedIn](https://www.linkedin.com/in/davert/) [GitHub](https://github.com/DavertMik)

## Building with AI agents? Talk to an engineer.

[Start a project](https://sdclabs.com/contact/) [Book a call with the CEO](https://calendly.com/sdclabs/60min)
