liveBook · Manning

Vectorization

As explained in Designing AI Systems

An embedding model is an AI model that converts content into numerical vector representations capturing semantic or learned relationships.

Vectorization converts text into dense numerical vectors, or embeddings, that capture semantic relationships. In semantic search, it lets a query match relevant content even when the wording differs. section 5.1

Matching by meaning

A query about returning an opened laptop can be close in vector space to a passage about electronics returns and restocking fees, despite sharing few words. section 5.1

In an ingestion pipeline, documents are parsed and split into coherent chunks. An embedding model converts each chunk to a vector, which is stored with its text and metadata. At search time, the query is also embedded and compared with stored vectors; matching chunks return with source attribution, scores, and metadata. section 5.1

Embedding configuration belongs to the index. All its chunks must use the same model because vectors from different models occupy different spaces and cannot be meaningfully compared. Model and dimension settings are fixed when the index is created. Higher-dimensional vectors can capture more nuance, but increase storage and similarity-computation costs. section 5.2.2 section 5.3.6

Listing 5.1 Index configuration dataclass
@dataclass
class IndexConfig:
    name: str    #A
    embedding_model: str = 
➥"text-embedding-3-small"    #B
    embedding_dimensions: int = 1536    #B
    chunking_strategy: str = "fixed"    #C
    chunk_size: int = 512    #C
    chunk_overlap: int = 50    #C
    metadata_schema: Optional[Dict] = None    #D

The index configuration groups embedding model and dimensions with chunking and metadata settings. section 5.2.2

Generate embeddings through a model service rather than calling providers directly. The service can reuse provider abstraction, cost tracking, retries, and routing. Batch chunk texts before calling embed(), and embed queries using the index's model. section 5.3.6

Listing 5.12 Embedding generation through the Model Service
class EmbeddingGenerator:
    def __init__(self, model_client):    #A
        self.model_client = model_client
 
    def embed_chunks(
        self,
        chunks: List[Chunk],
        model: str = "text-embedding-3-small",
        batch_size: int = 100    #B
    ) -> List[List[float]]:
 
        all_embeddings = []
 
        for i in range(0, len(chunks), batch_size):
            batch = chunks[i:i + batch_size]
            texts = [chunk.text for chunk in batch]
 
            response = self.model_client.embed(    #C
                texts=texts,
                model=model
            )
            all_embeddings.extend(response.embeddings)
 
        return all_embeddings
 
    def embed_query(
        self, query: str, model: str
    ) -> List[float]:    #D
        response = self.model_client.embed(
            texts=[query],
            model=model
        )
        return response.embeddings[0]

The generator batches chunks and delegates embedding requests to a model client. section 5.3.6

Operate embedding configurations as index-level choices:

  • Select models suited to each collection, and restrict choices with an allowlist when cost or external data handling is a concern. section 5.2.1
  • To change models, create a new index, re-ingest documents, validate retrieval, and switch traffic. Keep the old index available for rollback. section 5.2.2
  • Use metadata filtering alongside similarity search when semantically similar documents serve different audiences. section 5.1

How Designing AI Systems covers it

How deep it goes
Explains index configuration, batching, dimensionality tradeoffs, service integration, and model migration without detailing model internals.
Examples
Illustrates semantic matching with an opened-laptop return query and a passage about electronics restocking fees.
What you can do after
Operate/configure index-level embedding selection, batch generation, and migration to a new model.
How it connects
Connects embeddings to chunking, vector databases, similarity search, metadata filtering, and provider abstraction.

Also explained in

Compare how 22 books explain vectorization →

Related concepts

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