Skip to content

Commit 4819b88

Browse files
feat(docs): reindex docs on change (#863)
* Add github action to index docs * Add new line * Update .github/workflows/docs-embeddings.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Updates --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent e71a736 commit 4819b88

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Process Docs Embeddings
2+
3+
on:
4+
push:
5+
branches: [main, staging]
6+
paths:
7+
- 'apps/docs/**'
8+
workflow_dispatch: # Allow manual triggering
9+
10+
jobs:
11+
process-docs-embeddings:
12+
name: Process Documentation Embeddings
13+
runs-on: ubuntu-latest
14+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging'
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Bun
21+
uses: oven-sh/setup-bun@v2
22+
with:
23+
bun-version: latest
24+
25+
- name: Setup Node
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: latest
29+
30+
- name: Install dependencies
31+
run: bun install
32+
33+
- name: Process docs embeddings
34+
working-directory: ./apps/sim
35+
env:
36+
DATABASE_URL: ${{ github.ref == 'refs/heads/main' && secrets.DATABASE_URL || secrets.STAGING_DATABASE_URL }}
37+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
38+
run: bun run scripts/process-docs-embeddings.ts --clear

apps/sim/scripts/process-docs-embeddings.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ async function processDocsEmbeddings(options: ProcessingOptions = {}) {
5353
clearExisting: config.clearExisting,
5454
})
5555

56-
// Clear existing embeddings if requested
57-
if (config.clearExisting) {
58-
logger.info('🗑️ Clearing existing docs embeddings...')
59-
try {
60-
const deleteResult = await db.delete(docsEmbeddings)
61-
logger.info(`✅ Successfully deleted existing embeddings`)
62-
} catch (error) {
63-
logger.error('❌ Failed to delete existing embeddings:', error)
64-
throw new Error('Failed to clear existing embeddings')
65-
}
66-
}
67-
6856
// Initialize the docs chunker
6957
const chunker = new DocsChunker({
7058
chunkSize: config.chunkSize,
@@ -73,7 +61,7 @@ async function processDocsEmbeddings(options: ProcessingOptions = {}) {
7361
baseUrl: config.baseUrl,
7462
})
7563

76-
// Process all .mdx files
64+
// Process all .mdx files first (compute embeddings before clearing)
7765
logger.info(`📚 Processing docs from: ${config.docsPath}`)
7866
const chunks = await chunker.chunkAllDocs(config.docsPath)
7967

@@ -84,6 +72,18 @@ async function processDocsEmbeddings(options: ProcessingOptions = {}) {
8472

8573
logger.info(`📊 Generated ${chunks.length} chunks with embeddings`)
8674

75+
// Clear existing embeddings if requested (after computing new ones to minimize downtime)
76+
if (config.clearExisting) {
77+
logger.info('🗑️ Clearing existing docs embeddings...')
78+
try {
79+
const deleteResult = await db.delete(docsEmbeddings)
80+
logger.info(`✅ Successfully deleted existing embeddings`)
81+
} catch (error) {
82+
logger.error('❌ Failed to delete existing embeddings:', error)
83+
throw new Error('Failed to clear existing embeddings')
84+
}
85+
}
86+
8787
// Save chunks to database in batches for better performance
8888
const batchSize = 10
8989
logger.info(`💾 Saving chunks to database (batch size: ${batchSize})...`)

0 commit comments

Comments
 (0)