MCPcopy Index your code
hub / github.com/upstash/jstack / indexDocs

Function indexDocs

www/src/scripts/index-docs.ts:34–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34async function indexDocs() {
35 await index.reset()
36
37 for (const doc of allDocs) {
38 try {
39 const sections = splitMdxByHeadings(doc.content)
40
41 for (const section of sections) {
42 if (!section || !section.content) continue
43
44 const headingId = `${doc._meta.path}#${slugify(section.title!)}`
45
46 const metadata = {
47 title: section.title ?? "<Error displaying title>",
48 path: doc._meta.path,
49 level: section.level ?? 2,
50 type: "section",
51 content: section.content,
52 documentTitle: doc.title,
53 } satisfies SearchMetadata
54
55 await index.upsert({
56 id: headingId,
57 data: `${section.title}\n\n${section.content}`,
58 metadata,
59 })
60 }
61
62 console.log(`✅ Indexed document sections: ${doc.title}`)
63 } catch (error) {
64 console.error(`❌ Failed to index ${doc.title}:`, error)
65 }
66 }
67
68 console.log("✅ Finished indexing docs")
69}
70
71indexDocs().catch(console.error)

Callers 1

index-docs.tsFile · 0.85

Calls 2

slugifyFunction · 0.90
splitMdxByHeadingsFunction · 0.85

Tested by

no test coverage detected