@@ -149,7 +149,13 @@ public ITDatastoreTest(
149149
150150 PROJECT_ID = this .options .getProjectId ();
151151 NAMESPACE = this .options .getNamespace ();
152- System .out .println ("Project: " + PROJECT_ID + ", Namespace: " + NAMESPACE + ", db: " + options .getDatabaseId ());
152+ System .out .println (
153+ "Project: "
154+ + PROJECT_ID
155+ + ", Namespace: "
156+ + NAMESPACE
157+ + ", db: "
158+ + options .getDatabaseId ());
153159
154160 ROOT_KEY =
155161 Key .newBuilder (PROJECT_ID , "rootkey" , "default" , options .getDatabaseId ())
@@ -172,7 +178,8 @@ public ITDatastoreTest(
172178 Key .newBuilder (options .getProjectId (), KIND2 , 100 , options .getDatabaseId ())
173179 .setNamespace (NAMESPACE )
174180 .build ();
175- VECTORKEY = Key .newBuilder (PROJECT_ID , VECTOR_KIND , "bean1" , options .getDatabaseId ())
181+ VECTORKEY =
182+ Key .newBuilder (PROJECT_ID , VECTOR_KIND , "bean1" , options .getDatabaseId ())
176183 .setNamespace (NAMESPACE )
177184 .build ();
178185
@@ -225,28 +232,21 @@ public ITDatastoreTest(
225232 .set ("partial2" , ENTITY2 )
226233 .build ();
227234 VECTOR_ENTITY_1 =
228- Entity .newBuilder (VECTORKEY )
229- .set ("name" , "Arabica" )
230- .set (
231- "embedding_field" ,
232- VectorValue .newBuilder (1.0 , 7.0 , 11.1 ).build ())
233- .build ();
235+ Entity .newBuilder (VECTORKEY )
236+ .set ("name" , "Arabica" )
237+ .set ("embedding_field" , VectorValue .newBuilder (1.0 , 7.0 , 11.1 ).build ())
238+ .build ();
234239 VECTOR_ENTITY_2 =
235- Entity .newBuilder (
236- Key .newBuilder (VECTORKEY ).setName ("bean2" ).build ())
237- .set ("name" , "Robusta" )
238- .set (
239- "embedding_field" ,
240- VectorValue .newBuilder (1.0 , 9.0 , 11.1 ).build ()).set ("vector_distance" , 0 )
241- .build ();
240+ Entity .newBuilder (Key .newBuilder (VECTORKEY ).setName ("bean2" ).build ())
241+ .set ("name" , "Robusta" )
242+ .set ("embedding_field" , VectorValue .newBuilder (1.0 , 9.0 , 11.1 ).build ())
243+ .set ("vector_distance" , 0 )
244+ .build ();
242245 VECTOR_ENTITY_3 =
243- Entity .newBuilder (
244- Key .newBuilder (VECTORKEY ).setName ("bean3" ).build ())
245- .set ("name" , "Excelsa" )
246- .set (
247- "embedding_field" ,
248- VectorValue .newBuilder (4.0 , 9.0 , 11.1 ).build ())
249- .build ();
246+ Entity .newBuilder (Key .newBuilder (VECTORKEY ).setName ("bean3" ).build ())
247+ .set ("name" , "Excelsa" )
248+ .set ("embedding_field" , VectorValue .newBuilder (4.0 , 9.0 , 11.1 ).build ())
249+ .build ();
250250
251251 Key aggregationKey1 = datastore .newKeyFactory ().setKind (MARKS_KIND ).newKey (1 );
252252 Key aggregationKey2 = datastore .newKeyFactory ().setKind (MARKS_KIND ).newKey (2 );
@@ -289,7 +289,7 @@ public void tearDown() {
289289 @ Parameterized .Parameters (name = "database: {2}" )
290290 public static Iterable <Object []> data () {
291291 return Arrays .asList (
292- new Object [][] {{OPTIONS_1 , DATASTORE_1 , "default" }, {OPTIONS_2 , DATASTORE_2 , "test-db" }});
292+ new Object [][] {{OPTIONS_1 , DATASTORE_1 , "default" }, {OPTIONS_2 , DATASTORE_2 , "test-db" }});
293293 }
294294
295295 private <T > Iterator <T > getStronglyConsistentResults (Query scQuery , Query query )
@@ -2120,13 +2120,16 @@ public void testVectorSearchQueryWithLimit() {
21202120 datastore .put (VECTOR_ENTITY_1 , VECTOR_ENTITY_2 , VECTOR_ENTITY_3 );
21212121 // Test FindNearest query with limit
21222122 FindNearest findNearestQueryWithLimit =
2123- new FindNearest (
2124- "embedding_field" ,
2125- VectorValue .newBuilder (1 , 9 , 11.1 ).build (),
2126- FindNearest .DistanceMeasure .DOT_PRODUCT ,
2127- 3 );
2123+ new FindNearest (
2124+ "embedding_field" ,
2125+ VectorValue .newBuilder (1 , 9 , 11.1 ).build (),
2126+ FindNearest .DistanceMeasure .DOT_PRODUCT ,
2127+ 3 );
21282128 Query <Entity > queryWithLimit =
2129- Query .newEntityQueryBuilder ().setKind (VECTOR_KIND ).setFindNearest (findNearestQueryWithLimit ).build ();
2129+ Query .newEntityQueryBuilder ()
2130+ .setKind (VECTOR_KIND )
2131+ .setFindNearest (findNearestQueryWithLimit )
2132+ .build ();
21302133
21312134 QueryResults <Entity > resultWithLimit = datastore .run (queryWithLimit );
21322135
@@ -2142,26 +2145,31 @@ public void testVectorSearchQueryWithDistanceThreshold() {
21422145
21432146 VectorValue vectorValue = VectorValue .newBuilder (1.78 , 2.56 , 3.88 ).build ();
21442147 FindNearest vectorQuery =
2145- new FindNearest (
2146- "embedding_field" , vectorValue , FindNearest .DistanceMeasure .COSINE , 1 , "distance" );
2148+ new FindNearest (
2149+ "embedding_field" , vectorValue , FindNearest .DistanceMeasure .COSINE , 1 , "distance" );
21472150
21482151 Query <Entity > query = Query .newEntityQueryBuilder ().setFindNearest (vectorQuery ).build ();
21492152
2150-
21512153 // Test FindNearest query with distanceThreshold
21522154 FindNearest findNearestQueryWithThreshold =
2153- new FindNearest (
2154- "embedding_field" ,
2155- VectorValue .newBuilder (1 , 9 , 11.1 ).build (),
2156- FindNearest .DistanceMeasure .EUCLIDEAN ,
2157- 3 , "vector_distance" , 2.0 );
2155+ new FindNearest (
2156+ "embedding_field" ,
2157+ VectorValue .newBuilder (1 , 9 , 11.1 ).build (),
2158+ FindNearest .DistanceMeasure .EUCLIDEAN ,
2159+ 3 ,
2160+ "vector_distance" ,
2161+ 2.0 );
21582162 Query <Entity > queryWithWithThreshold =
2159- Query .newEntityQueryBuilder ().setKind (VECTOR_KIND ).setFindNearest (findNearestQueryWithThreshold ).build ();
2163+ Query .newEntityQueryBuilder ()
2164+ .setKind (VECTOR_KIND )
2165+ .setFindNearest (findNearestQueryWithThreshold )
2166+ .build ();
21602167 QueryResults <Entity > resultWithThreshold = datastore .run (queryWithWithThreshold );
21612168 List <Entity > resultsCopyWithThreshold = makeResultsCopy (resultWithThreshold );
21622169 // Verify threshold was applied regardless of limit
21632170 assertEquals (2 , resultsCopyWithThreshold .size ());
2164- // Verify qualified EUCLIDEAN distance: d((1, 9, 11.1), (1, 9, 11.1)) = 0.0, d((1, 9, 11.1), (1, 7, 11.1)) = 2.0
2171+ // Verify qualified EUCLIDEAN distance: d((1, 9, 11.1), (1, 9, 11.1)) = 0.0, d((1, 9, 11.1), (1,
2172+ // 7, 11.1)) = 2.0
21652173 assertEquals (DoubleValue .of (0.0 ), resultsCopyWithThreshold .get (0 ).getValue ("vector_distance" ));
21662174 assertEquals (DoubleValue .of (2.0 ), resultsCopyWithThreshold .get (1 ).getValue ("vector_distance" ));
21672175 }
@@ -2171,21 +2179,26 @@ public void testQueryWithVectorSearchWithDistanceField() {
21712179 datastore .put (VECTOR_ENTITY_1 , VECTOR_ENTITY_2 , VECTOR_ENTITY_3 );
21722180 // Test FindNearest query with distanceField
21732181 FindNearest findNearestQueryWithDistanceField =
2174- new FindNearest (
2175- "embedding_field" ,
2176- VectorValue .newBuilder (1 , 9 , 11.1 ).build (),
2177- FindNearest .DistanceMeasure .DOT_PRODUCT ,
2178- 3 , "vector_distance" , 0.0 );
2182+ new FindNearest (
2183+ "embedding_field" ,
2184+ VectorValue .newBuilder (1 , 9 , 11.1 ).build (),
2185+ FindNearest .DistanceMeasure .DOT_PRODUCT ,
2186+ 3 ,
2187+ "vector_distance" ,
2188+ 0.0 );
21792189 Query <Entity > queryWithWithDistanceField =
2180- Query .newEntityQueryBuilder ().setKind (VECTOR_KIND ).setFindNearest (findNearestQueryWithDistanceField ).build ();
2190+ Query .newEntityQueryBuilder ()
2191+ .setKind (VECTOR_KIND )
2192+ .setFindNearest (findNearestQueryWithDistanceField )
2193+ .build ();
21812194 QueryResults <Entity > resultWithDistanceField = datastore .run (queryWithWithDistanceField );
21822195 List <Entity > resultsCopyWithDistanceField = makeResultsCopy (resultWithDistanceField );
21832196 // Verify results count
21842197 assertEquals (3 , resultsCopyWithDistanceField .size ());
2185- for (int i = 0 ; i < resultsCopyWithDistanceField .size (); i ++)
2186- {
2198+ for (int i = 0 ; i < resultsCopyWithDistanceField .size (); i ++) {
21872199 // Verify distance field was not 0
2188- assertNotEquals (DoubleValue .of (0.0 ), resultsCopyWithDistanceField .get (i ).getValue ("vector_distance" ));
2200+ assertNotEquals (
2201+ DoubleValue .of (0.0 ), resultsCopyWithDistanceField .get (i ).getValue ("vector_distance" ));
21892202 }
21902203 }
21912204
@@ -2238,7 +2251,7 @@ public void testQueryWithReadTime() throws InterruptedException {
22382251 assertEquals (entity2 , withReadTime .next ());
22392252 assertFalse (withReadTime .hasNext ());
22402253 } finally {
2241- // datastore.delete(entity1.getKey(), entity2.getKey(), entity3.getKey());
2254+ // datastore.delete(entity1.getKey(), entity2.getKey(), entity3.getKey());
22422255 }
22432256 }
22442257
0 commit comments