Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

add going to prod for ai docs

egor-romanov3507117fe380
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
index b6d0ec39ca3..0cfe4ed1208 100644
--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
@@ -911,6 +911,7 @@ export const ai: NavMenuConstant = {
{ name: 'Vector columns', url: '/guides/ai/vector-columns' },
{ name: 'Engineering for scale', url: '/guides/ai/engineering-for-scale' },
{ name: 'Choosing Compute Add-on', url: '/guides/ai/choosing-compute-addon' },
+ { name: 'Going to Production', url: '/guides/ai/going-to-prod' },
],
},
{
diff --git a/apps/docs/pages/guides/ai/going-to-prod.mdx b/apps/docs/pages/guides/ai/going-to-prod.mdx
new file mode 100644
index 00000000000..5a83f466e3a
--- /dev/null
+++ b/apps/docs/pages/guides/ai/going-to-prod.mdx
@@ -0,0 +1,100 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'ai-going-to-prod',
+ title: 'Going to Production',
+ description: 'Checklist for going to production with your AI application.',
+ subtitle: 'Going to production checklist for AI applications.',
+ sidebar_label: 'Going to Production',
+}
+
+This guide will help you to prepare your application for production. We'll provide actionable steps to help you scale your application, ensure that it is reliable, can handle the load, and provide optimal precision for your use case.
+
+See our [Engineering for Scale](/docs/guides/ai/engineering-for-scale) guide for more information about engineering at scale.
+
+## Do you need indexes?
+
+Sequential scans will result in significantly higher latencies and lower throughput, guaranteeing 100% precision and not being RAM bound.
+
+There are a couple of cases where you might not need indexes:
+
+- You have a small dataset and don't need to scale it.
+- You are not expecting high amounts of vector search queries per second.
+- You need to guarantee 100% precision.
+
+You don't have to create indexes in these cases and can use sequential scans instead. This type of workload will not be RAM bound and will not require any additional resources but will result in higher latencies and lower throughput. Extra CPU cores may help to improve queries per second, but it will not help to improve latency.
+
+On the other hand, if you need to scale your application, you will need to create indexes. This will result in lower latencies and higher throughput, but will require additional RAM to make use of Postgres Caching. Also, using indexes will result in lower precision, as with indexes, you replace exact (KNN) search with approximate (ANN) search.
+
+## Understanding `probes` and `lists`
+
+Index used for approximate vector similarity search in pgvector divides a dataset into partitions. Number of these partitions is defined by the `lists` constant. The `probes` controls how many lists are going to be searched during a query.
+
+The values of lists and probes directly affect precision and RPS.
+
+- Higher `lists` means an index will be built slower, but you can achieve better RPS and precision.
+- Higher `probes` means that select queries will be slower, but you can achieve better precision.
+- `lists` and `probes` are not independent. Higher `lists` means that you will have to use higher `probes` to achieve the same precision.
+
+You can find more examples of how `lists` and `probes` constants affect precision and RPS in [pgvector 0.4.0 performance](https://supabase.com/blog/pgvector-performance) blogpost.
+
+<div>
+ <img
+ alt="multi database"
+ className="dark:hidden"
+ src="/docs/img/ai/going-prod/lists-count--light.png"
+ />
+ <img
+ alt="multi database"
+ className="hidden dark:block"
+ src="/docs/img/ai/going-prod/lists-count--dark.png"
+ />
+</div>
+
+## Performace Tips when using indexes
+
+First, a few generic tips which you can pick and choose from:
+
+1. If you are using Supabase you don't need to change your Postgres configs. But if you self-host, you should **adjust your Postgres config.** aligned with RAM & CPU cores. [Find more details here](https://gist.github.com/egor-romanov/323e2847851bbd758081511785573c08).
+2. Prefer `inner-product` to `L2` or `Cosine` distances if your vectors are normalized (like `text-embedding-ada-002`). If embeddings are not normalized, `Cosine` distance should give the best results with an index.
+3. **Pre-warm your database.** Implement the warm-up technique before transitioning to production or running benchmarks.
+ - Execute 10,000 to 50,000 "warm-up" queries before each benchmark, matching the number of `probes` you are going to use in production. Additionally, you can execute about 1,000 queries with probes ranging from three to ten times the prod's probes. Both of these help to increase RAM utilization.
+4. **Establish your workload.** Increasing the lists constant for the pgvector index can accelerate your queries (at the expense of a slower build). For instance, for benchmarks with 1,000,000 embeddings, we employed a `lists` constant of 2000 (`number of vectors / 500`) as opposed to the suggested 1000 (`number of vectors / 1000`).
+5. **Benchmark your own specific workloads.** Doing this during cache warm-up helps gauge the best value for the `probes` constant, balancing precision with RPS.
+
+## Going into production
+
+1. Decide if you are going to use indexes or not. You can skip the rest of this guide if you do not use indexes.
+2. Over-provision RAM during preparation. You can scale down in step `5`, but it's better to start with a larger size to get the best results for RAM requirements. (We'd recommend at least 8XL if you're using Supabase.)
+3. Upload your data to the database. If you use [`vecs`](https://supabase.com/docs/guides/ai/python/api) library, it will automatically generate an index with default parameters.
+4. Run a benchmark using randomly generated queries and see the results. Again, you can use `vecs` library with the `ann-benchmarks` tool. Do it with probes set to 10 (default) and then with probes set to 100 or more, so RPS will be lower than 10.
+5. Take a look at the RAM usage, and save it as a note for yourself. You would likely want to use compute add-on in the future that would have the same amount of RAM as used at the moment (both actual RAM usage and RAM used for cache and buffers).
+6. Scale down your compute add-on to the one that would have the same amount of RAM as used at the moment.
+7. Repeat step 3. to load the data into RAM. You should see that RPS is increased on subsequent runs, and stop when it no longer increases. Then repeat the benchmark with probes set to a higher value as well if you didn't do it before on that compute add-on size.
+8. Run a benchmark using real queries and see the results. You can use `vecs` library for that as well with `ann-benchmarks` tool. Do it with probes set to 10 (default) and then gradually increase/decrease probes value until you see that both precision and RPS match your requirements.
+9. If you want higher RPS and you don't expect to have frequent inserts and reindexing, you can increase `lists` constantly. You have to rebuild the index with higher lists value and repeat steps 6-7 to find the best combination of `lists` and `probes` constants to achieve the best RPS and precision values. Higher `lists` mean that index will build slower, but you can achieve better RPS and precision. Higher probes mean that select queries will be slower, but you can achieve better precision.
+
+## Useful links
+
+Don't forget to check out the general [Production Checklist](/guides/platform/going-into-prod) to ensure your project is secure, performant, and will remain available for your users.
+
+You can look at our [Choosing Compute Add-on](/guides/ai/choosing-compute-addon) guide to get a basic understanding of how much compute you might need for your workload.
+
+Or take a look at [pgvector 0.4.0 performance](https://supabase.com/blog/pgvector-performance) blogpost to check out what pgvector is capable of and how the technique described above can be used to achieve the best results.
+
+<div>
+ <img
+ alt="multi database"
+ className="dark:hidden"
+ src="/docs/img/ai/going-prod/size-to-rps--light.png"
+ />
+ <img
+ alt="multi database"
+ className="hidden dark:block"
+ src="/docs/img/ai/going-prod/size-to-rps--dark.png"
+ />
+</div>
+
+export const Page = ({ children }) => <Layout meta={meta} children={children} />
+
+export default Page
diff --git a/apps/docs/public/img/ai/going-prod/lists-count--dark.png b/apps/docs/public/img/ai/going-prod/lists-count--dark.png
new file mode 100644
index 00000000000..919b56b4a8c
Binary files /dev/null and b/apps/docs/public/img/ai/going-prod/lists-count--dark.png differ
diff --git a/apps/docs/public/img/ai/going-prod/lists-count--light.png b/apps/docs/public/img/ai/going-prod/lists-count--light.png
new file mode 100644
index 00000000000..f40a98500fc
Binary files /dev/null and b/apps/docs/public/img/ai/going-prod/lists-count--light.png differ
diff --git a/apps/docs/public/img/ai/going-prod/size-to-rps--dark.png b/apps/docs/public/img/ai/going-prod/size-to-rps--dark.png
new file mode 100644
index 00000000000..69ab4d76f51
Binary files /dev/null and b/apps/docs/public/img/ai/going-prod/size-to-rps--dark.png differ
diff --git a/apps/docs/public/img/ai/going-prod/size-to-rps--light.png b/apps/docs/public/img/ai/going-prod/size-to-rps--light.png
new file mode 100644
index 00000000000..b4aaf58e257
Binary files /dev/null and b/apps/docs/public/img/ai/going-prod/size-to-rps--light.png differ