<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tostisto</title>
    <description>The latest articles on DEV Community by Tostisto (@tostisto).</description>
    <link>https://dev.to/tostisto</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F394748%2Fa3ba843b-48f2-4171-bf34-55d9868b2a1e.png</url>
      <title>DEV Community: Tostisto</title>
      <link>https://dev.to/tostisto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tostisto"/>
    <language>en</language>
    <item>
      <title>Building a RAG Agent with .NET Aspire</title>
      <dc:creator>Tostisto</dc:creator>
      <pubDate>Tue, 24 Nov 2026 11:42:53 +0000</pubDate>
      <link>https://dev.to/tostisto/building-a-rag-agent-with-net-aspire-2hno</link>
      <guid>https://dev.to/tostisto/building-a-rag-agent-with-net-aspire-2hno</guid>
      <description>&lt;p&gt;Retrieval-augmented generation sounds complicated, but the core idea fits in a small app: find the right pieces of your docs, hand them to a model, and let it answer from them. This post walks through a small example that does exactly that, running locally with Aspire, Ollama and Qdrant.&lt;/p&gt;

&lt;h2&gt;
  
  
  The example
&lt;/h2&gt;

&lt;p&gt;The app reads a folder of Markdown pages, splits them into chunks and stores them in Qdrant. When you ask a question, an agent searches those chunks and answers only from what it found, with links to the pages it used.&lt;/p&gt;

&lt;p&gt;The sample content is the &lt;a href="https://github.com/microsoft/vscode/wiki" rel="noopener noreferrer"&gt;VS Code wiki&lt;/a&gt;, pulled into the repo as a git submodule. It is real documentation, but small enough to index quickly.&lt;/p&gt;

&lt;p&gt;Everything runs on your machine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Aspire starts all the pieces with a single command.&lt;/li&gt;
&lt;li&gt;Ollama runs the models: &lt;code&gt;llama3.2:3b&lt;/code&gt; for chat and &lt;code&gt;nomic-embed-text&lt;/code&gt; for embeddings.&lt;/li&gt;
&lt;li&gt;Qdrant holds the vectors.&lt;/li&gt;
&lt;li&gt;Microsoft.Extensions.AI, Microsoft.Extensions.VectorData and Microsoft Agent Framework tie it together in .NET.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full code is on GitHub: &lt;a href="https://github.com/Tostisto/dotnet-aspire-rag" rel="noopener noreferrer"&gt;Tostisto/dotnet-aspire-rag&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it fits together
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjriws6cw7cl78uccefvh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjriws6cw7cl78uccefvh.png" alt="Architecture overview" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aspire starts Qdrant, Ollama and both apps. The ingestion worker runs first and exits, and only then does the API start, so it never answers from an empty index.&lt;/p&gt;

&lt;p&gt;Inside each app the code follows Clean Architecture. The core only knows small interfaces like &lt;code&gt;IKnowledgeBase&lt;/code&gt; and &lt;code&gt;IAssistant&lt;/code&gt;, while Qdrant, Ollama and the agent framework live in the Infrastructure project. A few architecture tests break the build if that rule is ever broken.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two ways to retrieve
&lt;/h2&gt;

&lt;p&gt;There are two common ways to wire retrieval into an agent, and the API lets you pick one per request with the &lt;code&gt;mode&lt;/code&gt; field:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Always&lt;/code&gt; is classic RAG. Search first, then put the results into the prompt.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;OnDemand&lt;/code&gt; is agentic RAG. The model gets a &lt;code&gt;search_docs&lt;/code&gt; tool and decides for itself when to use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Agent Framework's &lt;code&gt;TextSearchProvider&lt;/code&gt; handles both, so switching is a single option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;searchProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextSearchProvider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextSearchProviderOptions&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;SearchTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strategy&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;RetrievalStrategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OnDemand&lt;/span&gt;
            &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;TextSearchBehavior&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OnDemandFunctionCalling&lt;/span&gt;
            &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;TextSearchBehavior&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BeforeAIInvoke&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;FunctionToolName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"search_docs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chatClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsAIAgent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ChatClientAgentOptions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ChatOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ChatOptions&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Instructions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AssistantPolicy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Instructions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;AIContextProviders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;searchProvider&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;search&lt;/code&gt; function behind it calls Qdrant and remembers which pages came back. Those pages become the citations in the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons learned
&lt;/h2&gt;

&lt;p&gt;The biggest surprise was how much the choice of model mattered. In &lt;code&gt;OnDemand&lt;/code&gt; mode the first model often skipped the search completely and just replied "I don't know". To see how bad it was, the same prompt and tool went to three local models, with eight questions the wiki can answer:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Searched (of 8)&lt;/th&gt;
&lt;th&gt;Time per decision&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;qwen3:4b-instruct&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;under 1 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;qwen3:4b&lt;/code&gt; (thinking)&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;about 5 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;llama3.2:3b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;about 0.2 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No amount of prompt tweaking fixed &lt;code&gt;qwen3:4b-instruct&lt;/code&gt;. Switching to &lt;code&gt;llama3.2:3b&lt;/code&gt; did, and since then the integration tests pass in both modes.&lt;/p&gt;

&lt;p&gt;A few other things worth knowing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thinking models are slow for chat. The thinking variant of qwen3 took 10 to 20 seconds per answer, the instruct one about a second.&lt;/li&gt;
&lt;li&gt;Chunks need context. Many wiki pages have no title heading, so each chunk now starts with its page title and heading path, like &lt;code&gt;Coding Guidelines &amp;gt; Names&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Some words are just noise. Every page mentions VS Code, so a question containing "VS Code" kept pulling in roadmap pages. The same question without those two words found the right section.&lt;/li&gt;
&lt;li&gt;Hybrid search did not help here. Keyword matching on words like "code" hits almost every page, so it made results worse and was taken out.&lt;/li&gt;
&lt;li&gt;Local models need longer timeouts. Aspire's default of 30 seconds cut off slower model calls.&lt;/li&gt;
&lt;li&gt;Tests need stable answers. Temperature 0 and a fixed seed made the integration tests repeatable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;You need the .NET 10 SDK, Docker, Ollama and the Aspire CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone --recurse-submodules https://github.com/Tostisto/dotnet-aspire-rag.git
&lt;span class="nb"&gt;cd&lt;/span&gt; dotnet-aspire-rag
aspire run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first run downloads the models, so give it a few minutes. Then open the Scalar link on the &lt;code&gt;api&lt;/code&gt; resource in the Aspire dashboard and ask something:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ask&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"question"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Do we indent code with tabs or spaces?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"mode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OnDemand"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get the answer together with the page it came from: "We use tabs, not spaces [Coding Guidelines]." The dashboard shows each model call, tool call and search as a trace, which is the easiest way to see what the agent actually did.&lt;/p&gt;

&lt;p&gt;Want to try it on your own docs? Add a folder of Markdown files under &lt;code&gt;Documents:Folders&lt;/code&gt; in the AppHost settings.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>aspire</category>
      <category>rag</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
