Fine-Tuning the Command R Language Model (Cohere)
Command R and Command R+ are Cohere's model family designed for RAG tasks and tool use. Out of the box, they don't always deliver the required citation accuracy and low hallucination rate in a specific domain. A typical problem: the model cites non-existent articles of law or incorrectly selects a relevant fragment from a 50-page document. Model adaptation solves this.
Our engineers fine-tune LLMs for enterprise clients: we adapt Command R to your stack, dataset, and business logic. We have 5+ years of NLP experience and over 30 deployed RAG systems. Since 2018, we've helped companies reduce hallucinations by up to 5x and cut inference costs by 40% compared to base models. For example, an enterprise with 10M monthly requests saves approximately $5,000 per month. Contact us for a consultation—we'll evaluate your project in a couple of days.
The Command R Family
| Model | Parameters | Context | Key Feature |
|---|---|---|---|
| Command R | 35B | 128K | RAG, citation |
| Command R+ | 104B | 128K | Complex tasks, reasoning |
| Command R7B | 7B | 128K | Fast, cheap |
| Command A | — | 256K | Latest generation |
Cohere provides open weights for Command R via Hugging Face, enabling self-hosted fine-tuning. The open version matches the RAG quality of the closed—the difference is only in infrastructure and control. As noted in the Cohere documentation, the model is specifically optimized for RAG scenarios.
How to Choose Between Managed and Self-Hosted Fine-Tuning?
The choice depends on data confidentiality requirements and request volume. Managed fine-tuning through the Cohere API works if data does not need to be stored on-premise. Self-hosted with QLoRA is for strict security policies and high loads.
Managed (via Cohere API)
import cohere
co = cohere.Client(api_key="...")
dataset = co.datasets.create(
name="legal-analysis-dataset",
type="chat-finetune-input",
data=open("train.jsonl", "rb"),
eval_data=open("val.jsonl", "rb"),
)
ft = co.finetuning.create_finetune(
request=cohere.finetuning.CreateFinetune(
name="command-r-legal",
model="command-r-plus",
settings=cohere.finetuning.Settings(
base_model=cohere.finetuning.BaseModel(
base_type=cohere.finetuning.BaseType.BASE_TYPE_CHAT,
name="command-r-plus",
),
dataset_id=dataset.dataset.id,
train_epochs=5,
learning_rate=0.001,
),
)
)
Self-Hosted via PEFT/LoRA
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import LoraConfig, get_peft_model
model = AutoModelForCausalLM.from_pretrained(
"CohereForAI/c4ai-command-r-v01",
device_map="auto",
torch_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained("CohereForAI/c4ai-command-r-v01")
lora_config = LoraConfig(
r=16,
target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
task_type="CAUSAL_LM"
)
model = get_peft_model(model, lora_config)
Technical Details of QLoRA
QLoRA uses 4-bit quantization and LoRA adapters, making it possible to train a 35B model on a single A100 GPU in 12–36 hours. Memory consumption is about 24 GB.
Self-hosted with QLoRA reduces cost by 2–3x compared to the API at high volumes.
Data Format: Chat with Preamble
Command R uses a special chat format supporting a system prompt (preamble), RAG documents, and conversation history:
{
"messages": [
{
"role": "System",
"message": "You are a legal assistant. Always cite specific articles of law."
},
{
"role": "User",
"message": "What is the statute of limitations for a real estate sale contract?"
},
{
"role": "Chatbot",
"message": "The statute of limitations for a real estate sale contract is three years (Article 196 of the Civil Code). For void transactions—also three years from the date the person knew or should have known about the violation (Article 181 of the Civil Code)..."
}
]
}
RAG-Specific: Fine-Tuning with Documents
A unique capability of Command R is training with documents in context. This allows you to adapt the model to a specific citation style and level of detail when working with corporate documents:
{
"messages": [...],
"documents": [
{
"title": "Claims Handling Regulations",
"snippet": "3.4. The claim review period shall not exceed 30 calendar days..."
}
]
}
With this approach, the model learns not only to generate answers but also to correctly extract relevant fragments from the provided documents.
Practical Case: Legal Assistant for Corporate Law
Task
A legal department assistant for a large company—contract analysis, internal regulation inquiries, legislative base work. Our client was a Russian law firm with 2000+ employees, requiring guaranteed hallucination reduction.
Dataset
2800 examples (question + relevant document fragment → answer with source citation). Data from real lawyer queries to the knowledge base.
Results
- Faithfulness (RAGAS): from 0.71 to 0.93
- Answer relevancy: from 0.78 to 0.91
- Citation accuracy: from 64% to 89%
- Hallucination rate: from 18% to 4%
This fine-tuning pays off through reduced hallucinations and fewer tokens per response. Inference cost savings reach 40%, and with the increased accuracy, the total cost of ownership decreases by 25%.
Why Our Approach Is More Effective Than Off-the-Shelf Solutions?
Ready-made assistant models do not account for the specifics of your data. Fine-tuning delivers accuracy unattainable through prompt engineering: up to 40% inference savings due to fewer tokens per response. We don't just run fine-tuning—we design the dataset for your use case. Our engineers have 10+ years of NLP experience and certifications from leading vendors (Cohere, Hugging Face). Our language model fine-tuning for enterprise RAG ensures your model fits your domain perfectly.
Estimated Implementation Timelines
Timelines depend on dataset size and chosen approach:
| Stage | Duration |
|---|---|
| Dataset preparation with documents | 3–6 weeks |
| Training (Cohere API) | 2–5 days |
| Training (self-hosted, 35B, QLoRA) | 12–36 hours |
| RAG quality testing | 1–2 weeks |
| Total | 6–10 weeks |
Deliverables (What's Included in the Work)
Turnkey fine-tuning includes:
- Audit of current data and dialogue collection process
- Data annotation with a domain expert
- Training and evaluation cycle (faithfulness, relevancy, hallucination rate)
- Deployment (on-premise or cloud) with documentation
- Access to the fine-tuned model via API or local endpoint
- Team training session (up to 4 hours)
- 1 month of production model support with monthly quality reports
Dataset Preparation: Key Steps
- Collect 1000–3000 dialogues with real queries and expert responses.
- Each example must include preamble, documents (if RAG), and expected answer with citations.
- Annotate faithfulness: the answer must rely only on provided documents.
- Ensure diversity: the dataset should cover all typical scenarios.
Comparison: self-hosted fine-tuning with QLoRA gives quality comparable to full fine-tuning but at 2–3x lower cost and faster. It's ideal for pilot projects.
Contact us to get a consultation on your project. We'll evaluate your data, choose the optimal method (managed or self-hosted), and provide precise timelines.







