diff --git a/Channel-Backend/src/services/chat.service.ts b/Channel-Backend/src/services/chat.service.ts index fd60ea2..fcb39f2 100644 --- a/Channel-Backend/src/services/chat.service.ts +++ b/Channel-Backend/src/services/chat.service.ts @@ -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({ diff --git a/Channel-Backend/src/services/extraction.service.ts b/Channel-Backend/src/services/extraction.service.ts index 9788518..f29b617 100644 --- a/Channel-Backend/src/services/extraction.service.ts +++ b/Channel-Backend/src/services/extraction.service.ts @@ -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}`, + }, + }); }); - }); + } } }