Search that finds the right answer in your price list, policies or manuals, so a chat assistant can quote them instead of guessing.
How to run it
Commands are copied from the source, unchanged except where a notebook cell is cut at 40 lines (marked in the code). Placeholders like <you> are the source's own. Credit goes to the authors named on each block.
Install (as written in the notebook)
%%capture
import os, re
if "COLAB_" not in "".join(os.environ.keys()):
!pip install unsloth # Do this in local & cloud setups
else:
!pip install sentencepiece protobuf "datasets==4.3.0" "huggingface_hub>=0.34.0" hf_transfer
!pip install --no-deps unsloth_zoo bitsandbytes accelerate peft trl triton unsloth
!unsloth install-kernels
!pip install --no-deps --upgrade "torchao>=0.16.0"
!pip install transformers==4.57.6
!pip install --no-deps trl==0.22.2
from unsloth import FastSentenceTransformer
fourbit_models = [
"unsloth/all-MiniLM-L6-v2",
"unsloth/embeddinggemma-300m",
"unsloth/Qwen3-Embedding-4B",
"unsloth/Qwen3-Embedding-0.6B",
"unsloth/all-mpnet-base-v2",
"unsloth/gte-modernbert-base",
"unsloth/bge-m3"
] # More models at https://huggingface.co/unsloth
model = FastSentenceTransformer.from_pretrained(
model_name = "unsloth/Qwen3-Embedding-0.6B",
max_seq_length = 512, # Choose any for long context!
full_finetuning = False, # [NEW!] We have full finetuning now!
)
from sentence_transformers import (
SentenceTransformerTrainer,
SentenceTransformerTrainingArguments,
losses
)
from sentence_transformers.training_args import BatchSamplers
from unsloth import is_bf16_supported
# This will use other positives in the same batch as negative examples
loss = losses.MultipleNegativesRankingLoss(model)
trainer = SentenceTransformerTrainer(
model = model,
train_dataset = dataset,
loss = loss,
args = SentenceTransformerTrainingArguments(
output_dir = "output",
num_train_epochs = 2,
per_device_train_batch_size = 256,
gradient_accumulation_steps = 1, # Use GA to mimic batch size!
learning_rate = 3e-5,
fp16 = not is_bf16_supported(),
bf16 = is_bf16_supported(),
logging_steps = 50,
warmup_ratio = 0.03,
report_to = "none",
lr_scheduler_type = "constant_with_warmup",
# Because we have duplicate anchors in the dataset, we don't want
# to accidentally use them for negative examples
batch_sampler = BatchSamplers.NO_DUPLICATES,
),
)