Language models, retrieval, prompting, and language adaptation · Contextual and sentence encoders · LNG020 · Model
BGE-M3 embeddings
Combines multilingual text representations with dense, sparse, and multi-vector retrieval modes in one embedding framework.
In CodeSplash
A CodeSplash feature runs part of this entry inside the app; some variants aren't offered. There's no Set up button; open it where the label says.
Do it in CodeSplash Run it on your own data in the app: Predict, a learner with a text column › Embedding model (Advanced): a local Ollama model such as bge-m3; dense vectors only, cached per model; sparse and multi-vector outputs aren't offered.
- Availability
- Partly runs in CodeSplash (Predict)
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Combines multilingual text representations with dense, sparse, and multi-vector retrieval modes in one embedding framework. Its value is flexible retrieval granularity rather than counting each supported scoring mode as a separate model.
Question / objective
Can one multilingual encoder support dense, sparse, and token-level retrieval representations?
Architecture / computational structure
A shared encoder supports distinct retrieval heads and scoring modes, coordinated by training/distillation. Learned encoder/head weights differ from chosen hybrid score weights, sparsity pruning, and index settings.
Assumptions
Scores from different modes are not inherently calibrated.
Formula / computational definition
Dense similarity compares pooled vectors; sparse scoring uses weighted lexical overlap; multi-vector scoring aggregates token-level maximum similarities. Self-knowledge distillation coordinates these objectives, so a hybrid score may combine several normalized components.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Retrieval mode, sequence length, pooling, score weights, index configuration, candidate depth, and reranking budget.
Fitting, fine-tuning, and adaptation
Start with each retrieval mode separately before fitting hybrid weights on validation queries. Fine-tune with relevant domain pairs and negatives using the authors' recipe; compatible adapters require verified support across heads. Reindex outputs after updates and test low-resource languages and mode-specific regressions.
How to use and calibrate
Report each mode separately plus hybrid ablations, retrieval quality, latency, storage, and performance by language and document length. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Compare dense, lexical-expansion, and token-level matching for multilingual technical documents.
Interpretation / pitfalls
Watch out
Long-input support does not guarantee all relevant details survive representation; multilingual aggregate metrics can conceal language-specific weaknesses. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use the authors' FlagEmbedding implementation or compatible documented integrations. R generally bridges Python through reticulate; native score computation is straightforward after exporting vectors/weights, but full training is not supplied by that step.
Example scope: A toy BGE-M3 hybrid score after independently supplied mode scores; weights need validation.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — A toy BGE-M3 hybrid score after independently supplied mode scores; weights need validation.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
dense, sparse, multivector = [0.8,0.5], [0.3,0.9], [0.7,0.6]
weights = [0.4,0.2,0.4]
hybrid = [sum(w*s[i] for w,s in zip(weights,[dense,sparse,multivector])) for i in range(2)]
print(hybrid)
Component demo, not a trained model — A toy BGE-M3 hybrid score after independently supplied mode scores; weights need validation.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
scores <- rbind(c(0.8,0.5), c(0.3,0.9), c(0.7,0.6))
weights <- c(0.4,0.2,0.4)
hybrid <- colSums(scores * weights)
print(hybrid)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG020.