Skip to main content
LangWatch tracks the optimization of a RAG application built with DSPy, step by step.

DSPy RAG Module

The example RAG application is the sample app from the official DSPy documentation. For more detail, see the RAG tutorial. Firstly, lets access the dataset of wiki abstracts that will be used for example RAG optimization.
Next step - to define the RAG module itself. You can explain the task and what the expected outputs mean in this context that an LLM can optimize these commands later.
Finally, you can connect to LangWatch. After running this code snippet - you will get a link that will give you access to an api_key in the browser. Paste the API key into your code editor popup and press enter - now you are connected to LangWatch.
Last step is to actually run the prompt optitmizer. In this example BootstrapFewShot is used and it will bootstrap our prompt with the best demos from our dataset.
The result of optimization can be found on your LangWatch dashboard. On the graph you can see how many demos were boostrapped during the first optimization step.
DSPy Experiment Dashboard

DSPy Experiment Dashboard

Additionally, you can see each LLM call that has been done during the optimization with the corresponding costs and token counts.
DSPy LLM calls

DSPy LLM calls

Open in Notebook

You can access and run the code yourself in Jupyter Notebook
Last modified on August 23, 2026