-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a separate queue for indexing embeddings and summaries, to prevent blocking the main SB indexing thread #61
Conversation
…t blocking the main SB indexing threa
WalkthroughWalkthroughThe changes to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Queue
participant EmbeddingService
participant SummaryService
User->>Queue: Queue page indexing event
Queue->>EmbeddingService: Process embedding generation
EmbeddingService->>Queue: Generate embeddings
Queue->>SummaryService: Process summary generation
SummaryService->>Queue: Generate summary
Queue->>User: Respond with indexing status
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Outside diff range, codebase verification and nitpick comments (5)
src/embeddings.ts (5)
Line range hint
73-84
: Add error handling for embedding generation.Consider adding error handling for the embedding generation process to ensure robustness.
Use this diff to add error handling:
try { const embedding = await currentEmbeddingProvider.generateEmbeddings({ text: paragraphText, }); } catch (error) { log("error", `Failed to generate embeddings for paragraph: ${error}`); continue; }
Line range hint
150-161
: Add error handling for summary generation.Consider adding error handling for the summary generation process to ensure robustness.
Use this diff to add error handling:
try { summary = await summaryProvider.singleMessageChat( "Contents of " + page + ":\n" + pageText + "\n\n" + summaryPrompt, ); } catch (error) { log("error", `Failed to generate summary for page: ${error}`); return; }
Consider adding error handling for
space.readPage
inindexEmbeddings
.While the function checks for
tree.children
after parsing, it lacks explicit error handling forspace.readPage
. Adding error handling would improve robustness against potential issues like file not found or read permissions.
src/embeddings.ts
: Add error handling forspace.readPage
.Analysis chain
Line range hint
73-84
: Verify page reading and parsing logic.Ensure that the logic for reading and parsing the page content is correctly implemented and handles potential errors.
Run the following script to verify the usage of
space.readPage
andmarkdown.parseMarkdown
:Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of space.readPage and markdown.parseMarkdown. # Test: Search for the usage of space.readPage and markdown.parseMarkdown. Expect: Correct usage and error handling. rg --type typescript -A 5 $'space.readPage' rg --type typescript -A 5 $'markdown.parseMarkdown'Length of output: 163
Script:
#!/bin/bash # Description: Verify the usage of space.readPage and markdown.parseMarkdown with corrected file type. # Test: Search for the usage of space.readPage and markdown.parseMarkdown. Expect: Correct usage and error handling. rg --type ts -A 5 $'space.readPage' rg --type ts -A 5 $'markdown.parseMarkdown'Length of output: 4411
223-243
: Consider adding error handling formq.send
operations.The
mq.send
calls in thequeueEmbeddingGeneration
function lack error handling, which could lead to unhandled exceptions if the message queue fails. It's recommended to wrap these operations in try-catch blocks or implement other error-handling mechanisms to ensure robustness.
src/embeddings.ts
: Lines wheremq.send
is used.Analysis chain
Verify queuing logic.
Ensure that the logic for queuing embedding and summary indexing tasks is correctly implemented and handles potential errors.
Run the following script to verify the usage of
mq.send
:Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of mq.send for queuing operations. # Test: Search for the usage of mq.send. Expect: Correct usage and error handling. rg --type typescript -A 5 $'mq.send'Length of output: 70
Script:
#!/bin/bash # Description: Verify the usage of mq.send for queuing operations. # Test: Search for the usage of mq.send. Expect: Correct usage and error handling. rg --type ts -A 5 $'mq.send'Length of output: 440
Consider Adding Error Handling for
space.readPage
andmarkdown.parseMarkdown
While there is a check for
tree.children
to handle parsing results, explicit error handling for thespace.readPage
andmarkdown.parseMarkdown
calls is missing. Consider wrapping these calls in try-catch blocks to handle potential exceptions gracefully.
- In
src/embeddings.ts
, lines wherespace.readPage
andmarkdown.parseMarkdown
are used.Analysis chain
Line range hint
150-161
: Verify page reading and parsing logic.Ensure that the logic for reading and parsing the page content is correctly implemented and handles potential errors.
Run the following script to verify the usage of
space.readPage
andmarkdown.parseMarkdown
:Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of space.readPage and markdown.parseMarkdown. # Test: Search for the usage of space.readPage and markdown.parseMarkdown. Expect: Correct usage and error handling. rg --type typescript -A 5 $'space.readPage' rg --type typescript -A 5 $'markdown.parseMarkdown'Length of output: 163
Script:
#!/bin/bash # Description: Verify the usage of space.readPage and markdown.parseMarkdown. # Test: Search for the usage of space.readPage and markdown.parseMarkdown in TypeScript files. rg 'space.readPage' --glob '*.ts' -A 5 rg 'markdown.parseMarkdown' --glob '*.ts' -A 5Length of output: 4419
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
silverbullet-ai.plug.yaml
is excluded by none and included by none
Files selected for processing (1)
- src/embeddings.ts (6 hunks)
Additional context used
Path-based instructions (1)
src/embeddings.ts (1)
Pattern
**/*.ts
: Review these typescript files for best practices, readability, and DRY.
Additional comments not posted (2)
src/embeddings.ts (2)
245-254
: Verify queue statistics retrieval.Ensure that the queue statistics are correctly retrieved and logged.
Run the following script to verify the usage of
mq.getQueueStats
:Verification successful
Queue Statistics Retrieval Verified
The
mq.getQueueStats
function is used correctly in theprocessEmbeddingsQueue
function. The queue statistics are retrieved and logged as expected.
- Location:
src/embeddings.ts
const queueStats = await mq.getQueueStats("aiEmbeddingsQueue");
console.log(
AI: Embeddings queue stats: ${JSON.stringify(queueStats)});
The code correctly retrieves and logs the queue statistics. No issues found with this implementation.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of mq.getQueueStats for queue statistics retrieval. # Test: Search for the usage of mq.getQueueStats. Expect: Correct usage and logging. rg --type typescript -A 5 $'mq.getQueueStats'Length of output: 79
Script:
#!/bin/bash # Description: Verify the usage of mq.getQueueStats for queue statistics retrieval. # Test: Search for the usage of mq.getQueueStats. Expect: Correct usage and logging. rg -A 5 'mq.getQueueStats'Length of output: 732
256-265
: Verify queue statistics retrieval.Ensure that the queue statistics are correctly retrieved and logged.
Run the following script to verify the usage of
mq.getQueueStats
:Verification successful
Queue statistics retrieval is correctly implemented.
The
mq.getQueueStats
function is correctly used to retrieve and log the statistics for the "aiSummaryQueue" insrc/embeddings.ts
. No issues were found with its implementation.
src/embeddings.ts
: Correct retrieval and logging of queue statistics for "aiSummaryQueue".Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of mq.getQueueStats for queue statistics retrieval. # Test: Search for the usage of mq.getQueueStats. Expect: Correct usage and logging. rg --type typescript -A 5 $'mq.getQueueStats'Length of output: 79
Script:
#!/bin/bash # Description: Verify the usage of mq.getQueueStats for queue statistics retrieval. # Test: Search for the usage of mq.getQueueStats. Expect: Correct usage and logging. rg --glob '*.ts' -A 5 'mq.getQueueStats'Length of output: 746
export async function queueEmbeddingGeneration( | ||
{ name: page, tree }: IndexTreeEvent, | ||
) { | ||
await initIfNeeded(); | ||
|
||
if (!canIndexPage(page)) { | ||
return; | ||
} | ||
|
||
if (!tree.children) { | ||
return; | ||
} | ||
|
||
if (await shouldIndexEmbeddings()) { | ||
await mq.send("aiEmbeddingsQueue", page); | ||
} | ||
|
||
if (await shouldIndexSummaries()) { | ||
await mq.send("aiSummaryQueue", page); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for queuing operations.
Consider adding error handling for the queuing operations to ensure robustness.
Use this diff to add error handling:
try {
await mq.send("aiEmbeddingsQueue", page);
} catch (error) {
log("error", `Failed to queue embedding task for page: ${error}`);
}
try {
await mq.send("aiSummaryQueue", page);
} catch (error) {
log("error", `Failed to queue summary task for page: ${error}`);
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export async function queueEmbeddingGeneration( | |
{ name: page, tree }: IndexTreeEvent, | |
) { | |
await initIfNeeded(); | |
if (!canIndexPage(page)) { | |
return; | |
} | |
if (!tree.children) { | |
return; | |
} | |
if (await shouldIndexEmbeddings()) { | |
await mq.send("aiEmbeddingsQueue", page); | |
} | |
if (await shouldIndexSummaries()) { | |
await mq.send("aiSummaryQueue", page); | |
} | |
} | |
export async function queueEmbeddingGeneration( | |
{ name: page, tree }: IndexTreeEvent, | |
) { | |
await initIfNeeded(); | |
if (!canIndexPage(page)) { | |
return; | |
} | |
if (!tree.children) { | |
return; | |
} | |
if (await shouldIndexEmbeddings()) { | |
try { | |
await mq.send("aiEmbeddingsQueue", page); | |
} catch (error) { | |
log("error", `Failed to queue embedding task for page: ${error}`); | |
} | |
} | |
if (await shouldIndexSummaries()) { | |
try { | |
await mq.send("aiSummaryQueue", page); | |
} catch (error) { | |
log("error", `Failed to queue summary task for page: ${error}`); | |
} | |
} | |
} |
export async function processSummaryQueue(messages: MQMessage[]) { | ||
await initIfNeeded(); | ||
for (const message of messages) { | ||
const pageName: string = message.body; | ||
console.log(`AI: Generating and indexing summary for ${pageName}`); | ||
await indexSummary(pageName); | ||
} | ||
const queueStats = await mq.getQueueStats("aiSummaryQueue"); | ||
console.log(`AI: Summary queue stats: ${JSON.stringify(queueStats)}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for summary generation.
Consider adding error handling for the summary generation process to ensure robustness.
Use this diff to add error handling:
try {
await indexSummary(pageName);
} catch (error) {
console.error(`Failed to index summary for ${pageName}: ${error}`);
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export async function processSummaryQueue(messages: MQMessage[]) { | |
await initIfNeeded(); | |
for (const message of messages) { | |
const pageName: string = message.body; | |
console.log(`AI: Generating and indexing summary for ${pageName}`); | |
await indexSummary(pageName); | |
} | |
const queueStats = await mq.getQueueStats("aiSummaryQueue"); | |
console.log(`AI: Summary queue stats: ${JSON.stringify(queueStats)}`); | |
} | |
export async function processSummaryQueue(messages: MQMessage[]) { | |
await initIfNeeded(); | |
for (const message of messages) { | |
const pageName: string = message.body; | |
console.log(`AI: Generating and indexing summary for ${pageName}`); | |
try { | |
await indexSummary(pageName); | |
} catch (error) { | |
console.error(`Failed to index summary for ${pageName}: ${error}`); | |
} | |
} | |
const queueStats = await mq.getQueueStats("aiSummaryQueue"); | |
console.log(`AI: Summary queue stats: ${JSON.stringify(queueStats)}`); | |
} |
export async function processEmbeddingsQueue(messages: MQMessage[]) { | ||
await initIfNeeded(); | ||
for (const message of messages) { | ||
const pageName: string = message.body; | ||
console.log(`AI: Generating and indexing embeddings for file ${pageName}`); | ||
await indexEmbeddings(pageName); | ||
} | ||
const queueStats = await mq.getQueueStats("aiEmbeddingsQueue"); | ||
console.log(`AI: Embeddings queue stats: ${JSON.stringify(queueStats)}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for embedding generation.
Consider adding error handling for the embedding generation process to ensure robustness.
Use this diff to add error handling:
try {
await indexEmbeddings(pageName);
} catch (error) {
console.error(`Failed to index embeddings for file ${pageName}: ${error}`);
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export async function processEmbeddingsQueue(messages: MQMessage[]) { | |
await initIfNeeded(); | |
for (const message of messages) { | |
const pageName: string = message.body; | |
console.log(`AI: Generating and indexing embeddings for file ${pageName}`); | |
await indexEmbeddings(pageName); | |
} | |
const queueStats = await mq.getQueueStats("aiEmbeddingsQueue"); | |
console.log(`AI: Embeddings queue stats: ${JSON.stringify(queueStats)}`); | |
} | |
export async function processEmbeddingsQueue(messages: MQMessage[]) { | |
await initIfNeeded(); | |
for (const message of messages) { | |
const pageName: string = message.body; | |
console.log(`AI: Generating and indexing embeddings for file ${pageName}`); | |
try { | |
await indexEmbeddings(pageName); | |
} catch (error) { | |
console.error(`Failed to index embeddings for file ${pageName}: ${error}`); | |
} | |
} | |
const queueStats = await mq.getQueueStats("aiEmbeddingsQueue"); | |
console.log(`AI: Embeddings queue stats: ${JSON.stringify(queueStats)}`); | |
} |
related: silverbulletmd/silverbullet#1021
Summary by CodeRabbit
New Features
Bug Fixes