Skip to content

Commit 85cf5f9

Browse files
fix tests
1 parent cea09ad commit 85cf5f9

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

posting/index.go

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"fmt"
1515
"math"
1616
"os"
17-
"strconv"
1817
"strings"
1918
"sync/atomic"
2019
"time"
@@ -1406,8 +1405,7 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
14061405
StartKey: x.DataKey(rb.Attr, 0),
14071406
})
14081407

1409-
indexer.SetDimension(dimension)
1410-
addDimensionOptionInSchema(rb.CurrentSchema, dimension)
1408+
indexer.SetDimension(rb.CurrentSchema, dimension)
14111409
}
14121410

14131411
fmt.Println("Selecting vector dimension to be:", dimension)
@@ -1457,7 +1455,6 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
14571455

14581456
if count < indexer.NumSeedVectors() {
14591457
indexer.SetNumPasses(0)
1460-
14611458
}
14621459

14631460
for pass_idx := range indexer.NumBuildPasses() {
@@ -1489,21 +1486,24 @@ func rebuildVectorIndex(ctx context.Context, factorySpecs []*tok.FactoryCreateSp
14891486
indexer.EndBuild()
14901487
}
14911488

1492-
txn := NewTxn(rb.StartTs)
14931489
centroids := indexer.GetCentroids()
14941490

1495-
bCentroids, err := json.Marshal(centroids)
1496-
if err != nil {
1497-
return err
1498-
}
1491+
if centroids != nil {
1492+
txn := NewTxn(rb.StartTs)
14991493

1500-
if err := addCentroidInDB(ctx, rb.Attr, bCentroids, txn); err != nil {
1501-
return err
1502-
}
1503-
txn.Update()
1504-
writer := NewTxnWriter(pstore)
1505-
if err := txn.CommitToDisk(writer, rb.StartTs); err != nil {
1506-
return err
1494+
bCentroids, err := json.Marshal(centroids)
1495+
if err != nil {
1496+
return err
1497+
}
1498+
1499+
if err := addCentroidInDB(ctx, rb.Attr, bCentroids, txn); err != nil {
1500+
return err
1501+
}
1502+
txn.Update()
1503+
writer := NewTxnWriter(pstore)
1504+
if err := txn.CommitToDisk(writer, rb.StartTs); err != nil {
1505+
return err
1506+
}
15071507
}
15081508

15091509
numIndexPasses := indexer.NumIndexPasses()
@@ -1705,17 +1705,6 @@ func addCentroidInDB(ctx context.Context, attr string, vec []byte, txn *Txn) err
17051705
return nil
17061706
}
17071707

1708-
func addDimensionOptionInSchema(schema *pb.SchemaUpdate, dimension int) {
1709-
for _, vs := range schema.IndexSpecs {
1710-
if vs.Name == "partionedhnsw" {
1711-
vs.Options = append(vs.Options, &pb.OptionPair{
1712-
Key: "vectorDimension",
1713-
Value: strconv.Itoa(dimension),
1714-
})
1715-
}
1716-
}
1717-
}
1718-
17191708
// rebuildTokIndex rebuilds index for a given attribute.
17201709
// We commit mutations with startTs and ignore the errors.
17211710
func rebuildTokIndex(ctx context.Context, rb *IndexRebuild) error {

tok/hnsw/persistent_hnsw.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/golang/glog"
16+
"github.com/hypermodeinc/dgraph/v25/protos/pb"
1617
c "github.com/hypermodeinc/dgraph/v25/tok/constraints"
1718
"github.com/hypermodeinc/dgraph/v25/tok/index"
1819
opt "github.com/hypermodeinc/dgraph/v25/tok/options"
@@ -125,7 +126,7 @@ func (ph *persistentHNSW[T]) Dimension() int {
125126
return 0
126127
}
127128

128-
func (ph *persistentHNSW[T]) SetDimension(dimension int) {
129+
func (ph *persistentHNSW[T]) SetDimension(schema *pb.SchemaUpdate, dimension int) {
129130
glog.Info("not implemented")
130131
}
131132

tok/index/index.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package index
88
import (
99
"context"
1010

11+
"github.com/hypermodeinc/dgraph/v25/protos/pb"
1112
c "github.com/hypermodeinc/dgraph/v25/tok/constraints"
1213
opts "github.com/hypermodeinc/dgraph/v25/tok/options"
1314
)
@@ -144,7 +145,7 @@ type VectorIndex[T c.Float] interface {
144145
EndBuild() []int
145146
NumThreads() int
146147
Dimension() int
147-
SetDimension(dimension int)
148+
SetDimension(schema *pb.SchemaUpdate, dimension int)
148149
}
149150

150151
// A Txn is an interface representation of a persistent storage transaction,

tok/partitioned_hnsw/partitioned_hnsw.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"context"
88
"errors"
99
"fmt"
10+
"strconv"
1011
"sync"
1112

13+
"github.com/hypermodeinc/dgraph/v25/protos/pb"
1214
c "github.com/hypermodeinc/dgraph/v25/tok/constraints"
1315
hnsw "github.com/hypermodeinc/dgraph/v25/tok/hnsw"
1416
"github.com/hypermodeinc/dgraph/v25/tok/index"
@@ -104,8 +106,16 @@ func (ph *partitionedHNSW[T]) Dimension() int {
104106
return ph.vectorDimension
105107
}
106108

107-
func (ph *partitionedHNSW[T]) SetDimension(dimension int) {
109+
func (ph *partitionedHNSW[T]) SetDimension(schema *pb.SchemaUpdate, dimension int) {
108110
ph.vectorDimension = dimension
111+
for _, vs := range schema.IndexSpecs {
112+
if vs.Name == "partionedhnsw" {
113+
vs.Options = append(vs.Options, &pb.OptionPair{
114+
Key: "vectorDimension",
115+
Value: strconv.Itoa(dimension),
116+
})
117+
}
118+
}
109119
}
110120

111121
func (ph *partitionedHNSW[T]) NumIndexPasses() int {

0 commit comments

Comments
 (0)