Sentence Similarity
sentence-transformers
baa-embedding-reranker
retrieval
embeddings
reranker
cross-encoder
rag
Instructions to use baa-ai/Merino-Pro-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use baa-ai/Merino-Pro-4bit with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("baa-ai/Merino-Pro-4bit") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
Rebrand card to Merino-Pro-4bit
Browse files
README.md
CHANGED
|
@@ -1,85 +1,47 @@
|
|
| 1 |
---
|
| 2 |
license: other
|
| 3 |
license_name: baa-proprietary
|
| 4 |
-
library_name:
|
| 5 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
-
# baa
|
| 9 |
|
| 10 |
-
|
| 11 |
-
by **BAA AI (Black Sheep AI)**. The bi-encoder embedder and cross-encoder reranker share one
|
| 12 |
-
XLM-RoBERTa-large word-embedding table (stored once). This is the **4-bit** build (group-64 int4 Linear weights; ~2x smaller download, same hit@3).
|
| 13 |
|
| 14 |
-
|
| 15 |
-
- **Rerank (cross-encoder):** relevance score per (query, document) pair.
|
| 16 |
-
- One class, two methods: `.embed(...)` and `.rerank(...)`.
|
| 17 |
|
| 18 |
-
|
| 19 |
-
```bash
|
| 20 |
-
pip install -r requirements.txt
|
| 21 |
-
```
|
| 22 |
-
The package is self-contained β the loader lives in `modeling_baa.py` and reconstructs the model from the
|
| 23 |
-
files in this folder. Works on CPU, Apple Silicon (MPS), and CUDA.
|
| 24 |
-
|
| 25 |
-
## Load into memory
|
| 26 |
-
```python
|
| 27 |
-
from modeling_baa import BaaEmbeddingReranker
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
model = BaaEmbeddingReranker("path/to/baa-ai-Embedding-Reranker-v1-4bit")
|
| 31 |
-
# force a device if you want: BaaEmbeddingReranker("...", device="cpu")
|
| 32 |
-
```
|
| 33 |
|
| 34 |
-
|
| 35 |
-
```python
|
| 36 |
-
import numpy as np
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
-
top = int(np.argmax(scores))
|
| 44 |
-
print("best doc:", docs[top], "score:", float(scores[top]))
|
| 45 |
-
```
|
| 46 |
|
| 47 |
-
## Rerank β order candidates for a query
|
| 48 |
```python
|
| 49 |
-
|
| 50 |
-
candidates = ["Paris is the capital of France.",
|
| 51 |
-
"Berlin is the capital of Germany.",
|
| 52 |
-
"France is in western Europe."]
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
```
|
| 58 |
|
| 59 |
-
##
|
| 60 |
-
```python
|
| 61 |
-
import numpy as np
|
| 62 |
-
|
| 63 |
-
# 1) index your corpus once
|
| 64 |
-
corpus = ["...doc 1...", "...doc 2...", "...", "...doc N..."]
|
| 65 |
-
corpus_vecs = model.embed(corpus) # (N, 1024)
|
| 66 |
-
|
| 67 |
-
def search(query, k_dense=50, k_final=5):
|
| 68 |
-
qv = model.embed([query], is_query=True)[0]
|
| 69 |
-
# 2) dense shortlist
|
| 70 |
-
sims = corpus_vecs @ qv
|
| 71 |
-
shortlist = np.argsort(-sims)[:k_dense]
|
| 72 |
-
# 3) rerank the shortlist
|
| 73 |
-
cand = [corpus[i] for i in shortlist]
|
| 74 |
-
return model.rerank(query, cand, top_k=k_final)
|
| 75 |
-
|
| 76 |
-
print(search("your question here"))
|
| 77 |
-
```
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
because the cross-encoder absorbs it. This is the **4-bit** build (group-64 int4 Linear weights; ~2x smaller download, same hit@3).
|
| 82 |
|
| 83 |
-
|
| 84 |
-
- **BAA Contributions** (architecture, loader, packaging, weights, docs): **proprietary** β see `LICENSE`.
|
| 85 |
-
- Backbone `xlm-roberta-large`: **MIT** β see `LICENSE-xlm-roberta-large.txt`.
|
|
|
|
| 1 |
---
|
| 2 |
license: other
|
| 3 |
license_name: baa-proprietary
|
| 4 |
+
library_name: sentence-transformers
|
| 5 |
+
tags:
|
| 6 |
+
- retrieval
|
| 7 |
+
- embeddings
|
| 8 |
+
- reranker
|
| 9 |
+
- cross-encoder
|
| 10 |
+
- rag
|
| 11 |
+
- sentence-similarity
|
| 12 |
+
pipeline_tag: sentence-similarity
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# baa.ai Β· Merino-Pro-4bit
|
| 16 |
|
| 17 |
+
**The premium unified retrieval model β bi-encoder embedding *and* cross-encoder reranking in one package, over a single shared word-embedding table.** A 1024-dimensional multilingual model, by BAA AI (Black Sheep AI). ~872M params, 4-bit quantized (~0.5 GB).
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
## Get the optimal model for *your* data
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
Merino-Pro-4bit is baa.ai's flagship default. But the best embedder + reranker is **corpus-specific** β the ideal choice depends on your documents and your notion of relevance. **baa.ai offers exclusive tooling that identifies the optimal embedding and reranking models for your specific data**, so you ship the smallest models that maximize document recovery on your corpus. For a tailored recommendation, **reach out to baa.ai**.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
## What it is
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
A two-role retrieval model over a **shared input word-embedding matrix** (~256M params, stored once). The bi-encoder embedder and cross-encoder reranker are both built on the `xlm-roberta-large` backbone and **co-trained** to share a single word-embedding table at **no quality loss**, while each role keeps its native layers and head. 4-bit weight quantization is lossless on this stack (the embedder is the limiter; rerank tolerates lower bits).
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
- **Embed role:** bi-encoder, 1024-d, L2-normalized. Prepend `"query: "` to queries.
|
| 28 |
+
- **Rerank role:** cross-encoder, single relevance logit per (query, document) pair.
|
| 29 |
+
- **Router:** call `.embed(...)` or `.rerank(...)`.
|
| 30 |
|
| 31 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
| 32 |
|
|
|
|
| 33 |
```python
|
| 34 |
+
from modeling_baa import BaaEmbeddingReranker # included in this repo
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
m = BaaEmbeddingReranker("baa-ai/Merino-Pro-4bit")
|
| 37 |
+
qv = m.embed(["my query"], is_query=True)[0] # 1024-d normalized
|
| 38 |
+
dv = m.embed(["doc a", "doc b"])
|
| 39 |
+
ranked = m.rerank("my query", ["doc a", "doc b"], top_k=10) # [(doc, score), ...]
|
| 40 |
```
|
| 41 |
|
| 42 |
+
## License & attribution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
- **BAA Contributions** (shared-embedding architecture, router/loader code, packaging, weights, docs) are **proprietary to BAA AI (Black Sheep AI)** β see `LICENSE`.
|
| 45 |
+
- Incorporates the `xlm-roberta-large` backbone under the **MIT License** β see `LICENSE-xlm-roberta-large.txt`.
|
|
|
|
| 46 |
|
| 47 |
+
Β© 2026 BAA AI (Black Sheep AI) β baa.ai. Provided "as is" without warranty.
|
|
|
|
|
|