Leanpub Header

Skip to main content

Production-Grade RAG with C# and .NET

Building Retrieval-Augmented Generation Systems with C#, the Microsoft Agent Framework, and Azure

This book is 100% completeLast updated on 2026-07-26

Build production-grade RAG systems in C# — from an 80-line Hello World to a fully deployed Azure pipeline with the Microsoft Agent Framework, MCP, GraphRAG, multi-agent orchestration, eval gates, and EU AI Act-ready audit trails. 668 pages, 25 chapters, one evolving enterprise project, every line of code runnable in .NET 10.

Minimum price

$34.99

$46.99

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

Buying multiple copies for your team? See below for a discount!

PDF
Discussion Forum
About

About

About the Book

Production-Grade RAG with C# and .NET is the complete guide to building Retrieval-Augmented Generation systems on the Microsoft stack — from an 80-line Hello World to a fully deployed, audited, EU AI Act-aware Azure pipeline.

Most RAG material is written for Python. This book is written for you: a .NET developer with a few years of C# experience who wants to ship something real with your company's data. Across seven parts, twenty-five chapters and 668 pages, you'll build Contoso SmartDocs, a running enterprise project that grows chapter by chapter into a production system spanning six document silos — powered by the Microsoft Agent Framework 1.14, Microsoft.Extensions.AI, Azure AI Search, Qdrant, Neo4j, and .NET 10 / C# 14.

You'll learn to:

  • Build the core pipeline component by component: embeddings, chunking with Anthropic's Contextual Retrieval, multimodal content, vector databases, indexing strategies, hybrid retrieval with RRF, reranking, and first-class SSE streaming
  • Add query intelligence: metadata filters, query construction, routing, and conversational multi-turn rewriting
  • Go beyond vectors with graph databases, hybrid storage, GraphRAG, LazyGraphRAG, and Vectorless RAG
  • Serve retrieval as a tool over the Model Context Protocol and orchestrate multi-agent RAG workflows with agentic memory
  • Ship it for real: a 100-query golden eval gate on every pull request, latency and cost optimization, drift and model migration, prompt-injection defense, grounded citations, EU AI Act audit logging, and a full Bicep-deployed Azure capstone

Every chapter ships runnable code in the companion repository. Every snippet traces to a specific file. Every sample compiles; all 458 tests pass on a clean clone. The architecture is deliberately clean — small, named interfaces with swappable implementations — so what you learn maps directly onto the system you need to build, not just the one in the book.

Nine appendices round it out: worked exercise solutions, a design-pattern flashcard set, a vector database comparison, embedding benchmarks, a Python-to-.NET Rosetta Stone for readers arriving from LangChain or LlamaIndex, a debugging decision tree, prompt patterns, and the math behind RAG.

This is the production-concerns RAG book the .NET ecosystem has been missing. If you can write C#, you can ship RAG.

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $81.00
    Suggested price
    $109
  • Up to 5 members

    Minimum price
    $128
    Suggested price
    $172
  • Up to 10 members

    Minimum price
    $245
    Suggested price
    $329
  • Up to 15 members

    Minimum price
    $349
    Suggested price
    $469
  • Up to 25 members

    Minimum price
    $525
    Suggested price
    $705

Bundle

Bundles that include this book

Author

About the Author

Rachid DAHIR

I design systems for the long haul.

As a software architect, technical author, and educator based in Morocco, I've spent more than a decade building enterprise-grade .NET solutions in financial services, healthcare, and large-scale enterprise environments — where reliability, performance, and clean architecture are not optional.

I write for developers who are ready to move past tutorials. My books share a deliberate standard: production-grade code only — no toy examples, no shortcuts that would never survive a code review; every concept explained, demonstrated, then practiced; every advanced topic taught with the same patience as an introductory one — because complexity is never an excuse for a poor explanation.

Whether you're a mid-career developer leveling up, a solution architect consolidating best practices, or an enterprise team standardizing modern .NET, my goal stays the same: clarity without compromise.

When I'm not writing code or prose, I explore mathematics, AI research, and natural health.

Contents

Table of Contents

Table of Contents

Front Matter
  • Preface
  • How to Read This Book
  • Read This First — RAG Vocabulary at a Glance
  • About the Author
Part I — Foundations
  1. The AI Landscape
  2. The .NET Toolkit for RAG Development
Part II — The RAG Pipeline
  1. Embeddings: Turning Text into Vectors
  2. Chunking and Contextual Retrieval
  3. Multimodal RAG
  4. Vector Databases
  5. Indexing Strategies
  6. The Retriever
  7. Reranking
  8. The Complete RAG Pipeline
Part III — Query Intelligence
  1. Metadata Filtering and Query Construction
  2. Query Routing and Conversational Queries
Part IV — Graph and Hybrid Storage
  1. Graph Databases for RAG
  2. Hybrid Databases
Part V — RAG Design Patterns
  1. Classic RAG Enhancements
  2. Vectorless RAG
  3. GraphRAG and LazyGraphRAG
  4. Model Context Protocol
  5. Agentic, Multi-Agent, and Memory
Part VI — Production Concerns
  1. Evaluation and Metrics
  2. Latency, Cost, and Performance
  3. Freshness, Drift, and Migration
  4. Security
  5. Trust by Design
Part VII — Capstone Project
  1. Production Capstone
Appendices
  • Appendix A — Practice Exercise Solutions
  • Appendix B — Design Pattern Quick Reference
  • Appendix C — Vector Database Comparison
  • Appendix D — Embedding Benchmark
  • Appendix E — Python → .NET Rosetta
  • Appendix F — Companion Repository Guide
  • Appendix G — Debugging Checklist
  • Appendix H — Prompt Engineering Patterns
  • Appendix I — The Math Behind RAG
  • Other Books You'll Enjoy
  • Index

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub