Browse Source

refactor: fix embeddings endpoint to return actual embedding records

Previously the /embeddings endpoint was returning shop_content records
with fake embedding data, causing confusion about pending/completed status.

Changes:
- Added getAllShopEmbeddings() to get actual embeddings from shop_embeddings table
- Fixed getShopQdrantEmbeddings endpoint to return real embedding records
- Added 'pending' count to getShopEmbeddingsStats for better visibility
- Now returns accurate embedding_status from the actual embeddings table

This fixes the misleading '27 pending' display and makes the API consistent
with the actual database state.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh 8 months ago
parent
commit
3fd391a316
2 changed files with 22 additions and 10 deletions
  1. 7 7
      src/api/components/QdrantEndpoint.ts
  2. 15 3
      src/database/Database.ts

+ 7 - 7
src/api/components/QdrantEndpoint.ts

@@ -930,17 +930,17 @@ export class QdrantEndpoint extends BaseEndpointComponent {
         return;
         return;
       }
       }
 
 
-      // Get shop embeddings from database
-      const embeddings = this.db.getShopContent(shop.id);
+      // Get actual embeddings from shop_embeddings table
+      const embeddings = this.db.getAllShopEmbeddings(shop.id);
 
 
       res.json({
       res.json({
         data: {
         data: {
           embeddings: embeddings.map(embedding => ({
           embeddings: embeddings.map(embedding => ({
-            id: `emb-${embedding.id}`,
-            shop_content_id: `content-${embedding.id}`,
-            collection_name: shop.custom_id ? `${shop.custom_id}-${embedding.content_type}_1` : null,
-            point_id: embedding.qdrant_point_id || null,
-            embedding_status: embedding.embedding_status || 'pending',
+            id: embedding.id,
+            shop_content_id: embedding.shop_content_id,
+            collection_name: embedding.collection_name,
+            point_id: embedding.point_id,
+            embedding_status: embedding.embedding_status,
             created_at: embedding.created_at,
             created_at: embedding.created_at,
             updated_at: embedding.updated_at
             updated_at: embedding.updated_at
           }))
           }))

+ 15 - 3
src/database/Database.ts

@@ -1245,6 +1245,16 @@ export class ShopDatabase {
     return stmt.all(shopContentId) as ShopEmbedding[];
     return stmt.all(shopContentId) as ShopEmbedding[];
   }
   }
 
 
+  getAllShopEmbeddings(shopId: string): ShopEmbedding[] {
+    const stmt = this.db.prepare(`
+      SELECT se.* FROM shop_embeddings se
+      JOIN shop_content sc ON se.shop_content_id = sc.id
+      WHERE sc.shop_id = ?
+      ORDER BY se.created_at DESC
+    `);
+    return stmt.all(shopId) as ShopEmbedding[];
+  }
+
   deleteShopEmbedding(id: string): void {
   deleteShopEmbedding(id: string): void {
     this.db.prepare(`
     this.db.prepare(`
       DELETE FROM shop_embeddings
       DELETE FROM shop_embeddings
@@ -1407,12 +1417,13 @@ export class ShopDatabase {
   /**
   /**
    * Get shop embedding statistics
    * Get shop embedding statistics
    */
    */
-  getShopEmbeddingsStats(shopId: string): { total_embeddings: number; completed: number; failed: number } {
+  getShopEmbeddingsStats(shopId: string): { total_embeddings: number; completed: number; failed: number; pending: number } {
     const stats = this.db.prepare(`
     const stats = this.db.prepare(`
       SELECT
       SELECT
         COUNT(*) as total_embeddings,
         COUNT(*) as total_embeddings,
         SUM(CASE WHEN embedding_status = 'completed' THEN 1 ELSE 0 END) as completed,
         SUM(CASE WHEN embedding_status = 'completed' THEN 1 ELSE 0 END) as completed,
-        SUM(CASE WHEN embedding_status = 'failed' THEN 1 ELSE 0 END) as failed
+        SUM(CASE WHEN embedding_status = 'failed' THEN 1 ELSE 0 END) as failed,
+        SUM(CASE WHEN embedding_status = 'pending' THEN 1 ELSE 0 END) as pending
       FROM shop_embeddings se
       FROM shop_embeddings se
       JOIN shop_content sc ON se.shop_content_id = sc.id
       JOIN shop_content sc ON se.shop_content_id = sc.id
       WHERE sc.shop_id = ?
       WHERE sc.shop_id = ?
@@ -1421,7 +1432,8 @@ export class ShopDatabase {
     return {
     return {
       total_embeddings: stats?.total_embeddings || 0,
       total_embeddings: stats?.total_embeddings || 0,
       completed: stats?.completed || 0,
       completed: stats?.completed || 0,
-      failed: stats?.failed || 0
+      failed: stats?.failed || 0,
+      pending: stats?.pending || 0
     };
     };
   }
   }