Skip to content

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

feat(docs-gpt): page section heading

Greg Richardsonf16b81d4ba89
diff --git a/apps/docs/scripts/generate-embeddings.ts b/apps/docs/scripts/generate-embeddings.ts
index 11825b59677..8d144cdbefc 100644
--- a/apps/docs/scripts/generate-embeddings.ts
+++ b/apps/docs/scripts/generate-embeddings.ts
@@ -109,6 +109,7 @@ type Meta = ReturnType<typeof extractMetaExport>
type Section = {
content: string
+ heading?: string
slug?: string
}
@@ -160,9 +161,14 @@ function processMdxForSearch(content: string): ProcessedMdx {
const sections = sectionTrees.map((tree) => {
const [firstNode] = tree.children
+
+ const heading = firstNode.type === 'heading' ? toString(firstNode) : undefined
+ const slug = heading ? slugger.slug(heading) : undefined
+
return {
content: toMarkdown(tree),
- slug: firstNode.type === 'heading' ? slugger.slug(toString(firstNode)) : undefined,
+ heading,
+ slug,
}
})
@@ -340,7 +346,7 @@ async function generateEmbeddings() {
}
console.log(`Adding ${sections.length} page sections (with embeddings) for '${path}'`)
- for (const { content, slug } of sections) {
+ for (const { slug, heading, content } of sections) {
// OpenAI recommends replacing newlines with spaces for best results (specific to embeddings)
const input = content.replace(/\n/g, ' ')
@@ -364,6 +370,7 @@ async function generateEmbeddings() {
.insert({
page_id: page.id,
slug,
+ heading,
content,
token_count: embeddingResponse.data.usage.total_tokens,
embedding: responseData.embedding,
diff --git a/supabase/migrations/20230216232739_page_section_heading_slug.sql b/supabase/migrations/20230216232739_page_section_heading_slug.sql
new file mode 100644
index 00000000000..7186a9fd510
--- /dev/null
+++ b/supabase/migrations/20230216232739_page_section_heading_slug.sql
@@ -0,0 +1,3 @@
+alter table "public"."page_section"
+add column slug text,
+add column heading text;
diff --git a/supabase/migrations/20230216232739_page_section_slug.sql b/supabase/migrations/20230216232739_page_section_slug.sql
deleted file mode 100644
index 25000a60df4..00000000000
--- a/supabase/migrations/20230216232739_page_section_slug.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-alter table "public"."page_section"
-add slug text;