cosmosdb-best-practices by azurecosmosdb/cosmosdb-agent-kit
npx skills add https://github.com/azurecosmosdb/cosmosdb-agent-kit --skill cosmosdb-best-practices适用于 Azure Cosmos DB 应用程序的全面性能优化指南,包含 9 个类别共 60 多条规则,按影响优先级排序,以指导自动化重构和代码生成。
在以下情况下参考本指南:
| 优先级 | 类别 | 影响 | 前缀 |
|---|---|---|---|
| 1 | 数据建模 | 关键 | model- |
| 2 | 分区键设计 | 关键 | partition- |
| 3 | 查询优化 | 高 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
query- |
| 4 | SDK 最佳实践 | 高 | sdk- |
| 5 | 索引策略 | 中高 | index- |
| 6 | 吞吐量与扩展 | 中 | throughput- |
| 7 | 全球分布 | 中 | global- |
| 8 | 监控与诊断 | 低中 | monitoring- |
model-embed-related - 嵌入需要一起检索的相关数据model-reference-large - 当数据项过大时使用引用model-avoid-2mb-limit - 保持数据项远低于 2MB 限制model-id-constraints - 遵循 ID 值的长度和字符限制model-nesting-depth - 保持在 128 层嵌套深度限制内model-numeric-precision - 了解 IEEE 754 数字精度限制model-denormalize-reads - 对读密集型工作负载进行反规范化model-schema-versioning - 对文档模式进行版本控制model-type-discriminator - 对多态数据使用类型鉴别器model-json-serialization - 正确处理 Cosmos DB 文档的 JSON 序列化model-relationship-references - 使用 ID 引用配合瞬时水合处理文档关系partition-high-cardinality - 选择高基数分区键partition-avoid-hotspots - 均匀分布写入操作partition-hierarchical - 使用分层分区键以获得灵活性partition-query-patterns - 使分区键与查询模式保持一致partition-synthetic-keys - 在需要时创建合成键partition-key-length - 遵守分区键值的长度限制partition-20gb-limit - 为 20GB 逻辑分区限制做好规划query-avoid-cross-partition - 尽量减少跨分区查询query-use-projections - 仅投影所需字段query-pagination - 使用延续令牌进行分页query-avoid-scans - 避免全容器扫描query-parameterize - 使用参数化查询query-order-filters - 按选择性排序过滤器sdk-singleton-client - 将 CosmosClient 作为单例重用sdk-async-api - 使用异步 API 以提高吞吐量sdk-retry-429 - 使用重试间隔处理 429 错误sdk-connection-mode - 在生产环境中使用 Direct 模式sdk-preferred-regions - 配置首选区域sdk-excluded-regions - 排除出现问题的区域sdk-availability-strategy - 为弹性配置可用性策略sdk-circuit-breaker - 使用断路器实现容错sdk-diagnostics - 记录诊断信息以便故障排除sdk-serialization-enums - 将枚举序列化为字符串而非整数sdk-emulator-ssl - 为 Cosmos DB 模拟器配置 SSL 和连接模式sdk-java-content-response - 在写入操作上启用内容响应(Java)sdk-java-spring-boot-versions - 使 Java 版本与 Spring Boot 要求匹配sdk-local-dev-config - 配置本地开发以避免云冲突sdk-spring-data-annotations - 为 Spring Data Cosmos 注解实体sdk-spring-data-repository - 正确使用 CosmosRepository 并处理 Iterable 返回类型index-exclude-unused - 排除从未查询的路径index-composite - 对 ORDER BY 使用复合索引index-spatial - 为地理查询添加空间索引index-range-vs-hash - 选择合适的索引类型index-lazy-consistent - 了解索引模式throughput-autoscale - 对可变工作负载使用自动缩放throughput-right-size - 合理调整预配吞吐量throughput-serverless - 为开发/测试考虑无服务器选项throughput-burst - 了解突发容量throughput-container-vs-database - 明智选择分配级别global-multi-region - 配置多区域写入global-consistency - 选择适当的一致性级别global-conflict-resolution - 实现冲突解决global-failover - 配置自动故障转移global-read-regions - 在用户附近添加读取区域global-zone-redundancy - 为高可用性启用区域冗余monitoring-ru-consumption - 跟踪 RU 消耗monitoring-latency - 监控 P99 延迟monitoring-throttling - 对限制进行告警monitoring-azure-monitor - 集成 Azure Monitormonitoring-diagnostic-logs - 启用诊断日志记录pattern-change-feed-materialized-views - 使用变更源进行跨分区查询优化pattern-efficient-ranking - 使用基于计数或缓存的方法实现高效排名pattern-service-layer-relationships - 使用服务层来水合文档引用阅读单个规则文件以获取详细说明和代码示例:
rules/model-embed-related.md
rules/partition-high-cardinality.md
rules/_sections.md
每个规则文件包含:
如需包含所有规则详情的完整指南:AGENTS.md
每周安装次数
173
代码仓库
GitHub 星标数
22
首次出现时间
2026 年 1 月 21 日
安全审计
已安装于
github-copilot141
codex118
gemini-cli112
opencode112
claude-code98
amp85
Comprehensive performance optimization guide for Azure Cosmos DB applications, containing 60+ rules across 9 categories, prioritized by impact to guide automated refactoring and code generation.
Reference these guidelines when:
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Data Modeling | CRITICAL | model- |
| 2 | Partition Key Design | CRITICAL | partition- |
| 3 | Query Optimization | HIGH | query- |
| 4 | SDK Best Practices | HIGH | sdk- |
| 5 | Indexing Strategies | MEDIUM-HIGH | index- |
| 6 | Throughput & Scaling | MEDIUM | throughput- |
| 7 | Global Distribution | MEDIUM | global- |
| 8 | Monitoring & Diagnostics | LOW-MEDIUM | monitoring- |
model-embed-related - Embed related data retrieved togethermodel-reference-large - Reference data when items get too largemodel-avoid-2mb-limit - Keep items well under 2MB limitmodel-id-constraints - Follow ID value length and character constraintsmodel-nesting-depth - Stay within 128-level nesting depth limitmodel-numeric-precision - Understand IEEE 754 numeric precision limitsmodel-denormalize-reads - Denormalize for read-heavy workloadsmodel-schema-versioning - Version your document schemasmodel-type-discriminator - Use type discriminators for polymorphic datapartition-high-cardinality - Choose high-cardinality partition keyspartition-avoid-hotspots - Distribute writes evenlypartition-hierarchical - Use hierarchical partition keys for flexibilitypartition-query-patterns - Align partition key with query patternspartition-synthetic-keys - Create synthetic keys when neededpartition-key-length - Respect partition key value length limitspartition-20gb-limit - Plan for 20GB logical partition limitquery-avoid-cross-partition - Minimize cross-partition queriesquery-use-projections - Project only needed fieldsquery-pagination - Use continuation tokens for paginationquery-avoid-scans - Avoid full container scansquery-parameterize - Use parameterized queriesquery-order-filters - Order filters by selectivitysdk-singleton-client - Reuse CosmosClient as singletonsdk-async-api - Use async APIs for throughputsdk-retry-429 - Handle 429s with retry-aftersdk-connection-mode - Use Direct mode for productionsdk-preferred-regions - Configure preferred regionssdk-excluded-regions - Exclude regions experiencing issuessdk-availability-strategy - Configure availability strategy for resiliencesdk-circuit-breaker - Use circuit breaker for fault tolerancesdk-diagnostics - Log diagnostics for troubleshootingindex-exclude-unused - Exclude paths never queriedindex-composite - Use composite indexes for ORDER BYindex-spatial - Add spatial indexes for geo queriesindex-range-vs-hash - Choose appropriate index typesindex-lazy-consistent - Understand indexing modesthroughput-autoscale - Use autoscale for variable workloadsthroughput-right-size - Right-size provisioned throughputthroughput-serverless - Consider serverless for dev/testthroughput-burst - Understand burst capacitythroughput-container-vs-database - Choose allocation level wiselyglobal-multi-region - Configure multi-region writesglobal-consistency - Choose appropriate consistency levelglobal-conflict-resolution - Implement conflict resolutionglobal-failover - Configure automatic failoverglobal-read-regions - Add read regions near usersglobal-zone-redundancy - Enable zone redundancy for HAmonitoring-ru-consumption - Track RU consumptionmonitoring-latency - Monitor P99 latencymonitoring-throttling - Alert on throttlingmonitoring-azure-monitor - Integrate Azure Monitormonitoring-diagnostic-logs - Enable diagnostic loggingpattern-change-feed-materialized-views - Use Change Feed for cross-partition query optimizationpattern-efficient-ranking - Use count-based or cached approaches for efficient rankingpattern-service-layer-relationships - Use a service layer to hydrate document referencesRead individual rule files for detailed explanations and code examples:
rules/model-embed-related.md
rules/partition-high-cardinality.md
rules/_sections.md
Each rule file contains:
For the complete guide with all rules expanded: AGENTS.md
Weekly Installs
173
Repository
GitHub Stars
22
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot141
codex118
gemini-cli112
opencode112
claude-code98
amp85
Supabase Postgres 最佳实践指南 - 8大类别性能优化规则与SQL示例
62,800 周安装
model-json-serialization - Handle JSON serialization correctly for Cosmos DB documentsmodel-relationship-references - Use ID references with transient hydration for document relationshipssdk-serialization-enums - Serialize enums as strings not integerssdk-emulator-ssl - Configure SSL and connection mode for Cosmos DB Emulatorsdk-java-content-response - Enable content response on write operations (Java)sdk-java-spring-boot-versions - Match Java version to Spring Boot requirementssdk-local-dev-config - Configure local development to avoid cloud conflictssdk-spring-data-annotations - Annotate entities for Spring Data Cosmossdk-spring-data-repository - Use CosmosRepository correctly and handle Iterable return types