Browse Source

fix: wrong field name if create a new vector field

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 2 weeks ago
parent
commit
06ce6d279d
2 changed files with 39 additions and 14 deletions
  1. 27 7
      client/src/pages/dialogs/create/CreateFields.tsx
  2. 12 7
      server/src/utils/Helper.ts

+ 27 - 7
client/src/pages/dialogs/create/CreateFields.tsx

@@ -136,16 +136,36 @@ const CreateFields: FC<CreateFieldsProps> = ({
   const handleAddNewField = (index: number, type = DataTypeEnum.Int16) => {
     const id = generateId();
 
-    // Count existing scalar fields to generate new index
-    let scalarFieldCount = fields.filter(
-      f => !f.is_primary_key && !VectorTypes.includes(f.data_type)
-    ).length;
-    let name = `scalar_field_${scalarFieldCount}`;
+    // Determine field type and generate appropriate name prefix
+    const isVector = VectorTypes.includes(type);
+    const isPrimaryKey = false; // New fields are never primary keys by default
+    
+    let fieldTypePrefix: string;
+    if (isPrimaryKey) {
+      fieldTypePrefix = 'primary_key';
+    } else if (isVector) {
+      fieldTypePrefix = 'vector';
+    } else {
+      fieldTypePrefix = 'scalar';
+    }
+
+    // Count existing fields of the same type to generate new index
+    let fieldCount = fields.filter(f => {
+      if (isPrimaryKey) {
+        return f.is_primary_key;
+      } else if (isVector) {
+        return VectorTypes.includes(f.data_type);
+      } else {
+        return !f.is_primary_key && !VectorTypes.includes(f.data_type);
+      }
+    }).length;
+    
+    let name = `${fieldTypePrefix}_${fieldCount}`;
 
     const existingNames = new Set(fields.map(f => f.name));
     while (existingNames.has(name)) {
-      scalarFieldCount += 1;
-      name = `scalar_field_${scalarFieldCount}`;
+      fieldCount += 1;
+      name = `${fieldTypePrefix}_${fieldCount}`;
     }
 
     const newDefaultItem: FieldType = {

+ 12 - 7
server/src/utils/Helper.ts

@@ -44,27 +44,32 @@ export const makeRandomSparse = (dim: number) => {
 export const makeImageUrl = (): string => {
   const sizes = [
     '200x150',
-    '300x200', 
+    '300x200',
     '400x300',
     '500x400',
     '600x450',
     '800x600',
     '1024x768',
-    '1200x800'
+    '1200x800',
   ];
-  
+
   const formats = ['jpg', 'png', 'gif'];
-  
+
   const randomSize = sizes[Math.floor(Math.random() * sizes.length)];
   const randomFormat = formats[Math.floor(Math.random() * formats.length)];
-  
+
   return `https://dummyimage.com/${randomSize}.${randomFormat}`;
 };
 
 export const makeRandomVarChar = (maxLength: number) => {
-  // 20% 的几率返回图片URL
+  // Check if we should generate URL (20% chance)
   if (Math.random() < 0.2) {
-    return makeImageUrl();
+    const imageUrl = makeImageUrl();
+    // Only return URL if it fits within maxLength
+    if (imageUrl.length <= maxLength) {
+      return imageUrl;
+    }
+    // If URL is too long, fall through to generate text instead
   }
 
   const words = [