<?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: ahmed manai</title>
    <description>The latest articles on DEV Community by ahmed manai (@ahmed_manai).</description>
    <link>https://dev.to/ahmed_manai</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%2F4264528%2F1887bd35-7c23-440d-86e3-6e746ab64c79.jpg</url>
      <title>DEV Community: ahmed manai</title>
      <link>https://dev.to/ahmed_manai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmed_manai"/>
    <language>en</language>
    <item>
      <title>I built a local RAG server for Claude and Copilot in C#. Here is what I learned about search.</title>
      <dc:creator>ahmed manai</dc:creator>
      <pubDate>Thu, 26 Nov 2026 09:25:16 +0000</pubDate>
      <link>https://dev.to/ahmed_manai/i-built-a-local-rag-server-for-claude-and-copilot-in-c-here-is-what-i-learned-about-search-2h3</link>
      <guid>https://dev.to/ahmed_manai/i-built-a-local-rag-server-for-claude-and-copilot-in-c-here-is-what-i-learned-about-search-2h3</guid>
      <description>&lt;p&gt;I wanted Claude and GitHub Copilot to answer questions from my own notes and documentation, without uploading anything. So I built &lt;a href="https://github.com/Ahmed-Manai/docs-rag-mcp" rel="noopener noreferrer"&gt;docs-rag-mcp&lt;/a&gt;, an MCP server in C# that indexes a folder of documents and lets any MCP client search it.&lt;/p&gt;

&lt;p&gt;You point it at a folder of Markdown, text, HTML, Word or PDF files. It splits them into passages, embeds each passage, and stores everything in one SQLite file. When you ask your assistant a question, it calls &lt;code&gt;search_docs&lt;/code&gt; and answers from the passages it gets back, with the file and section for each one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add docs-rag -- dnx DocsRagMcp --yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In VS Code and Cursor, the &lt;a href="https://github.com/Ahmed-Manai/docs-rag-mcp#quick-start-local-with-ollama" rel="noopener noreferrer"&gt;README&lt;/a&gt; has one-click install buttons.&lt;/p&gt;

&lt;p&gt;With Ollama, nothing leaves your machine. It also works with OpenAI and Azure OpenAI embeddings.&lt;/p&gt;

&lt;p&gt;Getting a basic pipeline working is the easy part. Making the results good is harder, and that is what this post is about.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Split documents the way their authors did
&lt;/h2&gt;

&lt;p&gt;Most RAG tutorials cut text into fixed-size chunks. That loses the most useful piece of information a document has: which section a sentence belongs to.&lt;/p&gt;

&lt;p&gt;docs-rag-mcp splits Markdown, HTML and Word files at their headings first, and PDFs by page. Each passage remembers its location, such as &lt;code&gt;remote-work.md &amp;gt; Working from another country&lt;/code&gt;. Only then are long sections cut into chunks, at paragraph boundaries where possible, with a small overlap.&lt;/p&gt;

&lt;p&gt;Each format has its own traps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Markdown&lt;/strong&gt;: lines starting with &lt;code&gt;#&lt;/code&gt; inside code blocks are not headings. YAML front matter from Jekyll, Hugo or Obsidian is not content, but its &lt;code&gt;title&lt;/code&gt; is a good name for the text before the first heading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTML&lt;/strong&gt;: a saved page is mostly navigation. Reading only the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; element when a page has one removes sidebars and "Skip to main content" links without any site-specific rules. But a page's &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; is chrome, while an article's &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; usually holds its &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, so the rule depends on where it sits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Word&lt;/strong&gt;: style ids are translated. A German Word writes &lt;code&gt;berschrift1&lt;/code&gt; instead of &lt;code&gt;Heading1&lt;/code&gt;. The style &lt;em&gt;names&lt;/em&gt; are always &lt;code&gt;heading 1&lt;/code&gt; in English, so headings are found by name. A &lt;code&gt;.docx&lt;/code&gt; file is just a zip of XML, so this needed no extra library.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Embed each chunk with its context
&lt;/h2&gt;

&lt;p&gt;A passage like "Up to 220 EUR in Paris" is useless on its own. Which budget? Which policy?&lt;/p&gt;

&lt;p&gt;Before a chunk is embedded, the server puts the file name and heading in front of it: &lt;code&gt;travel-and-expenses.md &amp;gt; Hotels&lt;/code&gt;. The vector then carries the context, and the passage matches a question about hotel budgets even though it never says "hotel".&lt;/p&gt;

&lt;p&gt;This was the cheapest improvement in the whole project.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Meaning is not enough: hybrid search
&lt;/h2&gt;

&lt;p&gt;Embeddings match meaning, which is why "Can I spend a month working from Spain?" finds a section about "working from another country for up to 30 days a year". Neither "Spain" nor "month" appears in it.&lt;/p&gt;

&lt;p&gt;But meaning is fuzzy where developers need precision. In testing, a question about pages that "require a login" matched a page about &lt;em&gt;logging&lt;/em&gt;. API names, error codes and option names need exact matching.&lt;/p&gt;

&lt;p&gt;So every chunk is also indexed with SQLite's built-in FTS5 full-text search, with porter stemming and headings weighted twice as much as body text. A search scores candidates both ways, scales both scores to 0..1, and blends them: 90% meaning, 10% keywords.&lt;/p&gt;

&lt;p&gt;The obvious choice was reciprocal rank fusion, the usual way to combine two rankings. I tried it first, and it made results worse: any passage that shared a word with the question could beat the best meaning match, and plain-language questions suffered. A small keyword weight settles close calls without outvoting a clearly better match.&lt;/p&gt;

&lt;p&gt;I measured this instead of guessing. The repository has two evaluation sets: 14 employee questions about a sample handbook, and 22 developer questions about the MCP C# SDK documentation (30 pages, 556 chunks), each with the page that answers it. With Ollama and &lt;code&gt;nomic-embed-text&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Search mode&lt;/th&gt;
&lt;th&gt;Handbook: right section first&lt;/th&gt;
&lt;th&gt;SDK docs: right page in the top 3&lt;/th&gt;
&lt;th&gt;SDK docs: mean reciprocal rank&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Vector only&lt;/td&gt;
&lt;td&gt;14 of 14&lt;/td&gt;
&lt;td&gt;15 of 22&lt;/td&gt;
&lt;td&gt;0.61&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hybrid&lt;/td&gt;
&lt;td&gt;14 of 14&lt;/td&gt;
&lt;td&gt;17 of 22&lt;/td&gt;
&lt;td&gt;0.66&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both sets are small, so I read these as a direction, not a benchmark. Keywords help most when the question names the feature, such as cancellation or elicitation, and can't help when the question shares no distinctive word with the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Keep the index in sync without trusting file events
&lt;/h2&gt;

&lt;p&gt;An index that is out of date gives confident wrong answers. So indexed folders are watched with &lt;code&gt;FileSystemWatcher&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;File system events are unreliable. They arrive in bursts, can be dropped when too many happen at once, and behave differently on Windows, macOS and Linux. Handling them one by one is a bug factory.&lt;/p&gt;

&lt;p&gt;Instead, an event only means "something changed". The watcher waits until the folder has been quiet for 2 seconds, then runs the normal sync. The sync compares each file's SHA-256 with the stored hash, so it only re-embeds files whose content actually changed. When the server starts, it runs the same sync once per folder to catch up on changes made while it was off.&lt;/p&gt;

&lt;p&gt;One code path for indexing, re-indexing and watching meant one code path to test.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. No vector database
&lt;/h2&gt;

&lt;p&gt;Vectors are stored as blobs in SQLite and compared with &lt;code&gt;TensorPrimitives.CosineSimilarity&lt;/code&gt;, which uses SIMD. Brute force sounds naive, but for personal and team document sets, up to tens of thousands of chunks, it is fast and needs no native extension. The whole index is one file you can delete or copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small details that matter
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The index remembers its embedding model.&lt;/strong&gt; Vectors from different models can't be compared, so searching with another model is refused instead of returning nonsense.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Folder limits.&lt;/strong&gt; &lt;code&gt;DOCSRAG_ALLOWED_PATHS&lt;/code&gt; stops an assistant from indexing your home folder. Paths are resolved before the check, so &lt;code&gt;docs/../secrets&lt;/code&gt; doesn't get around it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;list_sources&lt;/code&gt; says where the index is and which model built it.&lt;/strong&gt; When results look wrong, that is the first thing to check.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I would tell someone building their own
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Keep structure. Headings are the best metadata you will get for free.&lt;/li&gt;
&lt;li&gt;Put context into the embedded text, not only into metadata.&lt;/li&gt;
&lt;li&gt;Write down 20 real questions with known answers before tuning anything. Every change I made was decided by that list.&lt;/li&gt;
&lt;li&gt;Treat file events as hints, not facts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;docs-rag-mcp is open source (MIT), on &lt;a href="https://www.nuget.org/packages/DocsRagMcp" rel="noopener noreferrer"&gt;NuGet&lt;/a&gt; and in the official MCP Registry. Issues and pull requests are welcome, and if it is useful to you, a star on &lt;a href="https://github.com/Ahmed-Manai/docs-rag-mcp" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; helps other people find it.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>rag</category>
      <category>dotnet</category>
      <category>ai</category>
    </item>
    <item>
      <title>Local RAG server for Claude and Copilot in C#. Here is what I learned about search</title>
      <dc:creator>ahmed manai</dc:creator>
      <pubDate>Wed, 25 Nov 2026 11:16:47 +0000</pubDate>
      <link>https://dev.to/ahmed_manai/local-rag-server-for-claude-and-copilot-in-c-here-is-what-i-learned-about-search-49d</link>
      <guid>https://dev.to/ahmed_manai/local-rag-server-for-claude-and-copilot-in-c-here-is-what-i-learned-about-search-49d</guid>
      <description>&lt;p&gt;I wanted Claude and GitHub Copilot to answer questions from my own notes and documentation, without uploading anything. So I built &lt;a href="https://github.com/Ahmed-Manai/docs-rag-mcp" rel="noopener noreferrer"&gt;docs-rag-mcp&lt;/a&gt;, an MCP server in C# that indexes a folder of documents and lets any MCP client search it.&lt;/p&gt;

&lt;p&gt;You point it at a folder of Markdown, text, HTML, Word or PDF files. It splits them into passages, embeds each passage, and stores everything in one SQLite file. When you ask your assistant a question, it calls &lt;code&gt;search_docs&lt;/code&gt; and answers from the passages it gets back, with the file and section for each one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add docs-rag -- dnx DocsRagMcp --yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Ollama, nothing leaves your machine. It also works with OpenAI and Azure OpenAI embeddings.&lt;/p&gt;

&lt;p&gt;Getting a basic pipeline working is the easy part. Making the results good is harder, and that is what this post is about.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Split documents the way their authors did
&lt;/h2&gt;

&lt;p&gt;Most RAG tutorials cut text into fixed-size chunks. That loses the most useful piece of information a document has: which section a sentence belongs to.&lt;/p&gt;

&lt;p&gt;docs-rag-mcp splits Markdown, HTML and Word files at their headings first, and PDFs by page. Each passage remembers its location, such as &lt;code&gt;remote-work.md &amp;gt; Working from another country&lt;/code&gt;. Only then are long sections cut into chunks, at paragraph boundaries where possible, with a small overlap.&lt;/p&gt;

&lt;p&gt;Each format has its own traps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Markdown&lt;/strong&gt;: lines starting with &lt;code&gt;#&lt;/code&gt; inside code blocks are not headings. YAML front matter from Jekyll, Hugo or Obsidian is not content, but its &lt;code&gt;title&lt;/code&gt; is a good name for the text before the first heading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTML&lt;/strong&gt;: a saved page is mostly navigation. Reading only the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; element when a page has one removes sidebars and "Skip to main content" links without any site-specific rules. But a page's &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; is chrome, while an article's &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; usually holds its &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, so the rule depends on where it sits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Word&lt;/strong&gt;: style ids are translated. A German Word writes &lt;code&gt;berschrift1&lt;/code&gt; instead of &lt;code&gt;Heading1&lt;/code&gt;. The style &lt;em&gt;names&lt;/em&gt; are always &lt;code&gt;heading 1&lt;/code&gt; in English, so headings are found by name. A &lt;code&gt;.docx&lt;/code&gt; file is just a zip of XML, so this needed no extra library.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Embed each chunk with its context
&lt;/h2&gt;

&lt;p&gt;A passage like "Up to 220 EUR in Paris" is useless on its own. Which budget? Which policy?&lt;/p&gt;

&lt;p&gt;Before a chunk is embedded, the server puts the file name and heading in front of it: &lt;code&gt;travel-and-expenses.md &amp;gt; Hotels&lt;/code&gt;. The vector then carries the context, and the passage matches a question about hotel budgets even though it never says "hotel".&lt;/p&gt;

&lt;p&gt;This was the cheapest improvement in the whole project.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Meaning is not enough: hybrid search
&lt;/h2&gt;

&lt;p&gt;Embeddings match meaning, which is why "Can I spend a month working from Spain?" finds a section about "working from another country for up to 30 days a year". Neither "Spain" nor "month" appears in it.&lt;/p&gt;

&lt;p&gt;But meaning is fuzzy where developers need precision. In testing, a question about pages that "require a login" matched a page about &lt;em&gt;logging&lt;/em&gt;. API names, error codes and option names need exact matching.&lt;/p&gt;

&lt;p&gt;So every chunk is also indexed with SQLite's built-in FTS5 full-text search, with porter stemming and headings weighted twice as much as body text. A search scores candidates both ways, scales both scores to 0..1, and blends them: 90% meaning, 10% keywords.&lt;/p&gt;

&lt;p&gt;The obvious choice was reciprocal rank fusion, the usual way to combine two rankings. I tried it first, and it made results worse: any passage that shared a word with the question could beat the best meaning match, and plain-language questions suffered. A small keyword weight settles close calls without outvoting a clearly better match.&lt;/p&gt;

&lt;p&gt;I measured this instead of guessing. The repository has two evaluation sets: 14 employee questions about a sample handbook, and 22 developer questions about the MCP C# SDK documentation (30 pages, 556 chunks), each with the page that answers it. With Ollama and &lt;code&gt;nomic-embed-text&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Search mode&lt;/th&gt;
&lt;th&gt;Handbook: right section first&lt;/th&gt;
&lt;th&gt;SDK docs: right page in the top 3&lt;/th&gt;
&lt;th&gt;SDK docs: mean reciprocal rank&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Vector only&lt;/td&gt;
&lt;td&gt;14 of 14&lt;/td&gt;
&lt;td&gt;15 of 22&lt;/td&gt;
&lt;td&gt;0.61&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hybrid&lt;/td&gt;
&lt;td&gt;14 of 14&lt;/td&gt;
&lt;td&gt;17 of 22&lt;/td&gt;
&lt;td&gt;0.66&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both sets are small, so I read these as a direction, not a benchmark. Keywords help most when the question names the feature, such as cancellation or elicitation, and can't help when the question shares no distinctive word with the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Keep the index in sync without trusting file events
&lt;/h2&gt;

&lt;p&gt;An index that is out of date gives confident wrong answers. So indexed folders are watched with &lt;code&gt;FileSystemWatcher&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;File system events are unreliable. They arrive in bursts, can be dropped when too many happen at once, and behave differently on Windows, macOS and Linux. Handling them one by one is a bug factory.&lt;/p&gt;

&lt;p&gt;Instead, an event only means "something changed". The watcher waits until the folder has been quiet for 2 seconds, then runs the normal sync. The sync compares each file's SHA-256 with the stored hash, so it only re-embeds files whose content actually changed. When the server starts, it runs the same sync once per folder to catch up on changes made while it was off.&lt;/p&gt;

&lt;p&gt;One code path for indexing, re-indexing and watching meant one code path to test.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. No vector database
&lt;/h2&gt;

&lt;p&gt;Vectors are stored as blobs in SQLite and compared with &lt;code&gt;TensorPrimitives.CosineSimilarity&lt;/code&gt;, which uses SIMD. Brute force sounds naive, but for personal and team document sets, up to tens of thousands of chunks, it is fast and needs no native extension. The whole index is one file you can delete or copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small details that matter
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The index remembers its embedding model.&lt;/strong&gt; Vectors from different models can't be compared, so searching with another model is refused instead of returning nonsense.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Folder limits.&lt;/strong&gt; &lt;code&gt;DOCSRAG_ALLOWED_PATHS&lt;/code&gt; stops an assistant from indexing your home folder. Paths are resolved before the check, so &lt;code&gt;docs/../secrets&lt;/code&gt; doesn't get around it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;list_sources&lt;/code&gt; says where the index is and which model built it.&lt;/strong&gt; When results look wrong, that is the first thing to check.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I would tell someone building their own
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Keep structure. Headings are the best metadata you will get for free.&lt;/li&gt;
&lt;li&gt;Put context into the embedded text, not only into metadata.&lt;/li&gt;
&lt;li&gt;Write down 20 real questions with known answers before tuning anything. Every change I made was decided by that list.&lt;/li&gt;
&lt;li&gt;Treat file events as hints, not facts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;docs-rag-mcp is open source (MIT), on &lt;a href="https://www.nuget.org/packages/DocsRagMcp" rel="noopener noreferrer"&gt;NuGet&lt;/a&gt; and in the official MCP Registry. Issues and pull requests are welcome, and if it is useful to you, a star on &lt;a href="https://github.com/Ahmed-Manai/docs-rag-mcp" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; helps other people find it.&lt;/p&gt;

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