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

First, install the SDK:

$pip install -Uqq sarvamai

Then use the following Python code:

1from sarvamai import SarvamAI
2
3# Initialize the SarvamAI client with your API key
4client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
5
6# Example: Using wiki_grounding to improve factual accuracy
7response = client.chat.completions(
8 messages=[
9 {"role": "system", "content": "You are a knowledgeable history professor."},
10 {"role": "user", "content": "Who was the first woman to win a Nobel Prize?"}
11 ],
12 wiki_grounding=True,
13 reasoning_effort="high",
14 temperature=0.3
15)
16
17# Receive assistant's reply as output
18print(response.choices[0].message.content)