This free, MIT-licensed Cursor rule makes Cursor write production-grade .NET RAG code by default —
provider-agnostic embeddings, pgvector storage, sane chunking, and prompts that refuse to hallucinate. Drop
the .mdc into .cursor/rules/ and it applies automatically to your C# files.
What it does
Retrieval-augmented generation has a dozen small decisions that quietly wreck quality: binding to a
provider SDK instead of an abstraction, mismatching the embedding dimension against the vector column,
skipping chunk overlap, or letting the model answer from general knowledge. This rule encodes the correct
default for each, scoped to **/*.cs, so Cursor stops suggesting the footguns and starts producing the
shape of code you actually want to ship. It is opinionated on purpose: one obvious way to do each step,
matching how a careful team would build a RAG service in .NET.
What it gets right
The rule steers Cursor toward the Microsoft.Extensions.AI abstractions (IChatClient,
IEmbeddingGenerator) so your feature code never couples to a single provider's SDK — swapping models
becomes a config change, not a refactor. It insists the pgvector column dimension match the embedding
model exactly, because a silent mismatch is the single most common way teams ship a search index that
returns nonsense. It standardises chunking at roughly 512 tokens with 64 overlap, retrieval at top-k of
five by cosine similarity, and a system prompt that answers strictly from retrieved context and says "I
don't know" otherwise. Finally it nudges toward streaming responses over SSE with inline citations, and a
Result<T> return shape instead of exceptions for expected failures.
The rule
- Use Microsoft.Extensions.AI (IChatClient, IEmbeddingGenerator); never bind to a provider SDK.
- Store embeddings in pgvector; match the vector dimension to the model exactly.
- Chunk ~512 tokens / ~64 overlap; strip nav/footer; extract from <article>/<main>.
- Retrieve top-k=5 by cosine; answer ONLY from context, else "I don't know".
- Stream via GetStreamingResponseAsync over SSE with citations.
- Return Result<T>; respect the tenant filter on every query.
How to install it
Save it as .cursor/rules/dotnet-rag-pipeline.mdc in your project. The globs field scopes it to C#
files; set alwaysApply: true if you want it on every request. It pairs well with the AIML.chat MCP
server and the Connect Linear MCP agent skill when you're building the
surrounding tooling, and with the MCP docs for connecting tools to an agent.
Building an AI assistant on top of this? Start free, or compare limits on pricing.
How do I add this rule to Cursor?+
Save it under .cursor/rules/ in your repo. Cursor picks it up automatically and applies it to files matching the globs.
Does it work with the AIML.chat MCP server?+
Yes — it's written for exactly this stack. See the MCP docs for connecting tools.
Is it free?+
Yes, MIT-licensed. The AIML.chat product it's built for has a free plan; see pricing.