Skip to content

Commit

Permalink
add vector support
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-kharse committed Jul 31, 2024
1 parent d85c055 commit 4cb7901
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ message Value {
bytes datetime_val = 9;
string password_val = 10;
uint64 uid_val=11;
// number 12 is reserved for bigfloat
bytes vfloat32_val=13;
}
}

Expand Down
40 changes: 40 additions & 0 deletions src/test/java/io/dgraph/ExceptionTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.dgraph;

import com.google.protobuf.ByteString;
import io.dgraph.DgraphProto.Mutation;
import io.dgraph.DgraphProto.NQuad;
import io.dgraph.DgraphProto.Response;
import io.dgraph.DgraphProto.Value;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -37,4 +39,42 @@ public void testReadOnlyException() {
Transaction txn = dgraphClient.newReadOnlyTransaction();
txn.mutate(mu);
}

@Test
public void testVectorSupport() {
String vect = "[1, 2, 3, 4, 5]";
NQuad quad1 =
NQuad.newBuilder()
.setSubject("0x1000")
.setPredicate("productV")
.setObjectValue(
Value.newBuilder().setVfloat32Val(ByteString.copyFromUtf8(vect)).build())
.build();

System.out.println("quad1: " + quad1.toString());
Mutation mu1 = Mutation.newBuilder().addSet(quad1).build();
Transaction txn = dgraphClient.newTransaction();
Response response1 = txn.mutate(mu1);
System.out.printf("response:---------------------------> " + response1.toString());
try {
txn.commit();
} catch (Exception e) {
System.out.printf("response------------exe: " + e.toString());
}

String query =
"{\n" + " q(func: has(productV)) {\n" + " uid\n" + " productV\n" + " }\n" + "}";

// Create a transaction
Transaction txn1 = dgraphClient.newTransaction();
try {
// Run the query
DgraphProto.Response response = txn1.query(query);

// Print the response JSON
System.out.println(response.getJson().toStringUtf8());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}

0 comments on commit 4cb7901

Please sign in to comment.