liveBook · Manning

Embedding wrapper

As explained in Machine Learning Platform Engineering

An embedding wrapper is an adapter that presents a stable application interface around an embedding provider's API.

An embedding wrapper is an adapter that gives an application a stable interface around an embedding provider. It isolates Google API dependencies, supports provider changes, and centralizes retrieval-specific behavior. section 12.2.4

A production-oriented wrapper handles the embedding workflow by:

  • Initializing the provider client through the SDK. section 12.2.4
  • Embedding document collections through a unified method with progress feedback and per-document processing. section 12.2.4
  • Distinguishing document embeddings used for indexing from query embeddings used for search. section 12.2.4
Listing 12.3 Embedding API wrapper for document indexing and queries
class GeminiEmbeddings(Embeddings):    
    def __init__(self):
        self.client = genai.Client()  #1

    def embed_documents(self, 
                        texts: List[str]) 
                        -> List[List[float]]:  #2
        embeddings = []
        for text in tqdm(texts, desc="Embedding documents"):
            result = self.client.models.embed_content(
                model="text-embedding-004",  #3
                contents=text,
                config=types.EmbedContentConfig(
                    task_type="RETRIEVAL_DOCUMENT"  #4
                )
            )
            embeddings.append(
                result.embeddings[0].values)  #5

        return embeddings 

    def embed_query(self, text: str) -> List[float]:
        result = self.client.models.embed_content(
            model="text-embedding-004",
            contents=text,
            config=types.EmbedContentConfig(
                task_type="RETRIEVAL_QUERY"  #6
            )
        )
        return result.embeddings[0].values

Inspect the GeminiEmbeddings implementation, including the provider client, embedding model, document retrieval task, and returned vector values. section 12.2.4

Embedding documents for a FAISS index

A retrieval pipeline loads Markdown files, splits them into overlapping chunks, creates a FAISS index with GeminiEmbeddings, persists it, and tests similarity search with a user query.

How Machine Learning Platform Engineering covers it

How deep it goes
Explains the adapter’s client initialization, document processing, task selection, and vector return path, but not provider switching implementation.
Examples
Uses GeminiEmbeddings with Markdown loading, overlapping chunking, FAISS persistence, and a similarity-search test query.
What it assumes
Assumes familiarity with retrieval pipelines and vector indexes while demonstrating the provider wrapper’s core interface from initialization onward.
What you can do after
Build it from scratch as a provider-backed embedding component for document indexing and query retrieval.
How it connects
Connects embedding models with semantic search, vector databases, FAISS, document indexing, query processing, and RAG systems.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.