|
@@ -95,18 +95,36 @@ export class QdrantEmbeddingWorkflow {
|
|
|
let collectionName: string;
|
|
let collectionName: string;
|
|
|
|
|
|
|
|
if (existingEmbedding && existingEmbedding.collection_name) {
|
|
if (existingEmbedding && existingEmbedding.collection_name) {
|
|
|
- // Reuse existing collection for this URL
|
|
|
|
|
- collectionName = existingEmbedding.collection_name;
|
|
|
|
|
- logger.debug(`Reusing existing collection ${collectionName} for content ${contentId}`);
|
|
|
|
|
-
|
|
|
|
|
- // Delete all existing points in this collection for this content_id
|
|
|
|
|
- // This ensures we don't have duplicate/stale chunks
|
|
|
|
|
- await this.qdrantService.deletePointsByContentId(collectionName, contentId);
|
|
|
|
|
-
|
|
|
|
|
- // Delete all existing embedding records for this content
|
|
|
|
|
- // We'll create new ones for each chunk
|
|
|
|
|
- for (const emb of existingEmbeddings) {
|
|
|
|
|
- this.database.deleteShopEmbedding(emb.id);
|
|
|
|
|
|
|
+ // Check if the collection still exists in Qdrant
|
|
|
|
|
+ const collectionExists = await this.qdrantService.collectionExists(existingEmbedding.collection_name);
|
|
|
|
|
+
|
|
|
|
|
+ if (collectionExists) {
|
|
|
|
|
+ // Reuse existing collection for this URL
|
|
|
|
|
+ collectionName = existingEmbedding.collection_name;
|
|
|
|
|
+ logger.debug(`Reusing existing collection ${collectionName} for content ${contentId}`);
|
|
|
|
|
+
|
|
|
|
|
+ // Delete all existing points in this collection for this content_id
|
|
|
|
|
+ // This ensures we don't have duplicate/stale chunks
|
|
|
|
|
+ await this.qdrantService.deletePointsByContentId(collectionName, contentId);
|
|
|
|
|
+
|
|
|
|
|
+ // Delete all existing embedding records for this content
|
|
|
|
|
+ // We'll create new ones for each chunk
|
|
|
|
|
+ for (const emb of existingEmbeddings) {
|
|
|
|
|
+ this.database.deleteShopEmbedding(emb.id);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Collection was deleted externally, clean up database and get new iterator
|
|
|
|
|
+ logger.info(`Collection ${existingEmbedding.collection_name} no longer exists in Qdrant, assigning new collection`);
|
|
|
|
|
+
|
|
|
|
|
+ // Delete all existing embedding records for this content
|
|
|
|
|
+ for (const emb of existingEmbeddings) {
|
|
|
|
|
+ this.database.deleteShopEmbedding(emb.id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Get next iterator for this category (one collection per URL)
|
|
|
|
|
+ const iterator = await this.qdrantService.getNextIterator(shop.custom_id, contentType);
|
|
|
|
|
+ collectionName = this.qdrantService.generateCollectionName(shop.custom_id, contentType, iterator);
|
|
|
|
|
+ logger.info(`Assigned new collection ${collectionName} for content ${contentId}`);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// Get next iterator for this category (one collection per URL)
|
|
// Get next iterator for this category (one collection per URL)
|