ConTra โ€” Context That Travels. The same prefix accompanies its passage through writing, retrieval, and reranking.

Jiajun Hou ยท Jingbang Chen
CUHK-Shenzhen ยท SLAI

ConTra writes short contextual prefixes for document chunks. At indexing time, each prefix is prepended to its chunk and reused for both embedding retrieval and reranking.

Models  ยท  RealContextBench  ยท  Project page

Models and dataset

Model Base model
ConTra-0.8B Qwen3.5-0.8B
ConTra-2B Qwen3.5-2B
ConTra-4B Qwen3.5-4B

All three are Qwen3.5 generators post-trained with reinforcement learning to produce contextual prefixes. ConTra-2B has the highest average reranked score in this release.

RealContextBench contains five application collections and three NanoBEIR context conditions for text retrieval.

Using ConTra on documents

Generate one prefix per chunk when building your index. We recommend a context window of about 16K tokens. Use the full document when it fits. For longer documents, use nearby complete chunks in their original order and mark the target chunk separately.

This example uses ConTra-2B with PyTorch and Transformers on CUDA.

import torch
from transformers import AutoModelForImageTextToText, AutoTokenizer

repo = "JJHou1/ConTra-2B"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForImageTextToText.from_pretrained(
    repo, dtype=torch.bfloat16,
).to("cuda").eval()

chunks = [
    "The City Library will reopen its East Branch on 3 June.",
    "It will be open from 10 a.m. to 6 p.m. on weekdays.",
]
target = chunks[1]
document = "\n\n".join(
    f'<CHUNK index="{index}">\n{chunk}\n</CHUNK>'
    for index, chunk in enumerate(chunks)
)
system_prompt = (
    "You are a contextualization model for retrieval-augmented generation (RAG).\n\n"
    "Given a document and one target chunk from that document, generate a concise "
    "contextual prefix containing only the necessary information that helps the chunk "
    "remain understandable and retrievable outside its original document.\n\n"
    "Do not repeat the target chunk, introduce unsupported information, or add "
    "unnecessary details. If the chunk does not need additional context, output exactly "
    "<NO_CONTEXT>.\n\n"
    "Output only the contextual prefix or <NO_CONTEXT>."
)
messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": (
        f"<DOCUMENT>\n{document}\n</DOCUMENT>\n\n<TARGET_CHUNK>\n{target}\n</TARGET_CHUNK>"
    )},
]
inputs = tokenizer.apply_chat_template(
    messages, tokenize=True, add_generation_prompt=True, enable_thinking=False,
    return_dict=True, return_tensors="pt",
).to("cuda")
with torch.inference_mode():
    output = model.generate(**inputs, do_sample=False, max_new_tokens=768)

new_tokens = output[0, inputs["input_ids"].shape[1]:]
prefix = tokenizer.decode(new_tokens, skip_special_tokens=True).strip()
augmented_chunk = target
if prefix and not prefix.upper().startswith("<NO_CONTEXT>") and prefix != target:
    augmented_chunk = f"{prefix}\n\n{target}"
print(augmented_chunk)

Keep each chunk's original ID and use the augmented text for both embedding and reranking.

Results

Reported macro-averaged nDCG@10 after top-15 reranking with Qwen3-Reranker-4B.

Method ConTEB RealContextBench
Qwen3-Embedding-4B, original text 0.6483 0.6373
InSeNT 0.6381 0.5291
PPLX-context-0.6B 0.7110 0.6083
PPLX-context-4B 0.7310 0.6542
Voyage-context-3 0.7292 0.6636
Voyage-context-4 0.7300 0.6608
Qwen3.5-0.8B 0.6531 0.6384
Qwen3.5-2B 0.7585 0.6456
Qwen3.5-4B 0.8110 0.6553
Qwen3.5-9B 0.8279 0.6632
ConTra-0.8B 0.7346 0.6471
ConTra-2B 0.8525 0.6692
ConTra-4B 0.8465 0.6669

ConTEB averages eight tasks. RealContextBench averages five application collections and three NanoBEIR conditions. Contextual encoders supply original chunks to the reranker. Prefix-based pipelines supply the prefix and original chunk.

Downloads last month
-
Safetensors
Model size
0.9B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for JJHou1/ConTra-0.8B

Finetuned
(1,063)
this model

Collection including JJHou1/ConTra-0.8B