|
@@ -18,7 +18,7 @@ import {
|
|
|
scrollPoints,
|
|
scrollPoints,
|
|
|
getCollectionName,
|
|
getCollectionName,
|
|
|
initializeStoreCollections,
|
|
initializeStoreCollections,
|
|
|
- generateSimpleEmbedding,
|
|
|
|
|
|
|
+ generateEmbeddingBatch,
|
|
|
createProductText,
|
|
createProductText,
|
|
|
createOrderText,
|
|
createOrderText,
|
|
|
createCustomerText,
|
|
createCustomerText,
|
|
@@ -175,9 +175,9 @@ async function syncProductsToQdrant(
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Convert products to Qdrant points
|
|
|
|
|
- const points: QdrantPoint[] = products.map((product) => {
|
|
|
|
|
- const productText = createProductText({
|
|
|
|
|
|
|
+ // Generate text representations for all products
|
|
|
|
|
+ const productTexts = products.map((product) =>
|
|
|
|
|
+ createProductText({
|
|
|
name: product.name,
|
|
name: product.name,
|
|
|
description: product.description,
|
|
description: product.description,
|
|
|
short_description: product.short_description,
|
|
short_description: product.short_description,
|
|
@@ -188,24 +188,30 @@ async function syncProductsToQdrant(
|
|
|
price: product.price,
|
|
price: product.price,
|
|
|
stock_status: product.stock_status,
|
|
stock_status: product.stock_status,
|
|
|
})
|
|
})
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
- return {
|
|
|
|
|
- id: `woocommerce-${storeId}-${product.id}`,
|
|
|
|
|
- vector: generateSimpleEmbedding(productText),
|
|
|
|
|
- payload: {
|
|
|
|
|
- store_id: storeId,
|
|
|
|
|
- product_id: product.id.toString(),
|
|
|
|
|
- platform: 'woocommerce',
|
|
|
|
|
- name: product.name,
|
|
|
|
|
- sku: product.sku || null,
|
|
|
|
|
- price: parseFloat(product.price) || 0,
|
|
|
|
|
- stock_status: product.stock_status,
|
|
|
|
|
- stock_quantity: product.stock_quantity,
|
|
|
|
|
- type: product.type || 'simple',
|
|
|
|
|
- synced_at: new Date().toISOString(),
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Generate embeddings in batch (more efficient)
|
|
|
|
|
+ console.log(`[Qdrant] Generating embeddings for ${productTexts.length} products...`)
|
|
|
|
|
+ const embeddings = await generateEmbeddingBatch(productTexts)
|
|
|
|
|
+ console.log(`[Qdrant] Embeddings generated successfully`)
|
|
|
|
|
+
|
|
|
|
|
+ // Convert products to Qdrant points with embeddings
|
|
|
|
|
+ const points: QdrantPoint[] = products.map((product, index) => ({
|
|
|
|
|
+ id: `woocommerce-${storeId}-${product.id}`,
|
|
|
|
|
+ vector: embeddings[index],
|
|
|
|
|
+ payload: {
|
|
|
|
|
+ store_id: storeId,
|
|
|
|
|
+ product_id: product.id.toString(),
|
|
|
|
|
+ platform: 'woocommerce',
|
|
|
|
|
+ name: product.name,
|
|
|
|
|
+ sku: product.sku || null,
|
|
|
|
|
+ price: parseFloat(product.price) || 0,
|
|
|
|
|
+ stock_status: product.stock_status,
|
|
|
|
|
+ stock_quantity: product.stock_quantity,
|
|
|
|
|
+ type: product.type || 'simple',
|
|
|
|
|
+ synced_at: new Date().toISOString(),
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
await upsertPoints(collectionName, points)
|
|
await upsertPoints(collectionName, points)
|
|
|
synced = points.length
|
|
synced = points.length
|
|
@@ -270,8 +276,9 @@ async function syncOrdersToQdrant(
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const points: QdrantPoint[] = orders.map((order) => {
|
|
|
|
|
- const orderText = createOrderText({
|
|
|
|
|
|
|
+ // Generate text representations for all orders
|
|
|
|
|
+ const orderTexts = orders.map((order) =>
|
|
|
|
|
+ createOrderText({
|
|
|
order_number: order.number || order.id,
|
|
order_number: order.number || order.id,
|
|
|
customer_name: `${order.billing?.first_name || ''} ${order.billing?.last_name || ''}`.trim(),
|
|
customer_name: `${order.billing?.first_name || ''} ${order.billing?.last_name || ''}`.trim(),
|
|
|
customer_email: order.billing?.email,
|
|
customer_email: order.billing?.email,
|
|
@@ -286,34 +293,40 @@ async function syncOrdersToQdrant(
|
|
|
line_items: order.line_items,
|
|
line_items: order.line_items,
|
|
|
note: order.customer_note,
|
|
note: order.customer_note,
|
|
|
})
|
|
})
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
- return {
|
|
|
|
|
- id: `woocommerce-${storeId}-${order.id}`,
|
|
|
|
|
- vector: generateSimpleEmbedding(orderText),
|
|
|
|
|
- payload: {
|
|
|
|
|
- store_id: storeId,
|
|
|
|
|
- order_id: order.id.toString(),
|
|
|
|
|
- platform: 'woocommerce',
|
|
|
|
|
- order_number: order.number || order.id.toString(),
|
|
|
|
|
- status: order.status,
|
|
|
|
|
- total: parseFloat(order.total) || 0,
|
|
|
|
|
- total_price: parseFloat(order.total) || 0,
|
|
|
|
|
- currency: order.currency || 'USD',
|
|
|
|
|
- customer_name: `${order.billing?.first_name || ''} ${order.billing?.last_name || ''}`.trim(),
|
|
|
|
|
- customer_email: order.billing?.email || null,
|
|
|
|
|
- customer_phone: order.billing?.phone || null,
|
|
|
|
|
- phone: order.billing?.phone || null,
|
|
|
|
|
- billing_address: order.billing || null,
|
|
|
|
|
- billing_city: order.billing?.city || null,
|
|
|
|
|
- billing_country: order.billing?.country || null,
|
|
|
|
|
- shipping_address: order.shipping || null,
|
|
|
|
|
- shipping_city: order.shipping?.city || null,
|
|
|
|
|
- shipping_country: order.shipping?.country || null,
|
|
|
|
|
- note: order.customer_note || null,
|
|
|
|
|
- synced_at: new Date().toISOString(),
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Generate embeddings in batch
|
|
|
|
|
+ console.log(`[Qdrant] Generating embeddings for ${orderTexts.length} orders...`)
|
|
|
|
|
+ const embeddings = await generateEmbeddingBatch(orderTexts)
|
|
|
|
|
+ console.log(`[Qdrant] Embeddings generated successfully`)
|
|
|
|
|
+
|
|
|
|
|
+ // Convert orders to Qdrant points with embeddings
|
|
|
|
|
+ const points: QdrantPoint[] = orders.map((order, index) => ({
|
|
|
|
|
+ id: `woocommerce-${storeId}-${order.id}`,
|
|
|
|
|
+ vector: embeddings[index],
|
|
|
|
|
+ payload: {
|
|
|
|
|
+ store_id: storeId,
|
|
|
|
|
+ order_id: order.id.toString(),
|
|
|
|
|
+ platform: 'woocommerce',
|
|
|
|
|
+ order_number: order.number || order.id.toString(),
|
|
|
|
|
+ status: order.status,
|
|
|
|
|
+ total: parseFloat(order.total) || 0,
|
|
|
|
|
+ total_price: parseFloat(order.total) || 0,
|
|
|
|
|
+ currency: order.currency || 'USD',
|
|
|
|
|
+ customer_name: `${order.billing?.first_name || ''} ${order.billing?.last_name || ''}`.trim(),
|
|
|
|
|
+ customer_email: order.billing?.email || null,
|
|
|
|
|
+ customer_phone: order.billing?.phone || null,
|
|
|
|
|
+ phone: order.billing?.phone || null,
|
|
|
|
|
+ billing_address: order.billing || null,
|
|
|
|
|
+ billing_city: order.billing?.city || null,
|
|
|
|
|
+ billing_country: order.billing?.country || null,
|
|
|
|
|
+ shipping_address: order.shipping || null,
|
|
|
|
|
+ shipping_city: order.shipping?.city || null,
|
|
|
|
|
+ shipping_country: order.shipping?.country || null,
|
|
|
|
|
+ note: order.customer_note || null,
|
|
|
|
|
+ synced_at: new Date().toISOString(),
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
await upsertPoints(collectionName, points)
|
|
await upsertPoints(collectionName, points)
|
|
|
synced = points.length
|
|
synced = points.length
|
|
@@ -376,8 +389,9 @@ async function syncCustomersToQdrant(
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const points: QdrantPoint[] = customers.map((customer) => {
|
|
|
|
|
- const customerText = createCustomerText({
|
|
|
|
|
|
|
+ // Generate text representations for all customers
|
|
|
|
|
+ const customerTexts = customers.map((customer) =>
|
|
|
|
|
+ createCustomerText({
|
|
|
first_name: customer.first_name,
|
|
first_name: customer.first_name,
|
|
|
last_name: customer.last_name,
|
|
last_name: customer.last_name,
|
|
|
username: customer.username,
|
|
username: customer.username,
|
|
@@ -388,29 +402,35 @@ async function syncCustomersToQdrant(
|
|
|
orders_count: customer.orders_count,
|
|
orders_count: customer.orders_count,
|
|
|
total_spent: customer.total_spent,
|
|
total_spent: customer.total_spent,
|
|
|
})
|
|
})
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
- return {
|
|
|
|
|
- id: `woocommerce-${storeId}-${customer.id}`,
|
|
|
|
|
- vector: generateSimpleEmbedding(customerText),
|
|
|
|
|
- payload: {
|
|
|
|
|
- store_id: storeId,
|
|
|
|
|
- customer_id: customer.id.toString(),
|
|
|
|
|
- platform: 'woocommerce',
|
|
|
|
|
- email: customer.email || null,
|
|
|
|
|
- first_name: customer.first_name || null,
|
|
|
|
|
- last_name: customer.last_name || null,
|
|
|
|
|
- username: customer.username || null,
|
|
|
|
|
- phone: customer.billing?.phone || customer.shipping?.phone || null,
|
|
|
|
|
- billing_address: customer.billing || null,
|
|
|
|
|
- shipping_address: customer.shipping || null,
|
|
|
|
|
- city: customer.billing?.city || customer.shipping?.city || null,
|
|
|
|
|
- country: customer.billing?.country || customer.shipping?.country || null,
|
|
|
|
|
- orders_count: customer.orders_count || 0,
|
|
|
|
|
- total_spent: parseFloat(customer.total_spent || '0'),
|
|
|
|
|
- synced_at: new Date().toISOString(),
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Generate embeddings in batch
|
|
|
|
|
+ console.log(`[Qdrant] Generating embeddings for ${customerTexts.length} customers...`)
|
|
|
|
|
+ const embeddings = await generateEmbeddingBatch(customerTexts)
|
|
|
|
|
+ console.log(`[Qdrant] Embeddings generated successfully`)
|
|
|
|
|
+
|
|
|
|
|
+ // Convert customers to Qdrant points with embeddings
|
|
|
|
|
+ const points: QdrantPoint[] = customers.map((customer, index) => ({
|
|
|
|
|
+ id: `woocommerce-${storeId}-${customer.id}`,
|
|
|
|
|
+ vector: embeddings[index],
|
|
|
|
|
+ payload: {
|
|
|
|
|
+ store_id: storeId,
|
|
|
|
|
+ customer_id: customer.id.toString(),
|
|
|
|
|
+ platform: 'woocommerce',
|
|
|
|
|
+ email: customer.email || null,
|
|
|
|
|
+ first_name: customer.first_name || null,
|
|
|
|
|
+ last_name: customer.last_name || null,
|
|
|
|
|
+ username: customer.username || null,
|
|
|
|
|
+ phone: customer.billing?.phone || customer.shipping?.phone || null,
|
|
|
|
|
+ billing_address: customer.billing || null,
|
|
|
|
|
+ shipping_address: customer.shipping || null,
|
|
|
|
|
+ city: customer.billing?.city || customer.shipping?.city || null,
|
|
|
|
|
+ country: customer.billing?.country || customer.shipping?.country || null,
|
|
|
|
|
+ orders_count: customer.orders_count || 0,
|
|
|
|
|
+ total_spent: parseFloat(customer.total_spent || '0'),
|
|
|
|
|
+ synced_at: new Date().toISOString(),
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
await upsertPoints(collectionName, points)
|
|
await upsertPoints(collectionName, points)
|
|
|
synced = points.length
|
|
synced = points.length
|