How to improve factual accuracy with wiki_grounding

If wiki_grounding is enabled, the model uses a RAG (Retrieval-Augmented Generation) approach:

  • It retrieves relevant chunks from Wikipedia based on the user’s question.
  • It then uses those chunks to ground its answer — making the response more accurate and fact-based.

What is RAG?

RAG = Retrieval-Augmented Generation.

Instead of only relying on the model’s internal knowledge (which can be outdated or incomplete), RAG allows the model to:

  1. Look up external data sources (in this case, Wikipedia)
  2. Condition its response on those sources

Why enable wiki_grounding?

When to useBenefit
Factual Q&AImproves accuracy
Educational contentProvides verified explanations
”What is X?” or “Explain Y” type questionsUses up-to-date info from Wikipedia
Historical or scientific queriesReduces hallucination
1# Install SarvamAI
2!pip install -Uqq sarvamai
3from sarvamai import SarvamAI
1# Initialize the SarvamAI client with your API key
2client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
1# Example: Using wiki_grounding to improve factual accuracy
2response = client.chat.completions(
3 messages=[
4 {"role": "system", "content": "You are a knowledgeable history professor."},
5 {"role": "user", "content": "Who was the first woman to win a Nobel Prize?"}
6 ],
7 wiki_grounding=True,
8 reasoning_effort="high",
9 temperature=0.3
10)
1# Receive assistant's reply as output.
2print(response.choices[0].message.content)