Skip to content

Commit 1c73ec9

Browse files
chore: generate libraries at Sat Dec 14 01:46:19 UTC 2024
1 parent a4f2a6c commit 1c73ec9

File tree

7 files changed

+80
-61
lines changed

7 files changed

+80
-61
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,13 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-datastore/tre
375375
| Query Profile Explain Aggregation | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/queryprofile/QueryProfileExplainAggregation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/queryprofile/QueryProfileExplainAggregation.java) |
376376
| Query Profile Explain Analyze | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/queryprofile/QueryProfileExplainAnalyze.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/queryprofile/QueryProfileExplainAnalyze.java) |
377377
| Query Profile Explain Analyze Aggregation | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/queryprofile/QueryProfileExplainAnalyzeAggregation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/queryprofile/QueryProfileExplainAnalyzeAggregation.java) |
378+
| Store Vectors | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/vectorsearch/StoreVectors.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/vectorsearch/StoreVectors.java) |
379+
| Vector Search Basic | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchBasic.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchBasic.java) |
380+
| Vector Search Distance Result Property | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceResultProperty.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceResultProperty.java) |
381+
| Vector Search Distance Result Property Projection | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceResultPropertyProjection.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceResultPropertyProjection.java) |
382+
| Vector Search Distance Threshold | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceThreshold.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchDistanceThreshold.java) |
383+
| Vector Search Large Response | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchLargeResponse.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchLargeResponse.java) |
384+
| Vector Search Prefilter | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchPrefilter.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/vectorsearch/VectorSearchPrefilter.java) |
378385
| Task List | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/google/datastore/snippets/TaskList.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/datastore/snippets/TaskList.java) |
379386

380387

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ 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);
4646
System.out.printf("Saved %s: %s%n", entity.getKey().getName(), entity.getString("description"));
4747

4848
// Retrieve entity
4949
Entity retrieved = datastore.get(key);
50-
System.out.printf("Retrieved %s with embedding_field: %s%n",
51-
key.getName(),
52-
retrieved.getVector("embedding_field"));
50+
System.out.printf(
51+
"Retrieved %s with embedding_field: %s%n",
52+
key.getName(), retrieved.getVector("embedding_field"));
5353
}
5454
}
5555
// [END datastore_store_vectors]

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ public static void invoke() throws Exception {
3333

3434
// Create vector search query
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-
1))
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+
1))
44+
.build();
4445

4546
// Execute vector search query
4647
QueryResults<Entity> results = datastore.run(vectorSearchQuery);

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ public static void invoke() throws Exception {
3333

3434
// Create vector search query with projection
3535
Query<ProjectionEntity> vectorSearchQuery =
36-
Query.newProjectionEntityQueryBuilder()
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"))
43-
.setProjection("roast")
44-
.build();
36+
Query.newProjectionEntityQueryBuilder()
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+
.setProjection("roast")
46+
.build();
4547

4648
// Execute vector search query
4749
QueryResults<ProjectionEntity> results = datastore.run(vectorSearchQuery);
@@ -52,9 +54,9 @@ public static void invoke() throws Exception {
5254

5355
while (results.hasNext()) {
5456
ProjectionEntity entity = results.next();
55-
System.out.printf("Entity: %s, Distance: %s%n",
56-
entity.getKey().getName(),
57-
entity.getDouble("vector_distance"));
57+
System.out.printf(
58+
"Entity: %s, Distance: %s%n",
59+
entity.getKey().getName(), entity.getDouble("vector_distance"));
5860
}
5961
}
6062
}

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,23 @@ public static void invoke() throws Exception {
3939

4040
// Create a keys-only vector search query
4141
StructuredQuery<ProjectionEntity> keyOnlyVectorQuery =
42-
Query.newProjectionEntityQueryBuilder()
43-
.setKind("CoffeeBean")
44-
.setProjection("__key__")
45-
.setFindNearest(new FindNearest(
46-
"embedding_field",
47-
VectorValue.newBuilder(1, 9, 11.1).build(),
48-
FindNearest.DistanceMeasure.EUCLIDEAN,
49-
3, "vector_distance", 2.0))
50-
.build();
42+
Query.newProjectionEntityQueryBuilder()
43+
.setKind("CoffeeBean")
44+
.setProjection("__key__")
45+
.setFindNearest(
46+
new FindNearest(
47+
"embedding_field",
48+
VectorValue.newBuilder(1, 9, 11.1).build(),
49+
FindNearest.DistanceMeasure.EUCLIDEAN,
50+
3,
51+
"vector_distance",
52+
2.0))
53+
.build();
5154

5255
QueryResults<ProjectionEntity> keyOnlyResults = datastore.run(keyOnlyVectorQuery);
5356
ProjectionEntity[] keyEntities = Iterators.toArray(keyOnlyResults, ProjectionEntity.class);
5457
Key[] keys =
55-
ImmutableList.copyOf(keyEntities).stream().map(e -> e.getKey()).toArray(Key[]::new);
58+
ImmutableList.copyOf(keyEntities).stream().map(e -> e.getKey()).toArray(Key[]::new);
5659
System.out.printf("Key query result size: %s%n", keys.length);
5760

5861
// Lookup the full entities using the result of the keys only query.
@@ -62,10 +65,11 @@ public static void invoke() throws Exception {
6265

6366
// Combine and print results
6467
for (int i = 0; i < keyEntities.length; i++) {
65-
System.out.printf("Entity: %s, Distance: %s, Roast: %s%n",
66-
keyEntities[i].getKey().getName(),
67-
keyEntities[i].getDouble("vector_distance"),
68-
entitiesArray[i].getString("roast"));
68+
System.out.printf(
69+
"Entity: %s, Distance: %s, Roast: %s%n",
70+
keyEntities[i].getKey().getName(),
71+
keyEntities[i].getDouble("vector_distance"),
72+
entitiesArray[i].getString("roast"));
6973
}
7074
}
7175
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ public static void invoke() throws Exception {
3434

3535
// Create vector search query with property filter
3636
Query<Entity> vectorSearchQuery =
37-
Query.newEntityQueryBuilder()
38-
.setKind("CoffeeBean")
39-
.setFilter(PropertyFilter.eq("roast", "dark"))
40-
.setFindNearest(new FindNearest(
41-
"embedding_field",
42-
VectorValue.newBuilder(1, 9, 11.1).build(),
43-
FindNearest.DistanceMeasure.EUCLIDEAN,
44-
3, "vector_distance", 3.0))
45-
.build();
37+
Query.newEntityQueryBuilder()
38+
.setKind("CoffeeBean")
39+
.setFilter(PropertyFilter.eq("roast", "dark"))
40+
.setFindNearest(
41+
new FindNearest(
42+
"embedding_field",
43+
VectorValue.newBuilder(1, 9, 11.1).build(),
44+
FindNearest.DistanceMeasure.EUCLIDEAN,
45+
3,
46+
"vector_distance",
47+
3.0))
48+
.build();
4649

4750
// Execute vector search query
4851
QueryResults<Entity> results = datastore.run(vectorSearchQuery);
@@ -53,9 +56,9 @@ public static void invoke() throws Exception {
5356

5457
while (results.hasNext()) {
5558
Entity entity = results.next();
56-
System.out.printf("Entity: %s, Distance: %s%n",
57-
entity.getKey().getName(),
58-
entity.getDouble("vector_distance"));
59+
System.out.printf(
60+
"Entity: %s, Distance: %s%n",
61+
entity.getKey().getName(), entity.getDouble("vector_distance"));
5962
}
6063
}
6164
}

samples/snippets/src/test/java/com/example/datastore/vectorsearch/VectorSearchSampleIT.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,33 @@ public class VectorSearchSampleIT {
3838
private Key coffeeBeanKey2;
3939
private Key coffeeBeanKey3;
4040

41-
@Rule
42-
public final SystemsOutRule systemsOutRule = new SystemsOutRule();
41+
@Rule public final SystemsOutRule systemsOutRule = new SystemsOutRule();
4342

4443
@Before
4544
public void setUp() {
46-
//DatastoreOptions.getDefaultHttpTransportOptions()
45+
// DatastoreOptions.getDefaultHttpTransportOptions()
4746
coffeeBeanKey1 = datastore.newKeyFactory().setKind("CoffeeBean").newKey("Kahawa");
4847
// Prepares the entity with a vector embedding
49-
Entity entity1 = Entity.newBuilder(coffeeBeanKey1)
48+
Entity entity1 =
49+
Entity.newBuilder(coffeeBeanKey1)
5050
.set("name", "Arabica")
5151
.set("description", "Information about the Arabica coffee beans.")
5252
.set("roast", "dark")
5353
.set("embedding_field", VectorValue.newBuilder(1.0, 7.0, 11.1).build())
5454
.build();
5555

5656
coffeeBeanKey2 = datastore.newKeyFactory().setKind("CoffeeBean").newKey("Robusta");
57-
Entity entity2 = Entity.newBuilder(coffeeBeanKey2)
57+
Entity entity2 =
58+
Entity.newBuilder(coffeeBeanKey2)
5859
.set("name", "Robusta")
5960
.set("description", "Information about the Robusta coffee beans.")
6061
.set("roast", "light")
6162
.set("embedding_field", VectorValue.newBuilder(1.0, 9.0, 11.1).build())
6263
.build();
6364

6465
coffeeBeanKey3 = datastore.newKeyFactory().setKind("CoffeeBean").newKey("Excelsa");
65-
Entity entity3 = Entity.newBuilder(coffeeBeanKey3)
66+
Entity entity3 =
67+
Entity.newBuilder(coffeeBeanKey3)
6668
.set("name", "Excelsa")
6769
.set("description", "Information about the Excelsa coffee beans.")
6870
.set("roast", "dark")

0 commit comments

Comments
 (0)