Vector Embeddings
Dense numerical representations of meaning that enable similarity-based retrieval, powering semantic search and hybrid RAG pipelines.
1 / Representing Meaning as Numbers
Vector embeddings convert text — words, sentences, or entire documents — into dense numerical vectors in a high-dimensional space. The key property: texts with similar meaning produce vectors that are close together, measured by cosine similarity or Euclidean distance. This mathematical representation of semantic similarity is what makes Semantic Search possible.
2 / Embedding Generation
In Phoenix and StudyLink, I used SentenceTransformers (all-MiniLM-L6-v2) to generate embeddings for documents and queries. The model produces 384-dimensional vectors that capture semantic meaning. Documents were embedded at ingestion time and stored in pgvector columns within PostgreSQL. Queries were embedded at search time for similarity comparison.
3 / Storage and Indexing
Raw vector similarity search — computing cosine distance against every stored vector — scales linearly with dataset size. HNSW (Hierarchical Navigable Small World) indexes on pgvector columns provided approximate nearest neighbor search that traded perfect recall for dramatically faster query execution. For the dataset sizes in my projects, HNSW recall was sufficiently high that the approximation did not measurably affect retrieval quality.
4 / Limitations
Embedding models compress meaning into fixed-dimensional vectors, which inherently loses information. Specific technical terms, version numbers, and domain-specific identifiers may not be accurately represented in the embedding space. This compression loss is why Hybrid RAG pairs vector search with BM25 keyword matching — the lexical strategy captures what the embedding model loses.
5 / Model Choice
The choice of embedding model directly affects retrieval quality. all-MiniLM-L6-v2 was a pragmatic choice: it produces good-quality embeddings with low computational overhead, fast inference, and a small model size suitable for local deployment. Larger models like OpenAI's text-embedding-ada-002 or Google's text-embedding-004 produce higher-quality embeddings but require API calls and per-token costs.
