v1.0.0

4. Embeddings and vector search

Updated 30 Nov 2026Edit this page

How text becomes vectors that capture meaning, how similarity is measured, and how vector databases search millions of vectors fast with approximate nearest neighbour indexes like HNSW.

Embeddings

An embedding is a list of numbers (a vector) that represents the meaning of a piece of text. An embedding model maps text to vectors so that texts with similar meaning end up close together, even with no words in common:

  • How many vacation days do I get?
  • Annual leave entitlement per employee

These share almost no words but get nearby vectors, which is why vector search finds them and keyword search might not.

Embedding vectors have a fixed number of dimensions (384 for BAAI/bge-small-en-v1.5, 768–3072 for larger models). More dimensions can capture more nuance but cost more storage and compute. Embedding models are much smaller and cheaper than chat models; many run well on a laptop CPU.

Embeddings also power clustering, deduplication, recommendation, classification and semantic chunking (finding where a document’s topic changes).

Measuring similarity

Measure Formula (intuition) Notes
Cosine similarity cos θ = (a · b) / (‖a‖ ‖b‖): the angle between vectors −1 to 1; higher = more similar. The default for text.
Dot product a · b Equals cosine when vectors are normalised to length 1.
Euclidean distance ‖a − b‖ Lower = more similar.

AgenticMind normalises scores across all 12 vector stores to “cosine similarity (or dot product), higher = more similar”, so a threshold means the same thing everywhere.

  1. Index time: embed every chunk of your documents and store the vectors with the text and metadata.
  2. Query time: embed the question with the same model, find the stored vectors with the highest similarity (the k nearest neighbours), return their chunks.

Using a different model at query time produces vectors in a different space; the similarities are meaningless. That is why AgenticMind shares one Embedding Model handle between indexing and querying, records the model identity with every vector, and refuses mismatches.

Vector databases

A vector database stores vectors and finds nearest neighbours fast. Checking every vector (exact or brute-force search) is fine for thousands of chunks and too slow for millions. Production stores use approximate nearest neighbour (ANN) indexes that trade a tiny bit of recall for huge speedups:

  • HNSW (Hierarchical Navigable Small World; Malkov and Yashunin, 2016): a multi-layer graph where each vector links to its neighbours; search greedily walks from coarse layers to fine ones. The most popular index (Qdrant, Weaviate, Redis, pgvector, Elasticsearch, OpenSearch…).
  • IVF (inverted file): cluster vectors, search only the nearest clusters.
  • Product quantisation: compress vectors to save memory.

Vector databases also store metadata (filename, page, section, language, tenant) and support filters, so you can search only within one document, one customer or one language.

Embedded vs server

  • Embedded (Qdrant local mode, Chroma, FAISS, LanceDB): runs inside your process with data on disk. Zero setup, ideal for development and single machines, but needs a persistent disk wherever you deploy.
  • Server or cloud (Qdrant Cloud, Pinecone, Weaviate, Milvus/Zilliz, Elasticsearch, OpenSearch, MongoDB Atlas, Redis, pgvector): shared, scalable, managed.
  • Exact terms: product codes, names, error IDs and rare words are often better matched by keyword search (BM25). Hybrid search combines both (chapter 6).
  • Similar is not relevant: the nearest chunk may be on-topic but not answer the question. Reranking helps.
  • Chunking quality caps retrieval quality: a fact split across two chunks may match neither well.
  • Domain shift: general embedding models may struggle with highly specialised jargon; a domain-tuned model or hybrid search helps.

Try it in AgenticMind

  • Embedding Model: local fastembed (BAAI/bge-small-en-v1.5, no key) or any OpenAI-compatible embeddings API.
  • Vector Store: 12 backends; Qdrant embedded by default. See Embeddings and vector stores.
  • Index Documents → Retriever: template RAG retrieval; run Run → Results to see chunks with similarity scores.
  • The Chunker’s semantic strategy uses embeddings to split documents where the topic changes.

Key takeaways

Embeddings turn meaning into vectors; similar meanings are close. Cosine similarity measures closeness. Always query with the same model you indexed with. Vector databases use approximate indexes such as HNSW to search fast, and metadata filters to search narrowly. Vector search misses exact terms, so pair it with keyword search.