|
@@ -48,7 +48,8 @@ export class ChatPdfService {
|
|
|
username: configService.get<string>('PG_USERNAME'),
|
|
username: configService.get<string>('PG_USERNAME'),
|
|
|
password: configService.get<string>('PG_PASSWORD'),
|
|
password: configService.get<string>('PG_PASSWORD'),
|
|
|
database: configService.get<string>('PG_DATABASE'),
|
|
database: configService.get<string>('PG_DATABASE'),
|
|
|
- logging: (msg) => Logger.debug(msg, 'Sequelize')
|
|
|
|
|
|
|
+ // logging: (msg) => Logger.debug(msg, 'Sequelize')
|
|
|
|
|
+ logging: false
|
|
|
})
|
|
})
|
|
|
ChatEmbedding.init(
|
|
ChatEmbedding.init(
|
|
|
{
|
|
{
|
|
@@ -203,7 +204,7 @@ export class ChatPdfService {
|
|
|
result[arg.index] = await self.getEmbedding(arg.text)
|
|
result[arg.index] = await self.getEmbedding(arg.text)
|
|
|
Logger.log(`create embedding for ${arg.index + 1}/${content.length}`)
|
|
Logger.log(`create embedding for ${arg.index + 1}/${content.length}`)
|
|
|
}
|
|
}
|
|
|
- const q = queue.promise(worker, 64)
|
|
|
|
|
|
|
+ const q = queue.promise(worker, 32)
|
|
|
content.forEach((text, index) => {
|
|
content.forEach((text, index) => {
|
|
|
q.push({
|
|
q.push({
|
|
|
text,
|
|
text,
|
|
@@ -211,7 +212,7 @@ export class ChatPdfService {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
await q.drained()
|
|
await q.drained()
|
|
|
- return result
|
|
|
|
|
|
|
+ return result.filter(i=> i && i.text)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async getEmbedding(content: string, retry = 0) {
|
|
async getEmbedding(content: string, retry = 0) {
|
|
@@ -227,9 +228,11 @@ export class ChatPdfService {
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
if (retry < 3) {
|
|
if (retry < 3) {
|
|
|
- await setTimeout(1000)
|
|
|
|
|
|
|
+ Logger.error(`fetchEmbedding error: ${error.message}, retry ${retry}`, 'fetchEmbedding')
|
|
|
|
|
+ await setTimeout(2000)
|
|
|
return await this.getEmbedding(content, retry + 1)
|
|
return await this.getEmbedding(content, retry + 1)
|
|
|
}
|
|
}
|
|
|
|
|
+ Logger.error(error.stack, 'fetchEmbedding')
|
|
|
throw new InternalServerErrorException(error.message)
|
|
throw new InternalServerErrorException(error.message)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|