AI Engineering6 min read

Embedding Engineer

Selects and deploys text embedding models - MTEB benchmarks, batching, caching, semantic search, clustering, and production embedding pipeline optimisation.

embeddingssemantic searchsentence transformerstext similarityMTEB

The Embedding Engineer selects the right embedding model, designs the embedding pipeline, and ensures production performance - batch sizing, caching, and refresh strategies. Embedding model selection matters: the difference between a poor and a good embedding model on your specific domain can be 10–20 percentage points in retrieval recall.

Model Selection (MTEB Benchmark)

ModelDimensionsMTEB avgCost per 1M tokensBest for
text-embedding-3-large307264.6$0.13Best quality, high-stakes retrieval
text-embedding-3-small153662.3$0.02Best cost/quality ratio (recommended)
nomic-embed-text-v1.576862.4Free (self-hosted)Privacy, offline, high volume
bge-large-en-v1.5102463.6Free (self-hosted)Best open-source English quality
multilingual-e5-large102458.8Free (self-hosted)Multilingual (100+ languages)

Production Embedding Pipeline

import OpenAI from 'openai';
import { createHash } from 'crypto';

const openai = new OpenAI();

class EmbeddingService {
  private cache = new Map<string, number[]>();

  // Cache by content hash - same text always gets same embedding
  private cacheKey(text: string): string {
    return createHash('sha256').update(text).digest('hex');
  }

  async embed(texts: string[]): Promise<number[][]> {
    const uncached: { index: number; text: string }[] = [];
    const results: number[][] = new Array(texts.length);

    // Check cache first
    texts.forEach((text, i) => {
      const key = this.cacheKey(text);
      if (this.cache.has(key)) {
        results[i] = this.cache.get(key)!;
      } else {
        uncached.push({ index: i, text });
      }
    });

    if (uncached.length > 0) {
      // Batch embed uncached texts - max 2048 inputs per API call
      const chunks = [];
      for (let i = 0; i < uncached.length; i += 100) {
        chunks.push(uncached.slice(i, i + 100));
      }

      for (const chunk of chunks) {
        const response = await openai.embeddings.create({
          model: 'text-embedding-3-small',
          input: chunk.map(c => c.text),
          dimensions: 1536,
        });

        response.data.forEach((item, j) => {
          const { index, text } = chunk[j];
          const key = this.cacheKey(text);
          this.cache.set(key, item.embedding);
          results[index] = item.embedding;
        });
      }
    }

    return results;
  }
}

Cosine Similarity Search

function cosineSimilarity(a: number[], b: number[]): number {
  let dot = 0, magA = 0, magB = 0;
  for (let i = 0; i < a.length; i++) {
    dot  += a[i] * b[i];
    magA += a[i] * a[i];
    magB += b[i] * b[i];
  }
  return dot / (Math.sqrt(magA) * Math.sqrt(magB));
}

// For production: store in pgvector or Pinecone - never do in-memory search on >100k vectors

Explore all agents

Browse the full library of specialized AI agents.