# Query Transformation in Spring AI Modular RAG

DevFeed: [Query Transformation in Spring AI Modular RAG](<https://devfeed.tech/articles/query-transformation-in-spring-ai-modular-rag-109194.md>)

Original publisher: [Read original article](<https://www.baeldung.com/spring-ai-rag-query-transformation>)

Author: Manfred Ng

Published: 2026-10-30T11:51:20Z

Content type: tutorial

Language: en

Sources: [Baeldung](<https://devfeed.tech/sources/baeldung.md>)

Topics: [Spring AI](<https://devfeed.tech/topics/spring-ai.md>), [Retrieval Augmented Generation (RAG)](<https://devfeed.tech/topics/retrieval-augmented-generation-rag.md>), [AI Architecture](<https://devfeed.tech/topics/ai-architecture.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [llm](<https://devfeed.tech/tags/llm.md>), [modular](<https://devfeed.tech/tags/modular.md>), [query](<https://devfeed.tech/tags/query.md>), [rag](<https://devfeed.tech/tags/rag.md>), [retrieval](<https://devfeed.tech/tags/retrieval.md>), [retrieval-augmented-generation](<https://devfeed.tech/tags/retrieval-augmented-generation.md>), [spring](<https://devfeed.tech/tags/spring.md>), [spring-ai](<https://devfeed.tech/tags/spring-ai.md>), [spring-ai-llm](<https://devfeed.tech/tags/spring-ai-llm.md>), [transformation](<https://devfeed.tech/tags/transformation.md>)

## AI overview

Spring AI's modular RAG pipeline can transform a query before vector-store retrieval, where wording affects which documents match. RewriteQueryTransformer uses an LLM to remove irrelevant detail from verbose queries. TranslationQueryTransformer converts queries to the datastore's language; it leaves queries unchanged when they are already in the target language or the LLM cannot recognize them. CompressionQueryTransformer uses query history to resolve references such as "it," and can leave unrelated prior context out; applications must provide history, for example through a chat memory advisor. Transformers run in sequence, each needs a ChatClient.Builder and makes an additional LLM call, increasing latency. The excerpt recommends a low temperature such as 0.0 for more deterministic rewrites and enabling only transformers that are needed.

## Source excerpt

Learn how to set up query transformation in Spring AI for retrieval augmented generation. The post Query Transformation in Spring AI Modular RAG first appeared on Baeldung.