Skip to main content

Query-adaptive sparse/dense/KG reranker for RAG systems.

Project description

gardian-reranker

Query-adaptive sparse/dense/KG reranker for RAG systems.

Install

pip install .

After publishing to PyPI:

pip install gardian-reranker

What it returns

gardian-reranker returns:

  • query-level adaptive branch weights: sparse/dense/kg
  • ranked passages with final score
  • per-passage branch contributions for explainable routing into the reader

Python API

from gardian_reranker import GardianReranker, Candidate, QueryFeatures

reranker = GardianReranker.from_checkpoint("gardian_best.pt", {
    "sparse_dim": 3,
    "dense_dim": 4,
    "kg_dim": 6,
    "branch_hidden": 256,
    "controller_hidden": 256,
    "query_feat_dim": 1024,
    "n_qtypes": 7,
    "dropout": 0.2
})

query_features = QueryFeatures(
    query_emb=[0.0] * 1024,
    qtype_onehot=[0, 0, 0, 0, 0, 0, 1],
    kg_coverage=0.8
)

candidates = [
    Candidate(
        id="doc1",
        text="Passage text",
        sparse_feats=[0.1, 0.2, 0.3],
        dense_feats=[0.4, 0.5, 0.6, 0.7],
        kg_feats=[0.1, 0.2, 0.3, 0.1, 0.0, 0.4],
    )
]

result = reranker.rerank(query_features, candidates)
print(result["query_weights"])
print(result["ranked"][0]["contrib"])

CLI

gardian-rerank \
  --checkpoint results/gardian_best_hybrid.pt \
  --config config.json \
  --input input.json \
  --output output.json

PyPI release (maintainers)

  1. Replace placeholder repository URLs in pyproject.toml.
  2. Configure Trusted Publishing for your PyPI project.
  3. Bump version in pyproject.toml.
  4. Push a tag, e.g. v0.1.1:
git tag v0.1.1
git push origin v0.1.1

The GitHub Action .github/workflows/publish-pypi.yml will build and publish automatically.

Project details


Download files

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

Source Distribution

gardian_reranker-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

gardian_reranker-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file gardian_reranker-0.1.0.tar.gz.

File metadata

  • Download URL: gardian_reranker-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for gardian_reranker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6a3e6a9b26a6e222b04915315c6b2fea075495ddc3a98237ae1c6ed0423941c4
MD5 7851ef59a6e33d15c4bd792cf6b03654
BLAKE2b-256 fe484a4e56d754eb8d3ac19ce69957b96ea8416682c3de9e5efc5fa01a0e67b1

See more details on using hashes here.

File details

Details for the file gardian_reranker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gardian_reranker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f457f0900872678c9d5f2dab786624a76ecbf8b09f5e5218a19e11aa9ce6e58f
MD5 005679c006c3703d985d2312ca3e701c
BLAKE2b-256 fac13852d27e37206c61a5c8feb05ccc8fcbc0f72e4d0c6d21a17a05469c23c8

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