Editor’s introduction
The study examines how sampling temperature influences the transfer of ideological discourse in Retrieval-Augmented Generation (RAG) systems, using a corpus of 1,117 COVID-19 treatment articles categorized into three ideological discourses. It compares LLM-only generation with RAG pipelines under regular and enhanced prompting, measuring discursive alignment via semantic, lexical, and hybrid similarity metrics. Results show higher alignment at moderate temperatures, where stochasticity balances retrieval grounding, and reduced alignment at low temperatures, where deterministic sampling suppresses ideological expression. This suggests that retrieval-based systems amplify ideological content more than standalone models, with temperature modulating the extent of that effect. The findings are limited to the specific context of pandemic-era medical treatments, and the generalizability to other domains like climate policy remains uncertain.
Introduction
Large Language Models (LLMs) have revolutionized the Artificial Intelligence paradigm, being increasingly used in domains such as healthcare, education, and finance, among others. Because such models may hallucinate providing incorrect answers for queries that require up-to-date or domain-specific knowledge, Retrieval-Augmented Generation (RAG) has been introduced as a solution to connect LLMs with external knowledge sources. Notwithstanding, while RAG enhances factual analysis, it also introduces new challenges, specifically in scenarios where the retrieved documents contain inaccurate information or ideological biases. Recent work, for instance, shows that LLMs’ responses contain not only factual cues but also ideological patterns. When combined with RAG systems comprising ideological documents, it can potentially reinforce or shift ideological viewpoints, potentially influencing and steering public opinion. This is particularly concerning in sensitive contexts, such as healthcare, where changes in wording and emphasis can reshape how treatments, risks, or scientific debates are interpreted. Despite its risks, limited attention has been paid to how RAG frameworks shape ideological discourse and how generation parameters can influence LLM outputs in such contexts. Sampling temperature, in particular, plays an important role in controlling the level of randomness in LLM-generated texts. While prior work shows that changes in temperature affect output diversity, creativity, coherence, and reasoning quality, limited attention has been given to its influence on LLMs’ responses based on external knowledge conveying ideological texts.
In this study, we aim to address this gap by examining how ideological discourses propagate through the RAG framework into LLMs’ responses. We evaluate two prompt conditions under varying sampling temperatures. To this end, external knowledge is grounded in an ideological discourse corpus of COVID-19 treatment texts. We adopted Lexical Multidimensional Analysis (LMDA) to identify ideological texts with a focus on two types of scientific articles: one comprising academic texts supporting controversial treatments, i.e., not approved by official health regulatory agencies, and academic texts aligned with health and science international standards. Thus, we constructed external-knowledge scenarios conveying opposing ideological positions. We also considered sampling temperatures ranging from 0.1 to 0.9 and employed targeted prompt engineering to evaluate how LLMs’ responses modulate ideological cues.
Related Work
LLMs generate text token-by-token from left-to-right (or right-to-left for Arabic language) by computing a probability distribution of a given vocabulary and choosing the next token. This process of choosing the next word is referred to as decoding. Research on stochastic decoding has explored how sampling temperature influences LLM outputs, often focusing on diversity, creativity, and task performance. Early work on language generation showed that injecting randomness through sampling can reduce repetition while increasing lexical diversity. More recent evidence suggests that temperature effects are task- and model-dependent. For instance, found strong impacts on machine translation and creativity, especially for smaller models, while reporting comparatively limited changes in reasoning. They also emphasized that no single temperature is optimal across tasks. Other studies, on the other hand, argue that temperature is frequently overestimated as a control for creativity showing minimal or not relevant differences in terms of accuracy across temperatures for multiple-choice, reasoning-oriented QA in several LLMs. Overall, prior work characterizes temperature as a meaningful but inconsistent control parameter with influence varying for different tasks and evaluation criteria.
A growing literature has also documented that LLMs can be influenced by ideological patterns present in their training data. Outputs are sensitive to conditioning context, i.e., subtle framing choices, stance markers, and ideological cues in prompts or provided documents can be transferred into generated text. RAG extends this conditioning by grounding responses in externally retrieved documents, aiming to improve factuality and reduce hallucinations. The retrieval process, however, introduces facts often embodied with unveiled ideological discourse. Thus, if the external source comprises biased, manipulative, or ideologically charged language, these lexical patterns may be reproduced, reinforced, or recontextualized in the model’s output. This is especially worrisome in high-stakes settings, such as education, finance, or healthcare, where small changes in framing or wording can shape how evidence, risks, and treatment recommendations are interpreted.
Discourse analysis provides a theoretical basis for approaching such effects in a systematic way. Commonly understood as a social practice where perspectives and social meanings are constructed, discourses can be conceptualized as structured evaluative orientations that shape representations through lexical patterns and framing strategies. Corpus-based methods operationalize these notions by examining regularities in word co-occurrence and distribution across large text collections. LMDA, extending Biber’s multidimensional framework, identifies statistically derived dimensions formed by clusters of co-occurring lexical items. Because it captures configurations of lexical association rather than isolated keywords, LMDA has been used to detect contrasting discursive orientations in domains such as migrant education, disciplinary knowledge systems, and climate change discourse.
Despite existing studies on temperature effects and the impact of ideological bias in LLMs, little attention has been given to how decoding randomness modulates ideological transfer in RAG. This work aims to fill this gap. Next, we detailed our methodology.
Methodology
This section outlines the methodological framework used in this study. We first describe the design of a domain-specific corpus and the use of LMDA. We then detail the answer generation setup, the prompt configurations, and the range of sampling temperatures adopted. At last, we present the so-called discourse-augmented generation pipeline, explaining the retriever and generator components.
Lexical Multidimensional Analysis (LMDA)
Microanalysis: A careful analysis of the factor scores is required to identify the communicative functions of the co-occurring features, leading to a label and description associated with each specific dimension. This is achieved by a detailed microanalysis of both factor and dimension scores to identify specific patterns and relationships within the text. This step considers social and linguistic aspects of the texts and is performed by an expert. Based on these analyses, descriptive labels are assigned to each dimension, enabling a clearer understanding of the themes and discursive structures present in the corpus.
Discourse-Augmented Generation
This approach explicitly conditions LLMs’ outputs on discourse-aware information derived from LMDA. To achieve that, the standard RAG framework is adapted by introducing ideological metadata into the prompts. Creating ideological outputs enables the assessment of whether or not LLMs’ responses align with the ideological framings presented in the external knowledge.
Prompt Configuration
Figures 2 and 3 present the two types of prompts adopted in our experiments, namely ”regular” and ”enhanced.” These prompts enable us to investigate whether providing explicit ideological context to LLMs influences their responses. The regular settings comprise a prompt with questions, instructions, and the retrieved context when external knowledge is available, i.e., for an RAG-based solution. In the case of the enhanced settings, ideological cues are also provided. Note that the LLM-only condition, i.e., regular prompt without external context, works as our baseline, which allows us to investigate whether LLMs already exhibit ideological biases within their encoded knowledge themselves or biases emerge mainly when exposed to ideological contexts.
Sampling Temperatures
In this study, all LLM responses were generated under five sampling temperatures - 0.1, 0.3, 0.5, 0.7, and 0.9 - to examine how stochastic variation during text generation influences discourse alignment with the reference corpus. In such scenarios, lower temperatures produce more precise answers, while higher ones introduce greater lexical and structural variability in the process of token generation. For each temperature setting, the same set of prompts was used across both LLM-only and RAG configurations to ensure that any observed differences were attributable solely to the sampling temperature, rather than to prompt structure or the retrieval pipeline.
Alignment Metrics
To evaluate how the generated responses under each temperature align with the target ideological discourses, we adopted semantic, lexical, and hybrid approaches. In the semantic approach, texts are represented as dense embeddings that capture meaning, while in the lexical one, texts are represented based on the frequency of specific words and terms. The hybrid setting combines the semantic and lexical approaches as a complementary text representation. To measure alignment, we used cosine similarity, which calculates the angle between two vectors in the representation space, where values closer to 1 indicate higher similarity. Next, we provide details on how we extracted each representation.
Semantic Similarity: For the semantic setting, we concatenate all generated answers for each given ideological dimension pole, e.g., Dim. 1 Neg, into a single document. The text is then tokenized using the BERT-like tokenizer, and if it exceeds the model’s maximum sequence length, it is split into overlapping windows. Each window is encoded into an embedding vector, and the resulting embeddings are averaged with length-based weighting to produce a single semantic representation. The same process is applied to the discourses of each dimension pole, leading to reference ideological vectors. In the next step, both vectors (i.e., from generated responses and the reference ones) are L2-normalized, and their cosine similarity is computed, yielding a scalar measure of semantic alignment between the generated responses and the reference discourses.
Lexical Similarity: For lexical similarity, texts are represented as TF-IDF vectors that capture term-frequency patterns within the documents, and are calculated between two sets of texts, that is, the concatenated model-generated answers associated with one ideological dimension pole, and the reference ideological texts for the corresponding pole. A separate TfidfVectorizer is trained on only these two documents, producing a vocabulary that includes all unique terms from both. Each document is represented as a TF-IDF vector, and cosine similarity is then computed between the two vectors, producing a score between 0 and 1 that reflects the degree of lexical alignment.
Structural Generation Metrics
Lexical Diversity: The Type–Token Ratio (TTR) quantifies the lexical diversity of LLM responses. TTR has long been used to study vocabulary richness and stylistic variation. Since higher sampling temperatures tend to encourage more diverse lexical choices, while retrieval can narrow the range of available terms, this measure helps to reveal how these two factors interact and shape the lexical diversity of LLM responses.
Mean Token Entropy: To capture the level of uncertainty and variability in the token-selection process of models, we compute the mean entropy of the output probability distribution. Token-level entropy originates from information theory and captures how predictable a model’s next word choice is. Higher entropy values indicate more uncertainty in the model’s predictions and greater variation in sentence structure. Because sampling temperature adjusts how sharply the model favors certain tokens over others, entropy provides a clear way to see how different temperature settings increase or limit randomness during generation.
Statistical Analysis of Temperature and Prompt Type
We performed an ANOVA test to assess how discourse alignment is influenced by temperature and prompt type across the three similarity metrics adopted in this study. This analysis enabled us to evaluate the individual effects of temperature and prompt type, as well as their combined effect on discourse alignment.
Main Results
Figures 5–7 compare discourse alignment across four generation conditions over five sampling temperatures. This setup allows us to assess how sampling temperature interacts with retrieval grounding under regular and enhanced prompting. Across all temperatures and in all three evaluation text representations, the RAG-based configurations achieve higher alignment compared to the LLM-only generation. This pattern is encountered in both prompt strategies, with RAG combined with enhanced prompting providing the best alignment with the reference ideological texts. This suggests that ideological cues in the prompt are most effective when reinforced by the retrieved ideological context. Note that temperature influences the variability of alignment differently across conditions, revealing distinct sensitivity to sampling randomness depending on whether retrieval is available.
For instance, RAG with enhanced prompting yields comparatively lower alignment at the most deterministic setting, i.e., temperature 0.1, increasing to a maximum at the moderate temperature of 0.5, with alignment becoming stable as temperature increases. RAG with regular prompting shows a more gradual and monotonic improvement as temperature values increase, reaching its highest alignment when the temperature is set to 0.9. This indicates that when retrieval grounding is present, higher sampling diversity can be exploited without substantially degrading alignment, likely because the retrieved evidence already constrains generation.
In contrast, LLM-only generation is consistently less aligned than retrieval-grounded generation. With enhanced prompting, alignment remains the lowest among all configurations, exhibiting only a small increase around temperature 0.3, followed by a drop and then near-stability. This suggests that adding discourse-oriented prompt enhancements alone cannot improve alignment, and additional randomness does not compensate for the lack of grounding. With regular prompting, alignment increases sharply from temperature 0.1 to 0.3 but then declines and stabilizes at higher temperatures, producing a clear rise-and-fall pattern. This behavior implies that modest stochasticity may temporarily improve ideological alignment, whereas larger temperatures introduce variability that the model cannot adequately control without retrieval support, making this configuration more sensitive to temperature changes overall.
Overall, the results suggest that temperature affects response discourse alignment differently depending on the generation setup. RAG-based configurations tend to slightly increase alignment as temperature and randomness increase. LLM-only models, on the other hand, show more sensitivity to temperature.
Limitations
We acknowledge that this study has some limitations. First, our findings are related to COVID-19 treatments administered between 2020 and 2022. The treatment content during that period was characterized by acute public health urgency, scientific uncertainty, and intense political polarization, all of which could have affected the findings. Second, while this study is a valuable case study for exploring ideological discourses in high-stakes settings, it remains unclear whether the patterns we identify can be generalized to non-medical domains, such as climate change contexts. Third, our evaluations rely on semantic, lexical, and hybrid similarity measures, which may be insufficient for assessing ideological discourse alignment, and human evaluation may be needed to corroborate the findings. Future work may further test the robustness of this approach across diverse ideological debates, determine which findings reflect general mechanisms of ideological encoding and which are specific to pandemic discourse.
Conclusion
This study investigates the effect of sampling temperature on the transfer of ideological discourse in Retrieval Augmented Generation (RAG) systems across four large language models, different prompting, and system configurations. We compare LLM-only and RAG pipelines using both regular prompts and enhanced prompts enriched with ideological metadata. Model outputs are evaluated using semantic, lexical, and hybrid cosine similarity measures against reference texts to assess ideological discourse alignment across multiple temperature settings.
Temperature significantly impacts alignment across all metrics. However, its effect strongly depends on the system configuration. LLM-only systems exhibit greater variability across temperature, suggesting that stochastic decoding more strongly affects ideological positioning in the absence of external grounding. In contrast, in the RAG setting, ideological alignment remains comparatively stable across temperatures, suggesting that retrieval grounding constrains temperature-driven ideological drift.
Overall, while sampling temperature contributes to ideological transfer, its effect is structurally moderated by retrieval and prompting design. Ideological transfer in grounded systems arises from the interaction between decoding stochasticity, metadata-based prompting, and retrieval constraints, rather than temperature alone.


