Command-R
Cohere's language model optimized for RAG
Cohere's language model optimized for RAG
Command-R is a language model developed by Cohere and optimized for RAG (Retrieval-Augmented Generation). It specializes in retrieving external documents and generating accurate answers based on their content, and its wide context window of 128K tokens lets it process a large number of reference documents at once.
Command-R, released in March 2024, is a 35B-parameter model, and Command-R+, with 104B parameters, was added afterward. Cohere is a startup focused on enterprise AI solutions, and it uses this model as the core of building enterprise RAG platforms that integrate retrieval and generation.
Command-R's core feature is Grounded Generation. When reference documents are passed through the documents parameter, the model generates answers based solely on the content of those documents. Because citations are automatically included in the answer, it is possible to trace which document the information came from, which makes hallucination verification easier.
In practice, Command-R is used for customer support chatbots, internal document search systems, legal/medical document analysis, technical document Q&A, and more. Its strong multilingual support makes it suitable for global services, and it is also available on AWS Bedrock and Google Cloud, which makes adoption in enterprise environments easier.
import cohere
# Cohere 클라이언트 초기화
co = cohere.Client("your-api-key")
# RAG용 참조 문서 준비
documents = [
{"title": "회사 연차 정책", "text": "입사 1년 이상 직원은 연 15일의 유급 휴가가 부여됩니다. 미사용 연차는 이월되지 않습니다."},
{"title": "재택근무 가이드", "text": "주 2회까지 재택근무가 가능하며, 팀장 사전 승인이 필요합니다."},
{"title": "경비 처리 규정", "text": "출장비는 월 50만원 한도 내에서 사후 정산됩니다. 영수증 첨부 필수입니다."}
]
# Grounded Generation으로 RAG 수행
response = co.chat(
model="command-r-plus",
message="연차 휴가는 며칠인가요?",
documents=documents, # 참조 문서 전달
temperature=0.3,
citation_quality="accurate" # 정확한 인용 생성
)
print("답변:", response.text)
print("\n인용 정보:")
for citation in response.citations:
print(f" - [{citation.start}:{citation.end}] 문서: {citation.document_ids}")
# Tool Use (함수 호출) 기능
tools = [{
"name": "search_database",
"description": "사내 데이터베이스에서 정보를 검색합니다",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "검색어"}
},
"required": ["query"]
}
}]
response = co.chat(
model="command-r-plus",
message="최근 프로젝트 현황을 알려줘",
tools=tools
)
if response.tool_calls:
print(f"호출할 함수: {response.tool_calls[0].name}")
"If you use Command-R in the generation step, citations are attached automatically, which is great. When a hallucination occurs, you can immediately see which document it came from, so debugging is easier and user trust goes up."
"Command-R's Grounded Generation answers based solely on the documents passed through the documents parameter. It is designed to prioritize the documents when parametric knowledge and document content conflict, so it is optimized for RAG scenarios."
"For the same RAG quality, Command-R costs about half as much as GPT-4. With a 128K context, the chunking strategy is less complex, and combined with embed-v3, multilingual search performs well too."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Clearly separate the title and text in each item of the documents array. Having a title improves citation quality and also makes it easier to show sources to users.
It supports up to 128K, but if you put in too many documents, answers may be generated from irrelevant information. We recommend filtering to the top 5-10 in the retrieval step.
Command-R (35B) is advantageous for speed and cost, and Command-R+ (104B) for complex reasoning. Consider using R for simple Q&A and R+ for multi-step analysis or summarization.