> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt.
> For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# How to improve factual accuracy with `wiki_grounding`

> Model uses a RAG based approach to retrieve relevant chunks from Wikipedia.

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 use**                            | **Benefit**                         |
| ------------------------------------------ | ----------------------------------- |
| Factual Q\&A                               | Improves accuracy                   |
| Educational content                        | Provides verified explanations      |
| "What is X?" or "Explain Y" type questions | Uses up-to-date info from Wikipedia |
| Historical or scientific queries           | Reduces hallucination               |

First, install the SDK:

```bash
pip install -Uqq sarvamai
```

Then use the following Python code:

```python
from sarvamai import SarvamAI

# Initialize the SarvamAI client with your API key
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")

# Example: Using wiki_grounding to improve factual accuracy
response = client.chat.completions(
    model="sarvam-105b",
    messages=[
        {"role": "system", "content": "You are a knowledgeable history professor."},
        {"role": "user", "content": "Who was the first woman to win a Nobel Prize?"}
    ],
    wiki_grounding=True,
    reasoning_effort="high",
    temperature=0.3
)

# Receive assistant's reply as output
print(response.choices[0].message.content)
```