Debug a RAG pipeline in Spring AI: what was retrieved and what the model saw
A wrong answer from a RAG app has at least four possible causes. Most of them are invisible unless you can see the retrieval and the final prompt side by side.
Four ways a RAG answer goes wrong
- The vector search returned nothing useful, or only low-scoring chunks.
- It found the right chunk, but the chunk never made it into the prompt.
- The prompt was fine, but the answer was cut off by the output token limit.
- The prompt grew close to the model’s context limit, so something had to give.
Looking only at the final answer, these all look the same. You change the prompt, re-run, and hope.
Put the whole question on one trace
With Spring AI 2.0 in your app and Causeline switched on, chat calls and vector searches join the request’s trace, streaming included, with no extra setup. Click a search or a chat span and the RAG panel follows that question through:
- the query that was sent to the vector store,
- the ranked chunks, each with its score,
- the final prompt, with each chunk marked In prompt or Not in prompt,
- the answer, with its input and output tokens and finish reason.
A chunk that was retrieved but never reached the model is the one you would never find from the answer alone. Here it is marked in plain sight.
Hints that name the cause
Plain rules, with no model involved, read the same trace and flag the common problems: an empty retrieval, low relevance, duplicate chunks, a chunk that missed the prompt, an answer cut off by its token limit, a context near the model’s limit, and the same text embedded twice.
Answer cut offThe chat call stopped at its output token limit before finishing.
Two settings tune them to your setup: causeline.ai.low-score for what counts as a low score in your store (default 0.5), and causeline.ai.context-limit for your model’s context size.
If your RAG lives in Python
Many teams keep the retrieval and the model in a FastAPI service with LangChain and call it from Spring Boot. The causeline package on PyPI puts that service in the same trace, and its LangChain calls show up in the same RAG panel, with the same hints.
import causeline from fastapi import FastAPI causeline.init(endpoint="http://localhost:8080", service="ai-service") app = FastAPI() causeline.instrument(app)
Your prompts stay with you
Prompts, answers and retrieved documents can contain anything. Causeline shows them in the local UI and withholds them from everything that leaves the app: exports, bug reports and what coding agents read over MCP get the metadata only. Each kind of text can be switched off with causeline.capture.ai.*. Causeline never runs a model and never caches or fakes a response.
Because a replay would call the real model again, a replay from the UI warns first, and load runs and agent replays are refused until you allow them.
What has and hasn’t been tested
This has been tested against Spring AI’s in-memory vector store and a fake model server. Other vector stores use the same Spring AI hooks, but they haven’t each been verified yet, so treat them as likely to work rather than certain. It is an alpha, and reports from real setups are welcome on GitHub.