Chain of Thought – A Query Transformation Technique for Advanced RAG


Chain of Thought technique actually breaks down user query into simpler sub-queries, and process them Sequentially , providing previous query output as context to next query processing , which results in getting better Response at End.
Chain of Thought :
What is it ?
- Its a method where a User Query is broken down into smaller, logical sub-questions or steps, and then step by step finding vector embeddings, doing semantic search and using it to generate response then that response gets passed onto next Subquery’s Context to retrieve better information and finally getting more accurate response.
Where do we apply this in RAG ?
RAG contains , three major steps, Indexing Retrieving Generation , now Indexing is storing Data sources in Database by creating Vector embeddings of data chunks , Retrieving process starts, after receiving User Query to get relevant data and we pass it as context with user Query to Generation part, which finally generated Response.
So, this COT technique is applicable at second step , i.e RETRIEVAL
How does it work ?
On Receiving user query, we ask our LLM to break it down to Sub-Queries ( Making Original query less abstract )
We process those Queries Sequentially, generating response from first sub-query and passing to it Second till last sub-query
When last Sub-query generates Response, we output it as Final Response to User .
How Response got More Accurate ?
- We increased Context ( by providing , more relevant context ) by deep diving in the User Query by making it LESS ABSTRACT, with that augmented context, we got more Precise Response aligned with the user Query.
Working Step by Step with Code & Visual :
From user-prompt, we ask LLM to break it down to simple Sub-Queries ( lets say 3 )
then, we go sequentially, we create vector embeddings and do semantic search on first query, getting relevant context, we provide it to LLM with first query to generate Response, then we set this Response as Context for next sub query process, we do this till last subquery.
After loop ends on subqueries, Response generated from last subquery we show it as Final Output to User
Chain of Thought Output :
Important Links:
CHAIN OF THOUGHT Code - Visit Here!
I have discussed all Advanced RAG techniques, check out! Advanced RAG Article Series
Advanced RAG Series Repository → Visit Repo Here!
Conclusion:
Just Explained my learning’s on CHAIN OF THOUGHT Technique ! if you find it useful then don’t forget to like this Article & Follow Me for more such informative Articles.
Credits:
Credits: I am very grateful to ChaiCode for Providing all this knowledge, Insights , Deep Learning about AI : Piyush Garg Hitesh Choudhary
If you want to learn too, you can Join here → Cohort || Apply from ChaiCode & Use NAKUL51937 to get 10% off
Thanks:
Feel free to Comment your thoughts, Would love to hear your feedback!
Thanks for Giving your Precious time , reading this article.
Connect on other Platforms:
Let’s learn something Together: LinkedIn , Twitter
If you would like , you can Check out my Portfolio
Subscribe to my newsletter
Read articles from Nakul Srivastava directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Nakul Srivastava
Nakul Srivastava
I'm a passionate web developer who loves building beautiful, functional, and efficient web applications. I focus on crafting seamless user experiences using modern frontend technologies.