sentence-transformers is a Python open-source library for producing dense vector representations of sentences, paragraphs, and images with encoder-only Transformer models. Similar texts occupy nearby positions in the resulting vector space, enabling semantic retrieval and similarity comparison. section 13.2 section 2.1.3
In retrieval-augmented generation, embed document chunks and user queries with the same model, then rank candidate passages using cosine similarity or another distance metric. The embeddings can be persisted for later retrieval. section 13.2 section 13.5
Operational choices shape retrieval quality and deployment cost:
- Choose an embedding model such as all-mpnet-base-v2, which maps text into a 768-dimensional vector space and is fine-tuned with contrastive learning. section 13.2
- Run encoding on CPU when hardware acceleration is unavailable, or use compatible GPU infrastructure when the surrounding search workflow requires it. section 13.2 section 2.1.3
- Pair generated vectors with a similarity index such as FAISS for efficient nearest-neighbor retrieval instead of brute-force comparison. section 2.1.3
Retrieve relevant document chunks
Load SentenceTransformer("all-mpnet-base-v2"), encode preprocessed sentence chunks, encode the query "blocked KV-cache", calculate cosine similarities, and select the top five results. A related classification workflow encodes superhero descriptions, normalizes vectors, and searches a FAISS L2 index for "He throws webs". section 13.2 section 2.1.3

