Skip to content

Commit 31d725d

Browse files
ikhareConvex, Inc.
authored and
Convex, Inc.
committed
Add a new docs section on AI (#33798)
GitOrigin-RevId: 4cf3a2c80033c9356d9a835cb3b08f359aa1b07b
1 parent c973729 commit 31d725d

File tree

8 files changed

+597
-57
lines changed

8 files changed

+597
-57
lines changed

npm-packages/docs/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
/using/environment-variables /production/environment-variables
6767
/production/hosting/environment-variables /production/environment-variables
6868
/production/log-streams /production/integrations/log-streams/
69+
/search/using-cursor /ai/using-cursor
6970
/using/error-handling /functions/error-handling
7071
/using/export /database/import-export/export
7172
/using/external-functions /functions/http-actions

npm-packages/docs/docs/ai.mdx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: AI Code Generation
3+
hide_table_of_contents: true
4+
---
5+
6+
Convex is designed around a small set of composable abstractions with strong
7+
guarantees that result in code that is not only faster to write, it’s easier to
8+
read and maintain, whether written by a team member or an LLM. Key features make
9+
sure you get bug-free AI generated code:
10+
11+
1. **Queries are Just TypeScript** Your database queries are pure TypeScript
12+
functions with end-to-end type safety and IDE support. This means AI can
13+
generate database code using the large training set of TypeScript code
14+
without switching to SQL.
15+
1. **Less Code for the Same Work** Since so much infrastructure and boiler plate
16+
is automatically manged by Convex there is less code to write, and thus less
17+
code to get wrong.
18+
1. **Automatic Reactivity** The reactive system automatically tracks data
19+
dependencies and updates your UI. AI doesn't need to manually manage
20+
subscriptions, WebSocket connections, or complex state synchronization—Convex
21+
handles all of this automatically.
22+
1. **Transactional Guarantees** Queries are read-only and mutations run in
23+
transactions. These constraints make it nearly impossible for AI to write
24+
code that could corrupt your data or leave your app in an inconsistent state.
25+
26+
Together, these features mean AI can focus on your business logic while Convex's
27+
guarantees prevent common failure modes.
28+
29+
## Convex AI rules
30+
31+
AI code generation is most effective when you provide it with a set of rules to
32+
follow.
33+
34+
If you're using Cursor, add the model specific `.mdc` files in your project's
35+
`.cursor/rules` directory.
36+
37+
- [Anthropic (Claude) Cursor Rules](https://convex.link/anthropic_convex_rules.mdc)
38+
- [OpenAI Cursor Rules](https://convex.link/openai_convex_rules.mdc)
39+
40+
For all other IDEs, you can add the following to your rules or memories.
41+
42+
- [Anthropic (Claude) Rules](https://convex.link/anthropic_convex_rules.txt)
43+
- [OpenAI Rules](https://convex.link/openai_convex_rules.txt)
44+
45+
We're constantly working on improving the quality of these rules for Convex by
46+
using rigorous evals. You can help by
47+
[contributing to our evals repo](https://github.com/get-convex/convex-evals).

npm-packages/docs/docs/search/using-cursor.mdx renamed to npm-packages/docs/docs/ai/using-cursor.mdx

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,19 @@ slug: "using-cursor"
99
maintain apps built with Convex. Let's walk through how to setup Cursor for the
1010
best possible results with Convex.
1111

12-
# Add Convex to Cursor’s Docs
12+
## Add Convex `.cursor/rules`
1313

14-
[Cursor composer agent](https://docs.cursor.com/composer/overview#agent), the
15-
main AI coding agent built into Cursor, uses Claude as it's LLM model of choice.
16-
While Claude knows about Convex, its knowledge can be patchy or outdated.
14+
To get the best results from Cursor put the model specific `.mdc` files in your
15+
project's `.cursor/rules` directory.
1716

18-
We need to give it a helping hand by using the
19-
[Cursors Docs](https://docs.cursor.com/context/@-symbols/@-docs) feature to give
20-
it the most up-to-date knowledge of Convex.
17+
- [Anthropic (Claude) Cursor Rules](https://convex.link/anthropic_convex_rules.mdc)
18+
- [OpenAI Cursor Rules](https://convex.link/openai_convex_rules.mdc)
2119

22-
From **`Cursor Settings`** > **`Features`** > **`Docs`** add new doc, use the
23-
URL "https://docs.convex.dev/"
24-
25-
![Chat UI](/img/cursor-with-convex/adding_convex_docs.webp)
26-
27-
Cursor will then index all of the Convex docs for the LLM to use.
28-
29-
![Chat UI](/img/cursor-with-convex/indexed_docs.webp)
30-
31-
You can then reference those docs in your prompt with the `@Convex` symbol.
32-
33-
![Chat UI](/img/cursor-with-convex/reference_convex_docs.webp)
34-
35-
<Admonition type="tip" title="Add more Convex knowledge">
20+
We're constantly working on improving the quality of these rules for Convex by
21+
using rigorous evals. You can help by
22+
[contributing to our evals repo](https://github.com/get-convex/convex-evals).
3623

37-
You can perform the above steps for https://stack.convex.dev/ too if you would
38-
like to provide even more context to the agent.
39-
40-
</Admonition>
41-
42-
# Install and run Convex yourself
24+
## Install and run Convex yourself
4325

4426
Keeping Convex running is crucial because
4527
[it automatically generates](https://docs.convex.dev/cli#run-the-convex-dev-server)
@@ -49,42 +31,18 @@ since it can't access the types for the queries and mutations it created.
4931
We recommended that you install (`npm install convex`) and run convex
5032
(`npx convex dev`) yourself in a terminal window.
5133

52-
# Use a `convex_instructions.md` to fine-tune Convex behavior even further
53-
54-
Despite Claude’s inbuilt knowledge of Convex plus referencing `@Convex` docs the
55-
LLM does still make silly Convex mistakes from time to time. To reduce this even
56-
more create a `convex_instructions.md` file in `/instructions` directory. Then
57-
reference it from your prompt.
58-
59-
![Chat UI](/img/cursor-with-convex/convex_instructions.webp)
60-
61-
To get you started see this one we have been using:
62-
63-
[convex_instructions.md](https://gist.github.com/mikecann/0dc25aeae0d06a88c3da71c1e026ae47)
64-
65-
Copy the above to your project then reference it in your prompts. You can edit
66-
it as needed.
67-
68-
<Admonition type="tip" title="Cursor Notepads">
69-
70-
Cursor does have a beta feature called
71-
[Notepads](https://docs.cursor.com/features/beta/notepads#notepads) that may be
72-
a better way to do this in the future.
73-
74-
</Admonition>
75-
76-
# Keep your requests small and git commit frequently
34+
## Keep your requests small
7735

7836
The best results when using agentic LLMs can be found when keeping the amount of
79-
changes you want to make small. This lets you be more specific around the
80-
context you provide the agent and it means the agent doesn't need to do a lot of
81-
searching for context.
37+
changes you want to make small and git commit frequently. This lets you be more
38+
specific around the context you provide the agent and it means the agent doesn't
39+
need to do a lot of searching for context.
8240

8341
After each successful prompt or series of prompts it is a good idea to commit
8442
your changes so that its simple to rollback to that point should the next prompt
8543
cause issues.
8644

87-
# Update and reference your `README.md`
45+
## Update and reference your `README.md`
8846

8947
The agent needs context about the specific business goals for your project.
9048
While it can infer some details from the files it reads, this becomes more
@@ -97,3 +55,28 @@ comprehensive README.md file in your project root and reference it.
9755
[Some people](https://youtu.be/2PjmPU07KNs?t=145) advocate for crafting a
9856
Product Requirements Document (PRD), this may be a good idea for more complex
9957
projects.
58+
59+
## Add Convex docs
60+
61+
Adding Convex docs can let you specifically refer to Convex features when
62+
building your app.
63+
64+
From **`Cursor Settings`** > **`Features`** > **`Docs`** add new doc, use the
65+
URL "https://docs.convex.dev/"
66+
67+
![Chat UI](/img/cursor-with-convex/adding_convex_docs.webp)
68+
69+
Cursor will then index all of the Convex docs for the LLM to use.
70+
71+
![Chat UI](/img/cursor-with-convex/indexed_docs.webp)
72+
73+
You can then reference those docs in your prompt with the `@Convex` symbol.
74+
75+
![Chat UI](/img/cursor-with-convex/reference_convex_docs.webp)
76+
77+
<Admonition type="tip" title="Add more Convex knowledge">
78+
79+
You can perform the above steps for https://stack.convex.dev/ too if you would
80+
like to provide even more context to the agent.
81+
82+
</Admonition>

npm-packages/docs/docs/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"Deduped",
2828
"denormalize",
2929
"dotenvy",
30+
"evals",
3031
"Finalizer",
3132
"Fivetran",
3233
"gapless",

npm-packages/docs/sidebars.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const sidebars = {
9595
},
9696
{
9797
type: "category",
98-
label: "AI & Search",
98+
label: "Search",
9999
link: { type: "doc", id: "search" },
100100
items: [{ type: "autogenerated", dirName: "search" }],
101101
className: "convex-sidebar-search",
@@ -107,6 +107,13 @@ const sidebars = {
107107
items: [{ type: "autogenerated", dirName: "components" }],
108108
className: "convex-sidebar-components",
109109
},
110+
{
111+
type: "category",
112+
label: "AI Code Gen",
113+
link: { type: "doc", id: "ai" },
114+
items: [{ type: "autogenerated", dirName: "ai" }],
115+
className: "convex-sidebar-ai",
116+
},
110117
{
111118
type: "category",
112119
label: "Testing",

npm-packages/docs/src/css/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ html[data-theme="dark"] .convex-menu-header {
713713
--convex-icon: url("../../static/img/sidebar-icons/components.svg");
714714
}
715715

716+
.convex-sidebar-ai {
717+
--convex-icon: url("../../static/img/sidebar-icons/magic-wand.svg");
718+
}
719+
716720
.convex-sidebar-production {
717721
--convex-icon: url("../../static/img/sidebar-icons/paper-plane.svg");
718722
}

0 commit comments

Comments
 (0)