spring-ai-rag-demo-module

spring-ai-rag-demo-module is a cursor rule for Cursor from ly1836/spring-ai-rag-demo. It costs 1,633 tokens per session, scanned A, original, Apache-2.0.

A set of architecture and coding rules for a single-module Spring Boot application that combines AI document search with business-system tools.

In plain words
What is it for?
Use it when adding chat, billing, conversation history, ERP tools, configuration, shared request types, or static front-end files to this project. RAG means finding relevant documents to provide context to an AI response.
Why use it?
It keeps new code in the expected packages and preserves constraints such as tenant separation, billing, database access, and the application’s front-end structure.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when adding chat, billing, conversation history, ERP tools, configuration, shared request types, or static front-end files to this project. RAG means finding relevant documents to provide context to an AI response.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/ly1836/spring-ai-rag-demo/spring-ai-rag-demo-module
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/ly1836/spring-ai-rag-demo

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for spring-ai-rag-demo-module

README.md
[![agentmods](https://agentmods.dev/badge/rules/ly1836/spring-ai-rag-demo/spring-ai-rag-demo-module/github.svg)](https://agentmods.dev/rules/ly1836/spring-ai-rag-demo/spring-ai-rag-demo-module)
Your own site
<a href="https://agentmods.dev/rules/ly1836/spring-ai-rag-demo/spring-ai-rag-demo-module"><img src="https://agentmods.dev/badge/rules/ly1836/spring-ai-rag-demo/spring-ai-rag-demo-module/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for spring-ai-rag-demo-module

Your own site · 80×15
<a href="https://agentmods.dev/rules/ly1836/spring-ai-rag-demo/spring-ai-rag-demo-module"><img src="https://agentmods.dev/badge/rules/ly1836/spring-ai-rag-demo/spring-ai-rag-demo-module.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 1,633 This file is loaded in full into every session.
When invoked 1,633 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.01633 $0.01633
Opus 5 $0.00816 $0.00816
Sonnet 5 $0.00327 $0.00327
Haiku 4.5 $0.00163 $0.00163

Measured 10d ago against content hash 4f4318ed6d7f, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

spring-ai-rag-demo-module scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 10d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/spring-ai-rag-demo-module.mdc · 71 lines

How it starts

The opening of the file, as written. The whole thing — 71 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Spring AI RAG Demo 项目规则

实施新功能前,先阅读 openspec/context/spring-ai-rag-demo.md 了解架构、租户隔离与计费扣费约束。

  • 项目类型: 单模块 Spring Boot 应用(非多模块 monorepo,无模块前缀概念)
  • 根包: com.example.rag
  • 启动类: com.example.rag.RagDemoApplication
  • 核心能力: Tool Calling(@Tool 查 ERP MySQL)+ RAG(PgVector 检索产品手册)+ 多模型路由

通用编码约定见 openspec/config.yaml

设计文档

  • 项目 context:openspec/context/spring-ai-rag-demo.md
  • 通用配置:openspec/config.yaml
  • 变更文档:openspec/changes/<change-name>/(按业务域命名,如 chat-add-stream-modebilling-monthly-quotatool-purchase-order
  • OpenSpec CLI:在仓库根目录执行(如 openspec list

业务域包结构

新增功能落到与业务语义一致的子包,避免根包堆积:

  • chat/ — 智能问答入口(ChatController、ErpAssistantService、DocumentLoaderService、ModelRegistry)
  • billing/ — 计费账户、配额校验、token 扣费、充值
  • conversation/ — 对话历史、ChatMemory、JdbcChatMemoryRepository
  • tool/ — ERP @Tool 方法集合(继承 BaseTool,按业务域拆分文件)
  • config/ — 数据源、过滤器、租户上下文、全局异常、模型属性
  • vo/ — 跨业务域共享的请求/响应 VO(同业务域内部 record 嵌套在 XxxVO 类中)
  • src/main/resources/static/ — 前端资源(index.html / app.js / style.css / vendor/),前后端一体部署,无独立前端工程

要求

  • 多租户隔离:所有 ERP 查询必须继承 tool/BaseTool 并通过 query() / queryWithAlias() 执行 SQL,禁止直接使用 erpJdbcTemplate.queryXxx() 绕过 ent_code 注入
  • 租户上下文:通过 TenantContext.requireEntCode() / TenantContext.getUserIdOrDefault() 读取,禁止从 Controller 参数或 Header 中重复解析;新建异步/响应式链路必须经过 TenantContextAccessor 透传,否则 reactor 线程切换后 ent_code 会丢失
  • 统一响应:REST 接口返回 RespVO<T>(SSE 流式接口除外),业务异常直接抛出 IllegalStateException/IllegalArgumentException,由 GlobalExceptionHandler 兜底转 RespVO.error禁止在 Controller/Service 内自行 try-catch 包装错误码
  • 数据源:VectorStore 自动配置依赖 @Primary 的 PgVector 数据源;ERP 业务查询必须注入 @Qualifier("erpJdbcTemplate") JdbcTemplate
  • ChatModel 路由:多模型场景统一通过 ModelRegistrymodelId 路由,禁止在业务代码中直接注入 deepSeekChatModel / openAiChatModel 等特定 provider Bean
  • 计费扣费:每次 LLM 调用入口前置 BillingService.checkQuota(),调用后按 Usage 调用 BillingService.deductTokens();新增问答模式(mode)时必须走相同的前后置流程
  • SQL 参数化:严禁 SQL 字符串拼接动态值,全部通过 ? 占位 + 参数列表传入
  • 依赖注入:使用构造器注入 + private final 字段,禁止 @Autowired 字段注入

Read the full file on GitHub · 71 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 10d ago First seen · 71 lines · 1,633 tokens per session scan A 4f4318ed6d7f

Subscribe to this mod's changes

spring-ai-rag-demo-module is a cursor rule published in the GitHub repository ly1836/spring-ai-rag-demo (86 stars, last pushed yesterday), licensed Apache-2.0. It adds 1,633 tokens to every session, about $0.0082 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.