Béranger THOMAS

ForzaEmbed

Python benchmarking framework for text embedding models: grid search over chunking strategies and similarity metrics, with textual heatmap and embedding space visualizations.

Technical sheet
Status Stable Release date 2025-07-23 Category NLP & RAG Language Python Stack FastEmbed · sentence-transformers · t-SNE · SQLite License MIT

Context

In Retrieval-Augmented Generation (RAG) pipelines, semantic filtering quality depends on multiple interdependent levers: text chunking strategy, embedding model, etc. Performance varies with document language, segment size, overlap rate, and the chosen similarity metric. The absence of systematic evaluation tools often leads to empirical architectural choices with no guarantee that the selected configuration is optimal. ForzaEmbed originated from this gap – it is a derived project from SmartWatch, where optimizing the semantic filter required building a dedicated evaluation framework.

Challenge

The objective was to design an automated tool capable of exhaustively exploring the hyperparameter space of embedding configurations and rendering results in a visually interpretable form. The expected deliverable was an open-source Python framework paired with an interactive HTML rendering engine, producing self-contained reports usable both by data scientists in R&D phases and by project teams needing to justify technical decisions.

Approach

The framework is structured as a Python CLI package organized in three main components:

  1. Grid Search Space Generation: From a YAML configuration file, the tool computes the Cartesian product of all declared hyperparameters: embedding backends (sentence-transformers, FastEmbed, OpenAI, Mistral), chunking strategies (LangChain, raw, semchunk, NLTK, spaCy), segment sizes (up to 7 steps, from 10 to 1000 characters), overlap rates (0 to 200), similarity metrics (cosine, Euclidean, Manhattan, dot product, Chebyshev), and thematic keyword lists. Invalid combinations (e.g., overlap larger than chunk size) are automatically excluded.

  2. Parallelized Execution with Persistent Cache: For each valid combination, the source text is segmented and embeddings are computed using the FastEmbed library – which natively supports multi-CPU/multi-GPU execution – complemented by a HuggingFace client for additional models. A local SQLite database acts as a persistent cache: each chunk is hashed and its vector stored, preventing redundant recomputation when varying external parameters (metric for instance). Segments are then evaluated for similarity against user-defined themes. With 7 chunk sizes × 7 overlaps × 5 strategies × 5 metrics × 3 themes × 8 models (≈21,000 combinations), this cache avoids massive recomputation.

  3. Self-contained Rendering Engine: Results are compiled into a single HTML file. A floating, semi-transparent control bar lets users adjust hyperparameter sliders in real time. The report includes:

    • An interactive textual heatmap: text is displayed as readable chunks, each colored by similarity (red = high, blue = low), with normalized scores (0–1) shown on hover.
    • 2D embedding space projections via t-SNE, UMAP or PCA, with chunk separation into two clusters based on a thematic threshold.
    • Intra- and inter-cluster silhouette scores and execution time for each grid combination.

Features

Exploitation for the SmartWatch Project

ForzaEmbed was used to optimize the semantic filter of SmartWatch, an automated monitoring application for public facility opening hours. Several analyses were conducted:

Outcome

ForzaEmbed provides RAG engineers with a quantitative tool to structure their R&D phases: