Production
This commit is contained in:
parent
73b1d35754
commit
61126a546a
@ -92,12 +92,17 @@ export class ChatService {
|
||||
}
|
||||
|
||||
// 2. Fetch Embeddings & Data Sources
|
||||
let embeddingsCount = await prisma.assetEmbedding.count({
|
||||
where: { assetId: { in: accessibleAssetIds } }
|
||||
// Ensure ALL accessible assets have embeddings generated
|
||||
const embeddedAssets = await prisma.assetEmbedding.findMany({
|
||||
where: { assetId: { in: accessibleAssetIds } },
|
||||
select: { assetId: true },
|
||||
distinct: ['assetId']
|
||||
});
|
||||
const embeddedAssetIds = embeddedAssets.map(e => e.assetId);
|
||||
const missingAssetIds = accessibleAssetIds.filter(id => !embeddedAssetIds.includes(id));
|
||||
|
||||
if (embeddingsCount === 0 && accessibleAssetIds.length > 0) {
|
||||
await this.autoIndexCatalog(accessibleAssetIds);
|
||||
if (missingAssetIds.length > 0) {
|
||||
await this.autoIndexCatalog(missingAssetIds);
|
||||
}
|
||||
|
||||
const embeddings = await prisma.assetEmbedding.findMany({
|
||||
|
||||
@ -266,23 +266,26 @@ export class ExtractionService {
|
||||
}
|
||||
});
|
||||
}
|
||||
// E. Plain Text / Markdown
|
||||
else {
|
||||
// E. Plain Text / Markdown / Code (Excluding binaries)
|
||||
else if (!ext.match(/\.(png|jpe?g|gif|webp|svg|mp4|webm|avi|mp3|wav)$/i)) {
|
||||
const textContent = buffer.toString('utf-8');
|
||||
const subChunks = this.splitText(textContent, 600);
|
||||
subChunks.forEach((text, i) => {
|
||||
chunks.push({
|
||||
chunkIndex: chunkIndex++,
|
||||
chunkType: 'TEXT',
|
||||
content: text,
|
||||
sourceMetadata: {
|
||||
assetId: asset.id,
|
||||
assetTitle: asset.title,
|
||||
assetType: asset.type,
|
||||
location: `Document Text: Segment ${i + 1}`,
|
||||
},
|
||||
// Only proceed if it looks like actual text (not arbitrary binary data)
|
||||
if (!textContent.includes('\u0000\u0000')) {
|
||||
const subChunks = this.splitText(textContent, 600);
|
||||
subChunks.forEach((text, i) => {
|
||||
chunks.push({
|
||||
chunkIndex: chunkIndex++,
|
||||
chunkType: 'TEXT',
|
||||
content: text,
|
||||
sourceMetadata: {
|
||||
assetId: asset.id,
|
||||
assetTitle: asset.title,
|
||||
assetType: asset.type,
|
||||
location: `Document Text: Segment ${i + 1}`,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user