Prompt Detail:
Sure, here's the code converted to process each chunk sequentially:
vbnetlet chunkProcessingErrorOccurred = false;
for (let i = 0; i < fileChunks.length; i++) {
const chunk = fileChunks[i];
try {
const indexingMessageData = await _intelligenceOpenAIChatComplete({
temperature: 0,
model: OpenAIEngine.ChatGpt,
messages: [
{
role: "system",
content:
"You are IndexingAssistantBot. Your job is to provide helpful messages to the user that gives them insight into the types of things that the indexing system is learning as it processes chunks of data.",
},
{
role: "user",
content: `The system is currently processing the following chunk of information:\n\n<chunk begin>\nFile Name: ${
file.title
}\nChunk: ${i + 1} of ${fileChunks.length}\n${
chunk.text
}<chunk end>\n
Provide up to 3 short (9 - 10 words max) and witty indexing message to help the user understand what you're learning. Each message should begin with "Learning about" or "Accumulating knowledge" or "Neural ridges forming" and should be as specific as possible. Respond in an array of strings (e.g. [message1, message2, message3])`,
},
],
});
const indexingProgressMessagesArray = JSON.parse(
indexingMessageData?.data.choices[0].message?.content as string
);
for (const message of indexingProgressMessagesArray) {
await pusherClient.trigger(
channelKey,
PusherEvent.WorkspaceNotification,
{
workspaceId,
entityId,
notification: message,
}
);
}
const result = await intelligenceModule.createEmbedding({
text: metadataHeader + chunk.text, // header included to aid vector search
embeddingsModel: EmbeddingsModel.AdaV2,
context,
});
if (!result?.data) {
continue;
}
const searchDocumentChunk = await kg.searchDocumentChunk.upsert({
where: {
id: uuidModule.generate(),
},
create: {
associatedSearchDocument: searchDocument.id,
body: chunk.text,
associatedWorkspace: workspaceId,
endIndex: chunk.end.toString(),
startIndex: chunk.start.toString(),
metadataHeader,
},
});
await pineconeModule.upsert({
pineconeIndex: PineconeIndex.ExperimentalAda2Embeddings,
vectors: [
{
id: searchDocumentChunk.id,
values: result.data,
metadata: { scopeIds }, // we emulate kg scope system here and use the $in operator in the pinecone query to filter
},
],
context,
});
} catch (unknownErr) {
const err = unknownErr as Error;
logger.error(`[makeChunksFromFileAttachment] Indexing chunk failed `, {
workspaceId,
chunk,
originalError: objectModule.safeErrorAsJson(err),
});
chunkProcessingErrorOccurred = true;
}
}
if (chunkProcessingErrorOccurred) {
throw new Error(
`At least one chunk failed to index for file ${entityId} in workspace ${workspaceId}`
);
}
In this version, the for...of
loop is used to process each message in the indexingProgressMessagesArray
array sequentially. Similarly, the for
loop is used to process each chunk of the file sequentially. The rest of the code remains largely the same.
Add a comment