Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vector):fix similar_to() error return when data is not present #9084

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion query/vector/vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ func querySingleVectorError(t *testing.T, vector, pred string, validateError boo
return []float32{}, err
}

if len(data.Vector) == 0 {
return []float32{}, nil
}

return data.Vector[0].VTest, nil
}

Expand Down Expand Up @@ -569,8 +573,9 @@ func TestVectorDelete(t *testing.T) {
}

triple := deleteTriple(len(triples) - 2)
// after deleteing all vectors, we should get an empty array of vectors in response when we do silimar_to query
_, err = querySingleVectorError(t, strings.Split(triple, `"`)[1], "vtest", false)
require.NotNil(t, err)
require.NoError(t, err)
}

func TestVectorUpdate(t *testing.T) {
Expand Down
26 changes: 26 additions & 0 deletions systest/vector/vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,29 @@ func TestVectorIndexRebuilding(t *testing.T) {

testVectorQuery(t, gc, vectors, rdfs, pred, numVectors)
}

func TestVectorIndexOnVectorPredWithoutData(t *testing.T) {
conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1).WithACL(time.Hour)
c, err := dgraphtest.NewLocalCluster(conf)
require.NoError(t, err)
defer func() { c.Cleanup(t.Failed()) }()
require.NoError(t, c.Start())

gc, cleanup, err := c.Client()
require.NoError(t, err)
defer cleanup()
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace))

hc, err := c.HTTPClient()
require.NoError(t, err)
require.NoError(t, hc.LoginIntoNamespace(dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace))

require.NoError(t, gc.SetupSchema(testSchema))
pred := "project_discription_v"

vector := []float32{1.0, 2.0, 3.0}
_, err = gc.QueryMultipleVectorsUsingSimilarTo(vector, pred, 10)
require.NoError(t, err)
}
1 change: 1 addition & 0 deletions tok/hnsw/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
DotProd = "dotproduct"
plError = "\nerror fetching posting list for data key: "
dataError = "\nerror fetching data for data key: "
EmptyHNSWTreeError = "HNSW tree has no elements"
VecKeyword = "__vector_"
visitedVectorsLevel = "visited_vectors_level_"
distanceComputations = "vector_distance_computations"
Expand Down
4 changes: 2 additions & 2 deletions tok/hnsw/persistent_hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ func (ph *persistentHNSW[T]) calculateNewEntryVec(
})

if err != nil {
return 0, errors.Wrapf(err, "HNSW tree has no elements")
return 0, errors.Wrapf(err, EmptyHNSWTreeError)
}
if itr == 0 {
return itr, errors.New("HNSW tree has no elements")
return itr, errors.New(EmptyHNSWTreeError)
}

return itr, nil
Expand Down
2 changes: 1 addition & 1 deletion worker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
int(numNeighbors), index.AcceptAll[float32])
}

if err != nil {
if err != nil && !strings.Contains(err.Error(), hnsw.EmptyHNSWTreeError+": "+badger.ErrKeyNotFound.Error()) {
return err
}
sort.Slice(nnUids, func(i, j int) bool { return nnUids[i] < nnUids[j] })
Expand Down