liveBook · Manning

Embedding

As explained in Building Reliable AI Systems

An embedding is a numerical representation of content that captures semantic meaning in a form suitable for comparison.

A policy assistant can have the right documents and still fail to answer a coverage question if retrieval misses the relevant passage. Embeddings help retrieval find content by meaning rather than exact wording, but a poor embedding model can surface irrelevant context or no context at all. section 4.0 section 4.2

An embedding is a vector of numbers representing text as a point in a high-dimensional space, often with 384 or 768 dimensions. A useful model places semantically similar text near each other. Cosine similarity compares vector directions; dot product also takes magnitude into account. section 4.1

Matching different wording

A question about paid adoption leave can be close in embedding space to a policy granting paid parental leave for adoption or foster care. The match depends on the model capturing the relationship despite the different wording. section 4.2

In a retrieval-augmented generation pipeline:

  • Load documents, split them into chunks, embed each chunk, and store the resulting vectors for search. section 3.4
  • Embed the user’s query in the same vector space and compare it with document vectors to retrieve close matches as context. section 4.0
  • Preserve metadata with chunks so results can be filtered by fields such as effective date or policy status. section 4.5.4
from sentence_transformers import SentenceTransformer
import numpy as np

model = SentenceTransformer('pritamdeka/S-PubMedBert-MS-MARCO')    #1

chunk_texts = [chunk['content'] for chunk in all_chunks]    #2

embeddings = model.encode(chunk_texts, show_progress_bar=True)    #3

print(f"Generated embeddings with shape: {embeddings.shape}")

This Python listing encodes health-care policy chunks with a model pretrained on medical literature. section 4.5.4

Choose an embedding model for the domain and retrieval constraints. Generic models can miss specialized vocabulary; in-domain question-document pairs or synthetic questions can support fine-tuning. As new document types are added, embeddings may need retraining. For a vector database, the index dimension must match the model’s output dimension, and the similarity metric must be configured. section 3.7.1 section 4.5.4

How Building Reliable AI Systems covers it

How deep it goes
Explains vector-space similarity and indexing, then demonstrates model encoding and vector database configuration.
Examples
Illustrates semantic matching with adoption leave and a health-care policy assistant.
What you can do after
Apply embeddings via Sentence Transformers and Pinecone to encode and search policy chunks.
How it connects
Connects embeddings to semantic search, vector databases, retrieval-augmented generation, and fine-tuning.

Also explained in

Compare how 51 books explain embedding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.