Read-only mirror of https://github.com/machinelearningZH/hybrid-search-eval — Zürich. Issues & pull requests at the source.
  • Python 94.8%
  • HTML 4.5%
  • Makefile 0.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-04 19:08:31 +01:00
.github/workflows chore(ci): update setup-uv and uv pins 2026-12-04 18:54:18 +01:00
_configs refactor: remove dead code and duplicate evaluation work 2026-12-04 18:44:50 +01:00
_core refactor: remove dead code and duplicate evaluation work 2026-12-04 18:44:50 +01:00
_data Initial commit 2026-01-08 16:47:38 +01:00
_imgs Add Snowflake model support with xformers workaround 2026-01-17 14:48:39 +01:00
tests test: strengthen behavioral coverage at application boundaries 2026-12-04 18:52:47 +01:00
_.code-workspace chore: update packages, add ruff to dev group 2026-10-01 14:43:25 +02:00
.gitignore chore: update ignores 2026-11-28 08:12:11 +01:00
AGENTS.md chore: update packages, AGENTS.md 2026-10-31 11:13:16 +01:00
download_mteb_datasets.py refactor: remove dead code and duplicate evaluation work 2026-12-04 18:44:50 +01:00
generate_evals.py refactor: remove dead code and duplicate evaluation work 2026-12-04 18:44:50 +01:00
generate_queries.py fix: resolve retrieval and generation reliability findings 2026-11-16 13:13:03 +01:00
LICENSE docs: restore README with badges and version info 2026-08-19 16:30:46 +02:00
list_retrieval_datasets.py refactor: remove dead code and duplicate evaluation work 2026-12-04 18:44:50 +01:00
Makefile fix: remove vulnerable PyLate dependencies and release v0.4.1 2026-11-16 14:51:27 +01:00
NOTES.md docs: align README and NOTES with codebase and trim stale work logs 2026-12-04 19:03:01 +01:00
pyproject.toml chore(release): bump version to 0.5.0 2026-12-04 19:08:31 +01:00
README.md chore(release): bump version to 0.5.0 2026-12-04 19:08:31 +01:00
uv.lock chore(release): bump version to 0.5.0 2026-12-04 19:08:31 +01:00

Hybrid Search Evaluation Tool

GitHub License Python GitHub Stars GitHub Issues GitHub Pull Requests Current Version linting - Ruff

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.

Example evaluation dashboard

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 with model and 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): Require OPENROUTER_API_KEY in .env. Browse available models on OpenRouter. You can set connect_timeout (default: 10s) and read_timeout (default: 120s) under embeddings.openrouter.settings. Incomplete or invalid API responses fail that model's evaluation.

Important

Document text is shortened to model.max_document_tokens (default: 512 cl100k_base tokens) 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) searches text only, never document IDs.

Caution

Local Sentence Transformers models load with trust_remote_code=True so 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. 0 means 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. Set visualization.pareto_quality_metric to 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-recompute after 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.