3939public abstract class VertexAiSearchTool extends BaseTool {
4040 public abstract Optional <String > dataStoreId ();
4141
42- public abstract Optional < List < VertexAISearchDataStoreSpec > > dataStoreSpecs ();
42+ public abstract ImmutableList < VertexAISearchDataStoreSpec > dataStoreSpecs ();
4343
4444 public abstract Optional <String > searchEngineId ();
4545
@@ -54,7 +54,7 @@ public abstract class VertexAiSearchTool extends BaseTool {
5454 public abstract Optional <String > dataStore ();
5555
5656 public static Builder builder () {
57- return new AutoValue_VertexAiSearchTool .Builder ();
57+ return new AutoValue_VertexAiSearchTool .Builder (). dataStoreSpecs ( ImmutableList . of ()) ;
5858 }
5959
6060 VertexAiSearchTool () {
@@ -80,14 +80,16 @@ public Completable processLlmRequest(
8080 searchEngineId ().ifPresent (vertexAiSearchBuilder ::engine );
8181 filter ().ifPresent (vertexAiSearchBuilder ::filter );
8282 maxResults ().ifPresent (vertexAiSearchBuilder ::maxResults );
83- dataStoreSpecs ().ifPresent (vertexAiSearchBuilder ::dataStoreSpecs );
83+ if (!dataStoreSpecs ().isEmpty ()) {
84+ vertexAiSearchBuilder .dataStoreSpecs (dataStoreSpecs ());
85+ }
8486
8587 Tool retrievalTool =
8688 Tool .builder ()
8789 .retrieval (Retrieval .builder ().vertexAiSearch (vertexAiSearchBuilder .build ()).build ())
8890 .build ();
8991
90- List <Tool > currentTools =
92+ ArrayList <Tool > currentTools =
9193 new ArrayList <>(
9294 llmRequest .config ().flatMap (GenerateContentConfig ::tools ).orElse (ImmutableList .of ()));
9395 currentTools .add (retrievalTool );
@@ -126,14 +128,18 @@ public abstract static class Builder {
126128
127129 public final VertexAiSearchTool build () {
128130 VertexAiSearchTool tool = autoBuild ();
129- if ((tool .dataStoreId ().isEmpty () && tool .searchEngineId ().isEmpty ())
130- || (tool .dataStoreId ().isPresent () && tool .searchEngineId ().isPresent ())) {
131+ boolean hasDataStoreId =
132+ tool .dataStoreId ().isPresent () && !tool .dataStoreId ().get ().isEmpty ();
133+ boolean hasSearchEngineId =
134+ tool .searchEngineId ().isPresent () && !tool .searchEngineId ().get ().isEmpty ();
135+ boolean hasDataStoreSpecs = !tool .dataStoreSpecs ().isEmpty ();
136+ if (hasDataStoreId == hasSearchEngineId ) {
131137 throw new IllegalArgumentException (
132- "Either dataStoreId or searchEngineId must be specified ." );
138+ "One and only one of dataStoreId or searchEngineId must not be empty ." );
133139 }
134- if (tool . dataStoreSpecs (). isPresent () && tool . searchEngineId (). isEmpty () ) {
140+ if (hasDataStoreSpecs && ! hasSearchEngineId ) {
135141 throw new IllegalArgumentException (
136- "searchEngineId must be specified if dataStoreSpecs is specified ." );
142+ "searchEngineId must not be empty if dataStoreSpecs is not empty ." );
137143 }
138144 return tool ;
139145 }
0 commit comments