Skip to main content

Baguetter

Baguetter is a flexible, efficient, and hackable search engine library implemented in Python. It's designed for quickly benchmarking, implementing, and testing new search methods. Baguetter supports sparse (traditional), dense (semantic), and hybrid retrieval methods.

Note: Baguetter is not built for production use-cases or scale. For such use-cases, please check out other search engine projects.

Paper: https://arxiv.org/abs/2408.06643

Features

  • Sparse retrieval using BM25 and BMX algorithms
  • Dense retrieval using embeddings
  • Hybrid retrieval combining sparse and dense methods
  • Customizable text preprocessing pipeline
  • Multi-threaded indexing and searching
  • Evaluation tools for benchmarking
  • Easy integration with HuggingFace datasets and models for sharing
  • Hackable interface to quickly implement new methods

Installation

pip install baguetter

Quick Start

from baguetter.indices import BMXSparseIndex

# Create an index
idx = BMXSparseIndex()

# Add documents
docs = [
  "We all love baguette and cheese",
  "Baguette is a great bread",
  "Cheese is a great source of protein",
  "Baguette is a great source of carbs",
]
doc_ids = ["1", "2", "3", "4"]

idx.add_many(doc_ids, docs, show_progress=True)

# Search
results = idx.search("quick fox")
print(results)

# Search many
results = idx.search_many(["quick fox", "baguette is great"])
print(results)

Evaluation

Baguetter includes tools for evaluating search performance on standard benchmarks:

from baguetter.evaluation import datasets, evaluate_retrievers
from baguetter.indices import BM25SparseIndex, BMXSparseIndex

results = evaluate_retrievers(datasets.mteb_datasets_small, {"bm25": BM25SparseIndex, "bmx": BMXSparseIndex})
results.save("eval_results")

Documentation

For more detailed usage instructions and API documentation, please refer to the full documentation.

Contributing

Contributions are welcome! We are using the GitHub Pull Request workflow. Either open an issue first and create a PR or include a comprehensive commit message when opening a PR.

To get started, please create a clone of the repo (or a fork). We recommend working in a virtual environment.

python -m pip install -e ".[dev]"

pre-commit install

To test your changes, run:

pytest

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Acknowledgements

Baguetter builds upon the work of several open-source projects:

  1. retriv by AmenRa: Baguetter is a fork of retriv, adjusting it to our needs.

  2. bm25s by xhluca: Our BM25 implementation is based on this project, which provides an efficient and effective implementation of the BM25 algorithm with different scoring functions.

  3. USearch by unum-cloud for dense retrival.

  4. ranx by AmenRa for evaluation.

Please check out the respective repositories and show some appreciation to the authors.

Citing

@article{li2024bmx,
      title={BMX: Entropy-weighted Similarity and Semantic-enhanced Lexical Search},
      author={Xianming Li and Julius Lipp and Aamir Shakir and Rui Huang and Jing Li},
      year={2024},
      eprint={2408.06643},
      archivePrefix={arXiv},
      primaryClass={cs.IR},
      url={https://arxiv.org/abs/2408.06643},
}

Metadata

Release files for baguetter 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for baguetter 0.1.1
File Size Uploaded
baguetter-0.1.1.tar.gz 55.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for baguetter 0.1.1
File Interpreter ABI Platform
baguetter-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 128.5 kB

Release files / baguetter-0.1.1.tar.gz

Download URL baguetter-0.1.1.tar.gz
Size 55.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9639f6e4f1e840185f55bd7b9313116cfc09a2995dd8473b1c98bb2be47a2660
BLAKE2b-256 checksum
How to use checksums
2ec8d2ab877ef2b88abe53c664e19a10821f1103eca2a16b4d40c41cc6f00852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Release files / baguetter-0.1.1-py3-none-any.whl

Download URL baguetter-0.1.1-py3-none-any.whl
Size 72.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33f6a8b891571c79efd2e153aa3fc20f67e341d3ec9375954315fd9acc4fd901
BLAKE2b-256 checksum
How to use checksums
559e27b3f8c9b686351a6558986628b5f6cd352cc125af771a5bde5804d4bf22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page