Skip to main content

ltr-bert-sir-client

PyPI npm Docker Model Space GitHub License

Python client for the ELSIE semantic information retrieval API. The API is served by the sir-elsie Hugging Face Space and implements the hybrid retrieval stack associated with the ltr-bert-sir bi-encoder checkpoint: BM25 first stage, pool-restricted LTR-BERT scoring, optional cross-encoder reranking, and library management for long-text corpora.

Authors: Syed Minnatullah Quadri, Vrishali A. Chakkarwar
License: Apache-2.0

Related resources

  1. Bi-encoder weights, metrics, and offline LTRBertSIR inference at s-m-quadri/ltr-bert-sir on Hugging Face
  2. Interactive ELSIE demo and REST API at s-m-quadri/sir-elsie on Hugging Face Spaces
  3. JavaScript and TypeScript client at @s-m-quadri/ltr-bert-sir-client on npm
  4. Python client (this package) at ltr-bert-sir-client on PyPI
  5. TypeScript source at ltr-bert-sir-client-js on GitHub
  6. Python source at ltr-bert-sir-client-py on GitHub
  7. Self-hosted ELSIE API at smquadri/ltr-bert-sir-elsie on Docker Hub

Background

Long-document ad hoc retrieval on MS MARCO is typically staged: a lexical first stage (here BM25@100) defines a candidate pool; a bi-encoder scores only within that pool; scores are fused (linear blend with alpha = 0.85 by default) or passed to a cross-encoder on a short shortlist. The Hub model repository documents the fine-tuned LTR-BERT bi-encoder and offline scoring. This package targets the live HTTP API exposed by the ELSIE Space: search, collection ingest, seed libraries, qrels upload, batch evaluation, and library export.

Default base URL (DEFAULT_SIR_API_URL):

https://huggingface.co/spaces/s-m-quadri/sir-elsie

Pass a different origin to SirClient(...) when the FastAPI app runs locally, via Docker, or elsewhere.

Installation

pip install ltr-bert-sir-client

Requirements: Python 3.10 or newer. Depends on httpx for HTTP.

Configuration

from ltr_bert_sir_client import SirClient, DEFAULT_SIR_API_URL

sir = SirClient(DEFAULT_SIR_API_URL, timeout=120.0)

Use the context manager to close the underlying HTTP client:

with SirClient() as sir:
    print(sir.health())

Search modes

API mode UI label First stage Neural stage Notes
bm25 Fast BM25 none No embedding index required
blend Hybrid BM25@bm25_k LTR-BERT fusion Default; needs encoded collection
semantic Dense semantic pool LTR-BERT Semantic-first variant
ce_cascade Precise Hybrid pool LTR-BERT + MiniLM CE Reranks top ce_top_k
ce_only CE-only CE on pool MiniLM CE Cross-encoder without blend shortcut

Search bodies accept query, optional collection_id, mode, k, bm25_k, ce_top_k, and alpha. Responses include hits, ms, optional trace, and optional eval when qrels are loaded.

API overview

The SirClient class mirrors the Space REST surface (parity with the JavaScript client).

Area Methods
Health and defaults health(), ranking_config()
Collections list_collections(), get_collection(), create_collection(), import_collection(), delete_collection(), cancel_collection()
Ingest and index ingest_file(), ingest_url(), encode(), progress()
Search and documents search(), get_document()
Statistics stats(), clear_stats(), stats_export_url()
Seeds list_seeds(), get_seed(), load_seed(), index_seed(), seed_alice()
Qrels and evaluation qrels_status(), upload_qrels(), delete_qrels(), export_qrels(), annotate_qrels(), evaluate()
Library library_config(), set_library_config(), index_all(), library_status(), import_library(), export_library(), export_library_with_config(), library_export_url()
Binary export export_url(), export_collection(), download()

Additional modules:

Module Role
ltr_bert_sir_client.format bytes_fmt, mode_label, progress_label, and related display helpers
ltr_bert_sir_client.hints Tooltip strings aligned with ELSIE
ltr_bert_sir_client.collections dedupe_collections, duplicate_collections, collections_by_seed
ltr_bert_sir_client.ui write_demo(), theme_css() for a standalone HTML demo

Usage

from ltr_bert_sir_client import SirClient

with SirClient() as sir:
    health = sir.health()
    cols = sir.list_collections()
    cid = cols["collections"][0]["id"]
    result = sir.search(
        {
            "query": "alice rabbit hole curious dream",
            "collection_id": cid,
            "mode": "blend",
            "k": 10,
        }
    )
    for hit in result["hits"]:
        print(hit["title"], hit["score"])

Batch evaluation when qrels are present:

metrics = sir.evaluate(
    cid,
    mode="blend",
    k=100,
    bm25_k=100,
    ce_top_k=32,
)

Generate a minimal browser demo:

from ltr_bert_sir_client.ui import write_demo

write_demo("./demo", "https://huggingface.co/spaces/s-m-quadri/sir-elsie")

Citation

Bibliographies and publication details are on the ltr-bert-sir model card on Hugging Face. Cite MS MARCO when using bundled evaluation qrels or MS MARCO-derived training described there.

License

Apache-2.0. MS MARCO remains under Microsoft research terms when used through the API or bundled seeds.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ltr_bert_sir_client-0.2.3.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ltr_bert_sir_client-0.2.3-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file ltr_bert_sir_client-0.2.3.tar.gz.

File metadata

  • Download URL: ltr_bert_sir_client-0.2.3.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for ltr_bert_sir_client-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c5e4e154fdc71ea2ea444ad7b0702f02422d1c487260e378dfe7132855816639
MD5 b0e7e997e74ceb67a5e053c63a7e88b1
BLAKE2b-256 0ee6229fd22912a23cdb8c490f2ca0f597f1f7ef9dda75d71c25b8daccbbd8cc

See more details on using hashes here.

File details

Details for the file ltr_bert_sir_client-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ltr_bert_sir_client-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a818aa8ebd891b57644e13fcd0a2942e499bedcbc10e5d678ce69e79938b81eb
MD5 0257e2c7da28b125054a770418ac7c17
BLAKE2b-256 ebad17e3adf1369ec1c5ad1444e8f4cb7f68a65add2618a7b8e90165599a50ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page