|
|
@@ -275,6 +275,45 @@ export async function getCollectionInfo(collectionName: string): Promise<any> {
|
|
|
return response.result;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Generate a deterministic UUID from a string using a simple hash-based approach
|
|
|
+ * This creates valid UUIDs that Qdrant accepts, while being reproducible
|
|
|
+ */
|
|
|
+export function generatePointId(platform: string, storeId: string, itemId: string | number): string {
|
|
|
+ // Create a unique string identifier
|
|
|
+ const uniqueString = `${platform}-${storeId}-${itemId}`;
|
|
|
+
|
|
|
+ // Simple hash function (FNV-1a)
|
|
|
+ let hash = 2166136261;
|
|
|
+ for (let i = 0; i < uniqueString.length; i++) {
|
|
|
+ hash ^= uniqueString.charCodeAt(i);
|
|
|
+ hash = Math.imul(hash, 16777619);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Convert to unsigned 32-bit and add more entropy from second pass
|
|
|
+ const hash1 = Math.abs(hash) >>> 0;
|
|
|
+
|
|
|
+ // Second hash for more bits
|
|
|
+ let hash2 = 2166136261;
|
|
|
+ for (let i = uniqueString.length - 1; i >= 0; i--) {
|
|
|
+ hash2 ^= uniqueString.charCodeAt(i);
|
|
|
+ hash2 = Math.imul(hash2, 16777619);
|
|
|
+ }
|
|
|
+ const hash2Val = Math.abs(hash2) >>> 0;
|
|
|
+
|
|
|
+ // Generate UUID v4 format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
|
+ // Use hash values to create a deterministic but valid UUID
|
|
|
+ const hex = (hash1.toString(16).padStart(8, '0') + hash2Val.toString(16).padStart(8, '0')).padStart(32, '0');
|
|
|
+
|
|
|
+ return [
|
|
|
+ hex.substring(0, 8),
|
|
|
+ hex.substring(8, 12),
|
|
|
+ '4' + hex.substring(13, 16), // Version 4
|
|
|
+ ((parseInt(hex.substring(16, 17), 16) & 0x3) | 0x8).toString(16) + hex.substring(17, 20), // Variant
|
|
|
+ hex.substring(20, 32)
|
|
|
+ ].join('-');
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Generate standardized collection name for a store
|
|
|
*/
|