tomkay commited on
Commit
a79daf5
Β·
verified Β·
1 Parent(s): 802a28a

Rebrand card to Merino-Pro-4bit

Browse files
Files changed (1) hide show
  1. README.md +28 -66
README.md CHANGED
@@ -1,85 +1,47 @@
1
  ---
2
  license: other
3
  license_name: baa-proprietary
4
- library_name: baa-embedding-reranker
5
- tags: [embeddings, reranker, retrieval, rag, cross-encoder, bi-encoder]
 
 
 
 
 
 
 
6
  ---
7
 
8
- # baa-ai-Embedding-Reranker-v1-4bit
9
 
10
- A **single package that does both embedding (retrieval) and reranking** for RAG / search pipelines,
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
- - **Embed (bi-encoder):** 1024-d, L2-normalized. Prefix queries with `"query: "`.
15
- - **Rerank (cross-encoder):** relevance score per (query, document) pair.
16
- - One class, two methods: `.embed(...)` and `.rerank(...)`.
17
 
18
- ## Install
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
- # point at the downloaded folder (or "." if you cd into it). Auto-selects mps/cuda/cpu.
30
- model = BaaEmbeddingReranker("path/to/baa-ai-Embedding-Reranker-v1-4bit")
31
- # force a device if you want: BaaEmbeddingReranker("...", device="cpu")
32
- ```
33
 
34
- ## Embed β€” dense retrieval
35
- ```python
36
- import numpy as np
37
 
38
- docs = ["Paris is the capital of France.", "The mitochondria is the powerhouse of the cell."]
39
- doc_vecs = model.embed(docs) # (2, 1024) float32, L2-normalized
40
- q_vec = model.embed(["What is the capital of France?"], is_query=True)[0] # note is_query=True
41
 
42
- scores = doc_vecs @ q_vec # cosine (vectors are normalized)
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
- query = "What is the capital of France?"
50
- candidates = ["Paris is the capital of France.",
51
- "Berlin is the capital of Germany.",
52
- "France is in western Europe."]
53
 
54
- ranked = model.rerank(query, candidates, top_k=3) # [(doc, score), ...] best-first
55
- for doc, score in ranked:
56
- print(round(score, 2), doc)
 
57
  ```
58
 
59
- ## End-to-end RAG retrieval (embed -> shortlist -> rerank)
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
- ## Performance
80
- Validated on a 450-query holdout: hit@3 = **0.9511** (fp16) / **0.9556** (4-bit) β€” quantization is free here
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
- ## License
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.