- Python 94.8%
- HTML 4.5%
- Makefile 0.7%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .github/workflows | ||
| _configs | ||
| _core | ||
| _data | ||
| _imgs | ||
| tests | ||
| _.code-workspace | ||
| .gitignore | ||
| AGENTS.md | ||
| download_mteb_datasets.py | ||
| generate_evals.py | ||
| generate_queries.py | ||
| LICENSE | ||
| list_retrieval_datasets.py | ||
| Makefile | ||
| NOTES.md | ||
| pyproject.toml | ||
| README.md | ||
| uv.lock | ||
Hybrid Search Evaluation Tool
Compare embedding models for hybrid search (keyword search with BM25 plus vector search). The tool tests local Sentence Transformers models and OpenRouter API models on any MTEB 2.x retrieval dataset using Weaviate.
For each model and search blend (alpha), it measures search quality (MRR@K and
Hit Rate@K), document embedding speed, and approximate RAM usage.
Install
Install uv, clone the repository, and create the Python 3.12 environment from the repository root:
git clone https://github.com/machinelearningZH/hybrid-search-eval.git
cd hybrid-search-eval
uv sync --locked
ColBERT (embeddings.colbert) is currently disabled because its upstream
package (pylate) depends on versions with known security issues. Remove
embeddings.colbert from older config files to run the supported backends. See
NOTES.md for dependency details.
The Makefile provides common shortcuts (run make help to see all):
make sync
make eval
make eval-force CONFIG=_configs/config.yaml
make test ARGS="-q"
make check
make queries INPUT=my_documents.csv ARGS="--provider ollama --num-queries 5"
make download DATASET=mteb/scifact ARGS="--sample 100"
make check checks code formatting, linting, and tests in order, stopping on
the first failure. make format applies safe lint fixes and formats Python
files; run make lint to see any remaining issues. Pass extra command-line
options through ARGS.
Quick start
The repository includes a small example dataset in _data/mteb_user. Because
_configs/config.yaml defaults to
_data/mteb/NanoBEIR-de (not included in a fresh clone), point
data.mteb_data_dir to the example dataset first:
data:
mteb_data_dir: "./_data/mteb_user"
Then run:
uv run generate_evals.py
Outputs are saved to _results/. Embeddings and evaluation results are cached
in _cache_embeddings/ and _cache_evals/ so repeated runs stay fast.
A minimal config for the included dataset:
project_id: "my-evaluation"
data:
mteb_data_dir: "./_data/mteb_user"
embeddings:
huggingface:
all-minilm: sentence-transformers/all-MiniLM-L6-v2
e5-small:
model: intfloat/multilingual-e5-small
use_query_prefix: true
use_passage_prefix: true
device: "auto" # cpu, cuda, mps, or auto
search:
alpha: [0.5, 1.0] # 0.0 = keyword only (BM25), 1.0 = vector only
metrics:
mrr_k: [10]
hit_rate_k: [10]
include_bm25_baseline: true
model:
embedding_batch_size: 32
max_document_tokens: 512
output:
results_dir: "./_results"
visualization: {}
Use --config PATH to run with a different config file, and pass
--force-recompute if you want to ignore saved caches and recalculate
everything.
Prepare a dataset
Generate queries from your documents
generate_queries.py reads a CSV or Parquet file with a required text column
and an optional id column, and creates corpus.parquet, queries.parquet,
and qrels.parquet in MTEB format.
Using OpenRouter (add OPENROUTER_API_KEY to a .env file first):
uv run generate_queries.py my_documents.csv
uv run generate_queries.py corpus.parquet --num-queries 5 --output-dir _data/my_dataset
Using a local Ollama model:
ollama pull llama3.2:latest
uv run generate_queries.py my_documents.csv --provider ollama --model llama3.2:latest
--max-workers and --model override the config file. Use --ollama-url to
change the Ollama address (default: http://localhost:11434/v1).
To create a fresh set of queries from an existing MTEB dataset, pass
--mteb-input-dir (the first argument is ignored in this mode):
uv run generate_queries.py ignored --mteb-input-dir _data/mteb/scifact --num-queries 5 --output-dir _data/my_dataset
This validates all three existing Parquet files and replaces the files in the
output folder (default: _data/mteb_user) rather than appending to them.
Generated queries keep the original document order and use IDs like
<source ID>::query_0. A generation_summary.json file records whether the run
was complete, partial, or failed, along with requested vs. actual query
counts and any incomplete documents. Only a complete run exits with status 0;
partial runs save what succeeded and exit with status 1; if zero queries are
generated, existing Parquet files are left untouched and only the failed summary
is written. Raw LLM responses and generation parameters are not saved, so store
them separately if you need a full audit trail.
Download an MTEB dataset
uv run download_mteb_datasets.py mteb/scifact
uv run download_mteb_datasets.py mteb/scifact --sample 100 --seed 42
uv run download_mteb_datasets.py mteb/XMarket --language de --split test
Datasets are saved to _data/mteb/ by default along with a
dataset_manifest.json file recording the revision, language, split, and
sampling details. Pass --language or --split when a dataset has more than
one option. (Dataset names, languages, and splits depend on what is currently on
Hugging Face.)
--sample selects queries first using --seed and keeps all of their relevant
documents, so the final corpus may be slightly larger than the requested size.
Combine it with --query-sample N to cap the number of sampled queries first.
Use --revision to request a specific dataset version instead of main.
To browse available retrieval datasets:
uv run list_retrieval_datasets.py --benchmark "MTEB(eng, v2)"
uv run list_retrieval_datasets.py --benchmark "MTEB(de)" --format csv --out retrieval_datasets.csv
Required MTEB files
Point data.mteb_data_dir to a folder with these three files:
| File | Required columns |
|---|---|
corpus.parquet |
id, text (optional title) |
queries.parquet |
id, text |
qrels.parquet |
query-id, corpus-id (optional score, defaults to 1) |
All three tables must be nonempty. Document and query IDs must be unique once
converted to strings, all text values must be strings, every qrels row must
point to existing document and query IDs, and every query must have at least one
relevant document (score > 0). Scores must be finite numbers. Duplicate
query/document pairs in qrels are rejected — clean duplicates before running
an evaluation.
Models and search modes
Model IDs in the config and examples are starting points, not guarantees that every model will download or run in your environment. See NOTES.md for the current German and multilingual model choices, licenses, benchmark evidence, and Apple Silicon runtime checks.
- Local models (
embeddings.huggingface): List each model as a plain ID or a mapping withmodeland optional text settings:use_query_prefix/use_passage_prefix(prepends"query: "/"passage: ")use_query_prompt/use_passage_prompt(uses the model's built-in"query"/"passage"prompt)query_prompt_name/passage_prompt_name(uses a named prompt from the model config; overrides the boolean prompt flags)
- OpenRouter models (
embeddings.openrouter.models): RequireOPENROUTER_API_KEYin.env. Browse available models on OpenRouter. You can setconnect_timeout(default: 10s) andread_timeout(default: 120s) underembeddings.openrouter.settings. Incomplete or invalid API responses fail that model's evaluation.
Important
Document text is shortened to
model.max_document_tokens(default: 512cl100k_basetokens) before both BM25 indexing and embedding. Prefixes are added afterward, and models may shorten text further with their own tokenizer. Document titles and extra query columns are not used. Keyword search (BM25) searchestextonly, never document IDs.
Caution
Local Sentence Transformers models load with
trust_remote_code=Trueso custom model architectures can run. Review and trust every model repository before using it.
Outputs and how to read them
Runs with results save a CSV table, PNG charts for each metric, and an interactive HTML dashboard. Embedding runs also create an embedding-speed chart and a quality-vs-speed tradeoff chart (plus a memory chart when RAM usage is measured). The HTML dashboard embeds its data directly, escapes text safely, and loads Tailwind CSS from a CDN (so styling needs an internet connection).
- MRR@K (Mean Reciprocal Rank): How high the first relevant document appears in the top K results (1.0 if ranked first, 0.5 if second, 0 if missed), averaged across all queries.
- Hit Rate@K: Share of queries with at least one relevant document in the top K results.
- Latency: Document embedding time only. It leaves out model loading, query embedding, indexing, and search. For OpenRouter models, it includes network and API time. Cached runs reuse the originally recorded time.
- RAM increase (MB): Approximate extra process RAM measured after loading
the model and embedding documents. It is not true peak memory and does not
include GPU memory.
0means no net increase was seen;-means unavailable (BM25, API models, or cached embeddings without memory data). - Pareto stars (
★): Highlight the configurations with the best tradeoff between one quality metric and document embedding speed. Setvisualization.pareto_quality_metricto choose the metric; otherwise the tool picks the highest MRR cutoff, then the highest Hit Rate cutoff. Memory is not part of this check, and BM25 is left unmarked.
Keep these limits in mind when comparing models:
- Synthetic queries have limits: LLM-generated queries mainly test whether search can find the source document; they can miss other relevant documents and do not match real user searches.
- Binary relevance only: MRR and Hit Rate treat each document as relevant or not relevant; they do not measure graded relevance or total recall.
- Caching: Cache keys include dataset contents, text limits, model backend,
and search settings. Incompatible or older cache files are ignored and
recomputed without deleting them. Because unpinned Hugging Face models can
change under the same model ID, use
--force-recomputeafter upstream updates. - Exit behavior: Invalid configs or Weaviate startup errors stop the run with a nonzero exit code. Individual model failures are skipped (even if every model fails), so always check the console log and result rows.
Project structure
| Path | Purpose |
|---|---|
generate_evals.py |
Main evaluation pipeline |
generate_queries.py |
LLM query generator |
download_mteb_datasets.py |
MTEB dataset downloader and sampler |
list_retrieval_datasets.py |
Lists available MTEB retrieval datasets |
_configs/config.yaml |
Default configuration |
_core/utils.py |
Shared validation, caching, metrics, charts, and dashboard |
_core/dashboard_template.html |
HTML dashboard template |
_core/utils_prompts.py |
Prompts for query generation |
_data/ |
MTEB datasets and user data |
tests/ |
Offline unit tests |
Makefile |
Shortcuts for setup, runs, and checks |
NOTES.md |
Maintainer decisions, workarounds, and model selection notes |
Contributing
Feedback and contributions are welcome: email the team, open an issue, or submit a pull request. The project uses Ruff for linting and formatting.
License
This project is licensed under the MIT License. See LICENSE.
Disclaimer
This evaluation tool (the Software) evaluates user-defined open-source and closed-source embedding models (the Models). You are solely responsible for ensuring that your use of the Software as well as of the underlying Models complies with all applicable local, national and international laws and regulations. By using this Software, you acknowledge and agree (a) that it is your responsibility to assess which laws and regulations, in particular regarding the use of AI technologies, are applicable to your intended use and to comply therewith, and (b) that you will hold us harmless from any action, claims, liability or loss in respect of your use of the Software.
