File size: 2,324 Bytes
ab0678b
 
ee1db39
 
ab0678b
 
073446b
 
ee1db39
 
 
 
 
ab0678b
ee1db39
 
 
 
 
ab0678b
ee1db39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab0678b
 
 
 
 
 
 
 
ee1db39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import prisma from '../prismaClient.js';

console.log('[check_ai_data] starting');

async function checkData() {
  try {
    await prisma.$connect();
    console.log('[check_ai_data] Connected to DB');
    console.log('[check_ai_data] querying counts');
    const withTimeout = (promise, ms) => Promise.race([
      promise,
      new Promise((_, reject) => setTimeout(() => reject(new Error(`Timeout after ${ms}ms`)), ms))
    ]);

    const [total] = await withTimeout(prisma.$queryRaw`SELECT count(*) as count FROM "Product"`, 15000);
    const [withMetadata] = await prisma.$queryRaw`SELECT count(*) as count FROM "Product" WHERE "aiMetadata" IS NOT NULL`;
    const [withEmbedding] = await prisma.$queryRaw`SELECT count(*) as count FROM "Product" WHERE embedding IS NOT NULL`;
    const [missingEither] = await prisma.$queryRaw`SELECT count(*) as count FROM "Product" WHERE "aiMetadata" IS NULL OR embedding IS NULL`;
    const [missingBoth] = await prisma.$queryRaw`SELECT count(*) as count FROM "Product" WHERE "aiMetadata" IS NULL AND embedding IS NULL`;

    console.log('--- AI Data Counts ---');
    console.log('Total products:', String(total.count));
    console.log('Products with aiMetadata:', String(withMetadata.count));
    console.log('Products with embedding:', String(withEmbedding.count));
    console.log('Products missing aiMetadata OR embedding:', String(missingEither.count));
    console.log('Products missing aiMetadata AND embedding:', String(missingBoth.count));
    console.log('----------------------\n');

    console.log('[check_ai_data] querying missing samples');
    const missingSamples = await prisma.$queryRaw`
      SELECT
        id,
        name,
        ("aiMetadata" IS NULL) as missing_metadata,
        (embedding IS NULL) as missing_embedding
      FROM "Product"
      WHERE "aiMetadata" IS NULL OR embedding IS NULL
      ORDER BY id DESC
      LIMIT 10
    `;

    console.log('Sample Missing Products (up to 10):');
    missingSamples.forEach(p => {
      console.log(`ID: ${p.id} | missing_metadata=${p.missing_metadata} | missing_embedding=${p.missing_embedding} | ${p.name}`);
    });
    console.log('[check_ai_data] done');

  } catch (error) {
    console.error('Error checking data:', error);
  } finally {
    await prisma.$disconnect();
  }
}

await checkData();