embedding model vector
**Embedding Models and Dense Retrieval** are the **neural network systems that encode text (sentences, paragraphs, documents) into fixed-dimensional vector representations where semantic similarity corresponds to geometric proximity — enabling fast similarity search over millions of documents through vector databases, powering RAG (Retrieval-Augmented Generation), semantic search, recommendation systems, and any application requiring meaning-based information retrieval**.
**From Sparse to Dense Retrieval**
- **Sparse Retrieval (BM25/TF-IDF)**: Represents documents as sparse vectors of term frequencies. Matching is lexical — the query and document must share exact words. "car accident" does not match "vehicle collision".
- **Dense Retrieval**: Represents documents as dense vectors (768-4096 dimensions) learned by neural networks. Matching is semantic — "car accident" is geometrically close to "vehicle collision" in embedding space. Captures synonymy, paraphrase, and conceptual similarity.
**Embedding Model Architectures**
- **Bi-Encoder**: Two independent encoders (or one shared encoder) separately encode the query and document into vectors. Similarity is computed as cosine similarity or dot product between vectors. Documents can be pre-computed and indexed offline — query-time computation is just encoding the query + ANN search. The standard for production retrieval.
- **Cross-Encoder**: Concatenates query and document as input to a single encoder, outputting a relevance score. More accurate (joint modeling of query-document interaction) but O(N) inference cost for N documents — impractical for first-stage retrieval. Used for re-ranking the top-K results from a bi-encoder.
**Training Methodology**
- **Contrastive Learning**: Given a query, the positive is the relevant document; negatives are irrelevant documents from the same batch (in-batch negatives) or mined from the corpus (hard negatives). InfoNCE loss trains the model to maximize similarity with positives and minimize with negatives.
- **Hard Negative Mining**: Easy negatives (random documents) provide little gradient signal. Hard negatives (documents that BM25 or a previous model version ranked highly but are not relevant) force the model to learn fine-grained distinctions.
- **Multi-Stage Training**: Pre-train on large weakly-supervised data (title-body pairs, query-click pairs), then fine-tune on task-specific labeled data. Sentence-BERT, E5, GTE, and BGE models follow this pattern.
**Production Deployment**
- **Vector Databases**: FAISS, Milvus, Pinecone, Weaviate, Qdrant store embeddings and support Approximate Nearest Neighbor (ANN) search: IVF (Inverted File Index), HNSW (Hierarchical Navigable Small World graphs), or PQ (Product Quantization). Sub-millisecond search over 100M+ vectors.
- **RAG Pipeline**: Query → embedding model → vector search (top-K chunks) → LLM generates answer conditioned on retrieved context. The architecture that gives LLMs access to current, private, and domain-specific knowledge without fine-tuning.
- **Quantization**: INT8 or binary quantization of embeddings reduces storage by 4-32x with <2% retrieval accuracy loss. Matryoshka embeddings train models where the first D dimensions (128, 256, 512 of 1024) form valid smaller embeddings, enabling adaptive dimension reduction.
Embedding Models are **the translation layer between human language and machine-searchable vector space** — the neural networks that make semantic understanding computationally tractable by converting meaning into geometry, enabling the retrieval systems that underpin modern AI applications.