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
  • How it works:
  • Parameter details:
  • When to use presence_penalty:
API Guides & TutorialsChat CompletionHow-to

How to encourage new topics with presence_penalty

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

How to reduce repetition with frequency_penalty

Next
Built with

The presence_penalty parameter helps you steer the model toward introducing new concepts or topics, instead of sticking to the same words.

  • Positive values → penalize tokens that have already appeared → model becomes more likely to explore new ideas.
  • Negative values → encourage staying on the same topic (rarely used).

How it works:

  • As the model generates text, it tracks which tokens have already been used.
  • Higher presence_penalty nudges the model to shift away from familiar tokens, helping it bring in new topics or angles.

Parameter details:

ParameterTypeRangeDefault
presence_penaltyDouble-2.0 to 2.00.0

When to use presence_penalty:

ScenarioSuggested Value
You want the model to introduce new topics0.5 to 1.0
Avoid getting stuck on the same subject0.5 to 1.0
Brainstorming ideas1.0 to 1.5
Writing diverse, exploratory content0.5 to 1.5

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: Encourage model to introduce new ideas
7response = client.chat.completions(
8 model="sarvam-105b",
9 messages=[
10 {"role": "system", "content": "You are a creative brainstorming assistant."},
11 {"role": "user", "content": "Suggest some ideas for eco-friendly products."}
12 ],
13 presence_penalty=1.0 # Encourage exploration of new ideas
14)
15
16# Receive assistant's reply as output
17print(response.choices[0].message.content)