@@ -1373,7 +1373,8 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
13731373 }
13741374
13751375 dimension := indexer .Dimension ()
1376- if dimension == 0 {
1376+ // If dimension is -1, it means that the dimension is not set through options in case of partitioned hnsw.
1377+ if dimension == - 1 {
13771378 numVectorsToCheck := 100
13781379 lenFreq := make (map [int ]int , numVectorsToCheck )
13791380 maxFreq := 0
@@ -1410,6 +1411,48 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
14101411
14111412 fmt .Println ("Selecting vector dimension to be:" , dimension )
14121413
1414+ norm := rebuilder {attr : rb .Attr , prefix : pk .DataPrefix (), startTs : rb .StartTs }
1415+ norm .fn = func (uid uint64 , pl * List , txn * Txn ) ([]* pb.DirectedEdge , error ) {
1416+ val , err := pl .Value (rb .StartTs )
1417+ if err != nil {
1418+ return nil , err
1419+ }
1420+ if val .Tid == types .VFloatID {
1421+ return nil , nil
1422+ }
1423+
1424+ // Convert to VFloatID and persist as binary bytes.
1425+ sv , err := types .Convert (val , types .VFloatID )
1426+ if err != nil {
1427+ return nil , err
1428+ }
1429+ b := types .ValueForType (types .BinaryID )
1430+ if err = types .Marshal (sv , & b ); err != nil {
1431+ return nil , err
1432+ }
1433+
1434+ edge := & pb.DirectedEdge {
1435+ Attr : rb .Attr ,
1436+ Entity : uid ,
1437+ Value : b .Value .([]byte ),
1438+ ValueType : types .VFloatID .Enum (),
1439+ }
1440+ inKey := x .DataKey (edge .Attr , uid )
1441+ p , err := txn .Get (inKey )
1442+ if err != nil {
1443+ return []* pb.DirectedEdge {}, err
1444+ }
1445+
1446+ if err := p .addMutation (ctx , txn , edge ); err != nil {
1447+ return []* pb.DirectedEdge {}, err
1448+ }
1449+ return nil , nil
1450+ }
1451+
1452+ if err := norm .RunWithoutTemp (ctx ); err != nil {
1453+ return err
1454+ }
1455+
14131456 count := 0
14141457
14151458 if indexer .NumSeedVectors () > 0 {
@@ -1426,6 +1469,22 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
14261469 if err != nil {
14271470 return err
14281471 }
1472+
1473+ if val .Tid != types .VFloatID {
1474+ // Here, we convert the defaultID type vector into vfloat.
1475+ sv , err := types .Convert (val , types .VFloatID )
1476+ if err != nil {
1477+ return err
1478+ }
1479+ b := types .ValueForType (types .BinaryID )
1480+ if err = types .Marshal (sv , & b ); err != nil {
1481+ return err
1482+ }
1483+
1484+ val .Value = b .Value
1485+ val .Tid = types .VFloatID
1486+ }
1487+
14291488 inVec := types .BytesAsFloatArray (val .Value .([]byte ))
14301489 if len (inVec ) != dimension {
14311490 return fmt .Errorf ("vector dimension mismatch expected dimension %d but got %d" , dimension , len (inVec ))
@@ -1464,7 +1523,6 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
14641523
14651524 builder := rebuilder {attr : rb .Attr , prefix : pk .DataPrefix (), startTs : rb .StartTs }
14661525 builder .fn = func (uid uint64 , pl * List , txn * Txn ) ([]* pb.DirectedEdge , error ) {
1467- edges := []* pb.DirectedEdge {}
14681526 val , err := pl .Value (rb .StartTs )
14691527 if err != nil {
14701528 return []* pb.DirectedEdge {}, err
@@ -1475,7 +1533,7 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
14751533 return []* pb.DirectedEdge {}, nil
14761534 }
14771535 indexer .BuildInsert (ctx , uid , inVec )
1478- return edges , nil
1536+ return [] * pb. DirectedEdge {} , nil
14791537 }
14801538
14811539 err := builder .RunWithoutTemp (ctx )
@@ -1519,21 +1577,22 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
15191577
15201578 builder := rebuilder {attr : rb .Attr , prefix : pk .DataPrefix (), startTs : rb .StartTs }
15211579 builder .fn = func (uid uint64 , pl * List , txn * Txn ) ([]* pb.DirectedEdge , error ) {
1522- edges := []* pb.DirectedEdge {}
15231580 val , err := pl .Value (rb .StartTs )
15241581 if err != nil {
15251582 return []* pb.DirectedEdge {}, err
15261583 }
15271584
15281585 inVec := types .BytesAsFloatArray (val .Value .([]byte ))
1529- if len (inVec ) != dimension {
1586+ if len (inVec ) != dimension && centroids != nil {
15301587 if pass_idx == 0 {
15311588 glog .Warningf ("Skipping vector with invalid dimension uid: %d, dimension: %d" , uid , len (inVec ))
15321589 }
15331590 return []* pb.DirectedEdge {}, nil
15341591 }
1592+
15351593 indexer .BuildInsert (ctx , uid , inVec )
1536- return edges , nil
1594+
1595+ return []* pb.DirectedEdge {}, nil
15371596 }
15381597
15391598 err := builder .RunWithoutTemp (ctx )
0 commit comments