Skip to content

Commit 402d2cd

Browse files
committed
Resolving conflicts
2 parents 6679cd2 + 4d0a125 commit 402d2cd

File tree

7 files changed

+48
-37
lines changed

7 files changed

+48
-37
lines changed

samples/snippets/src/main/java/com/example/datastore/vectorsearch/StoreVectors.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import com.google.cloud.datastore.Datastore;
2222
import com.google.cloud.datastore.DatastoreOptions;
23-
import com.google.cloud.datastore.Key;
2423
import com.google.cloud.datastore.Entity;
24+
import com.google.cloud.datastore.Key;
2525
import com.google.cloud.datastore.VectorValue;
2626

2727
public class StoreVectors {
@@ -34,12 +34,12 @@ public static void invoke() throws Exception {
3434

3535
// Prepares the entity with a vector embedding
3636
Entity entity =
37-
Entity.newBuilder(key)
38-
.set("name", "Kahawa")
39-
.set("description", "Information about the Kahawa coffee beans.")
40-
.set("roast", "dark")
41-
.set("embedding_field", VectorValue.newBuilder(1.0, 7.0, 11.1).build())
42-
.build();
37+
Entity.newBuilder(key)
38+
.set("name", "Kahawa")
39+
.set("description", "Information about the Kahawa coffee beans.")
40+
.set("roast", "dark")
41+
.set("embedding_field", VectorValue.newBuilder(1.0, 7.0, 11.1).build())
42+
.build();
4343

4444
// Saves the entity
4545
datastore.put(entity);

samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchBasic.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
import com.google.cloud.datastore.Datastore;
2222
import com.google.cloud.datastore.DatastoreOptions;
2323
import com.google.cloud.datastore.Entity;
24+
import com.google.cloud.datastore.FindNearest;
2425
import com.google.cloud.datastore.Query;
2526
import com.google.cloud.datastore.QueryResults;
2627
import com.google.cloud.datastore.VectorValue;
27-
import com.google.cloud.datastore.FindNearest;
2828

2929
public class VectorSearchBasic {
3030
public static void invoke() throws Exception {
3131
// Instantiates a client
3232
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
33+
3334
// Create vector search query
3435
Query<Entity> vectorSearchQuery =
3536
Query.newEntityQueryBuilder()

samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceResultProperty.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import com.google.cloud.datastore.Datastore;
2222
import com.google.cloud.datastore.DatastoreOptions;
2323
import com.google.cloud.datastore.Entity;
24+
import com.google.cloud.datastore.FindNearest;
2425
import com.google.cloud.datastore.Query;
2526
import com.google.cloud.datastore.QueryResults;
2627
import com.google.cloud.datastore.VectorValue;
27-
import com.google.cloud.datastore.FindNearest;
2828

2929
public class VectorSearchDistanceResultProperty {
3030
public static void invoke() throws Exception {
@@ -33,14 +33,16 @@ public static void invoke() throws Exception {
3333

3434
// Create vector search query with distance result property
3535
Query<Entity> vectorSearchQuery =
36-
Query.newEntityQueryBuilder()
37-
.setKind("CoffeeBean")
38-
.setFindNearest(new FindNearest(
39-
"embedding_field",
40-
VectorValue.newBuilder(1, 9, 11.1).build(),
41-
FindNearest.DistanceMeasure.DOT_PRODUCT,
42-
3, "vector_distance"))
43-
.build();
36+
Query.newEntityQueryBuilder()
37+
.setKind("CoffeeBean")
38+
.setFindNearest(
39+
new FindNearest(
40+
"embedding_field",
41+
VectorValue.newBuilder(1, 9, 11.1).build(),
42+
FindNearest.DistanceMeasure.DOT_PRODUCT,
43+
3,
44+
"vector_distance"))
45+
.build();
4446

4547
// Execute vector search query
4648
QueryResults<Entity> results = datastore.run(vectorSearchQuery);
@@ -51,7 +53,9 @@ public static void invoke() throws Exception {
5153

5254
while (results.hasNext()) {
5355
Entity entity = results.next();
54-
System.out.printf("Entity: %s, Distance: %s%n", entity.getKey().getName(), entity.getDouble("vector_distance"));
56+
System.out.printf(
57+
"Entity: %s, Distance: %s%n",
58+
entity.getKey().getName(), entity.getDouble("vector_distance"));
5559
}
5660
}
5761
}

samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceResultPropertyProjection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
import com.google.cloud.datastore.Datastore;
2222
import com.google.cloud.datastore.DatastoreOptions;
23+
import com.google.cloud.datastore.FindNearest;
24+
import com.google.cloud.datastore.ProjectionEntity;
2325
import com.google.cloud.datastore.Query;
2426
import com.google.cloud.datastore.QueryResults;
25-
import com.google.cloud.datastore.ProjectionEntity;
2627
import com.google.cloud.datastore.VectorValue;
27-
import com.google.cloud.datastore.FindNearest;
2828

2929
public class VectorSearchDistanceResultPropertyProjection {
3030
public static void invoke() throws Exception {

samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceThreshold.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import com.google.cloud.datastore.Datastore;
2222
import com.google.cloud.datastore.DatastoreOptions;
2323
import com.google.cloud.datastore.Entity;
24+
import com.google.cloud.datastore.FindNearest;
2425
import com.google.cloud.datastore.Query;
2526
import com.google.cloud.datastore.QueryResults;
2627
import com.google.cloud.datastore.VectorValue;
27-
import com.google.cloud.datastore.FindNearest;
2828

2929
public class VectorSearchDistanceThreshold {
3030
public static void invoke() throws Exception {
@@ -33,14 +33,17 @@ public static void invoke() throws Exception {
3333

3434
// Create vector search query with distance threshold
3535
Query<Entity> vectorSearchQuery =
36-
Query.newEntityQueryBuilder()
37-
.setKind("CoffeeBean")
38-
.setFindNearest(new FindNearest(
39-
"embedding_field",
40-
VectorValue.newBuilder(1, 9, 11.1).build(),
41-
FindNearest.DistanceMeasure.EUCLIDEAN,
42-
3, "vector_distance", 2.0))
43-
.build();
36+
Query.newEntityQueryBuilder()
37+
.setKind("CoffeeBean")
38+
.setFindNearest(
39+
new FindNearest(
40+
"embedding_field",
41+
VectorValue.newBuilder(1, 9, 11.1).build(),
42+
FindNearest.DistanceMeasure.EUCLIDEAN,
43+
3,
44+
"vector_distance",
45+
2.0))
46+
.build();
4447

4548
// Execute vector search query
4649
QueryResults<Entity> results = datastore.run(vectorSearchQuery);
@@ -51,7 +54,9 @@ public static void invoke() throws Exception {
5154

5255
while (results.hasNext()) {
5356
Entity entity = results.next();
54-
System.out.printf("Entity: %s, Distance: %s%n", entity.getKey().getName(), entity.getDouble("vector_distance"));
57+
System.out.printf(
58+
"Entity: %s, Distance: %s%n",
59+
entity.getKey().getName(), entity.getDouble("vector_distance"));
5560
}
5661
}
5762
}

samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchPrefilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import com.google.cloud.datastore.Datastore;
2222
import com.google.cloud.datastore.DatastoreOptions;
2323
import com.google.cloud.datastore.Entity;
24+
import com.google.cloud.datastore.FindNearest;
2425
import com.google.cloud.datastore.Query;
25-
import com.google.cloud.datastore.StructuredQuery.PropertyFilter;
2626
import com.google.cloud.datastore.QueryResults;
27+
import com.google.cloud.datastore.StructuredQuery.PropertyFilter;
2728
import com.google.cloud.datastore.VectorValue;
28-
import com.google.cloud.datastore.FindNearest;
2929

3030
public class VectorSearchPrefilter {
3131
public static void invoke() throws Exception {

samples/snippets/src/test/resources/index.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ indexes:
2929
- name: experience
3030
- kind: CoffeeBean
3131
properties:
32-
- name: __key__
33-
- name: embedding_field
34-
vectorConfig:
35-
dimension: 3
36-
flat: {}
32+
- name: roast
33+
- name: __key__
34+
- name: embedding_field
35+
vectorConfig:
36+
dimension: 3
37+
flat: {}

0 commit comments

Comments
 (0)