Views
No views yet

[!WARNING] This experimental model stems from the paper Context is Gold to find the Gold Passage: Evaluating and Training Contextual Document Embeddings. While results are promising, we have seen regression on standard embedding tasks, and using it in production will probably require further work on extending the training set to improve robustness and OOD generalization.
contextual-embeddings package:pip install git+https://github.com/illuin-tech/contextual-embeddings1from contextual_embeddings import LongContextEmbeddingModel
2from sentence_transformers import SentenceTransformer
3
4documents = [
5 [
6 "The old lighthouse keeper trimmed his lamp, its beam cutting a lonely path through the fog.",
7 "He remembered nights of violent storms, when the ocean seemed to swallow the sky whole.",
8 "Still, he found comfort in his duty, a silent guardian against the treacherous sea."
9 ],
10 [
11 "A curious fox cub, all rust and wonder, ventured out from its den for the first time.",
12 "Each rustle of leaves, every chirping bird, was a new symphony to its tiny ears.",
13 "Under the watchful eye of its mother, it began to learn the secrets of the whispering forest."
14 ]
15]
16base_model = SentenceTransformer("illuin-conteb/modernbert-large-insent")
17contextual_model = LongContextEmbeddingModel(
18 base_model=base_model,
19 add_prefix=True
20)
21embeddings = contextual_model.embed_documents(documents)
22print("Length of embeddings:", len(embeddings)) # 2
23print("Length of first document embedding:", len(embeddings[0])) # 3
24print(f"Shape of first chunk embedding: {embeddings[0][0].shape}") # torch.Size([768])1@misc{conti2025contextgoldgoldpassage,
2 title={Context is Gold to find the Gold Passage: Evaluating and Training Contextual Document Embeddings},
3 author={Max Conti and Manuel Faysse and Gautier Viaud and Antoine Bosselut and Céline Hudelot and Pierre Colombo},
4 year={2025},
5 eprint={2505.24782},
6 archivePrefix={arXiv},
7 primaryClass={cs.IR},
8 url={https://arxiv.org/abs/2505.24782},
9}