For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
CommunityAPI StatusAPI PricingSign Up
DocumentationAPI ReferencesCookbookIntegrationDeveloper Tools
DocumentationAPI ReferencesCookbookIntegrationDeveloper Tools
  • Getting Started
    • Welcome
    • Quickstart
    • SDKs & Libraries
    • Building for Indian Languages
    • Models
    • Credits & Rate Limits
    • Errors & Troubleshooting
    • Talk to us
    • Pricing
    • Changelog
  • API Guides & Tutorials
      • Overview
        • List your chat messages
        • Control response randomness
        • Control response diversity
        • Adjust the model's thinking level
        • Improve response factual accuracy
        • Encourage new topics in response
        • Reduce repetition words or phrases in response
        • Get repeatable results
        • Control the response length
        • Control where the model stops
LogoLogo
CommunityAPI StatusAPI PricingSign Up
On this page
  • What is RAG?
  • Why enable wiki_grounding?
API Guides & TutorialsChat CompletionHow-to

How to improve factual accuracy with wiki_grounding

||View as Markdown|
Was this page helpful?
Previous

How to encourage new topics with presence_penalty

Next
Built with

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 model="sarvam-105b",
9 messages=[
10 {"role": "system", "content": "You are a knowledgeable history professor."},
11 {"role": "user", "content": "Who was the first woman to win a Nobel Prize?"}
12 ],
13 wiki_grounding=True,
14 reasoning_effort="high",
15 temperature=0.3
16)
17
18# Receive assistant's reply as output
19print(response.choices[0].message.content)