Build a Star Wars Copilot in C# - Lesson 6: RAG from a Database

Jim Bennett | Mar 10, 2026

By lesson 6, we already have an MCP server and client working.

Now we add a classic enterprise use case: retrieval from structured business data.

Lessons in this series

Lesson
Lesson 0: Self-Setup
Lesson 1: Chat with an LLM
Lesson 2: Chat History and System Prompts
Lesson 3: Model Choice and Local Models
Lesson 4: Tool Calling
Lesson 5: MCP (Model Context Protocol)
Lesson 6: RAG from a Database
Lesson 7: Multimodal Image Generation
Lesson 8: Agents and Orchestration

Before you start (self-setup)

If you’re following along on your own, complete lesson 0 and lesson 5 first.

This lesson introduces a new Azure dependency: Storage Tables.

Self-setup: Azure Table Storage + seed data

  1. Create a Storage account in Azure.
  2. In that account, create three tables:
    • Figurines
    • Orders
    • OrderFigurines
  3. Get a connection string and save it:
dotnet user-secrets set "AzureStorage:ConnectionString" "<your-storage-connection-string>"
  1. Seed the data.
    • The workshop repo includes a dataloader project in 6-rag/dataloader you can run to populate sample data.
    • If you prefer, you can insert rows manually with Storage Explorer.

Quick verification: confirm order 66 exists before testing StarWarsPurchaseTool.

What this lesson adds

A new MCP tool (StarWarsPurchaseTool) that queries Azure Table Storage to retrieve figurine order data.

The model can then answer questions like:

  • what was in order 66?
  • what did Ben Smith purchase?
  • show orders for a specific character

A lot of people hear “RAG” and think vector DB + embeddings.

This lesson is a good reminder that RAG simply means augmenting generation with retrieved data, and that retrieval source can be:

  • relational/NoSQL tables
  • APIs
  • docs
  • search systems

Here it’s plain table queries plus deterministic filtering logic.

Data shape and tool design

The workshop uses three tables:

  • Figurines
  • Orders
  • OrderFigurines

The tool accepts optional filters:

  • orderNumber
  • characterName
  • customerName

Then combines data into a JSON payload the model can reason over.

This is exactly the pattern I like for production tools: perform strict filtering in code, let the model focus on explanation and narrative.

Practical implementation notes

The lesson adds:

  • Azure.Data.Tables package
  • helper functions for query composition
  • explicit error responses for bad inputs / no matches

The case-sensitive lookup note in the workshop is also an important real-world reminder: retrieval quality starts with query normalization rules.

Suggested banner prompt

A high-detail sci-fi data-vault scene with holographic tables of orders and figurines floating above a console while an AI assistant correlates records into a clear response stream. Cool cyan and purple palette, cinematic lighting, no text, no logos.

Follow along

Workshop source for this lesson: Lesson 6 README.

Next up: multi-modal AI with image generation tools.

Note: Original workshop repository: jimbobbennett/StarWarsCopilot.