From 374386f7176949747ded628f7f594bfa33a610ef Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 23 Apr 2024 08:34:50 -0700 Subject: [PATCH 01/10] Search May Preview Regeneration - Still need to add varargs convenience --- .../implementation/models/SearchOptions.java | 510 +++++++++--------- .../implementation/models/SearchRequest.java | 28 + .../models/VectorQueryKind.java | 10 + .../implementation/util/FieldBuilder.java | 14 +- .../documents/indexes/SearchableField.java | 14 +- .../models/AIServicesVisionParameters.java | 187 +++++++ .../models/AIServicesVisionVectorizer.java | 112 ++++ .../models/AIStudioModelCatalogName.java | 78 +++ .../indexes/models/AMLParameters.java | 248 +++++++++ .../indexes/models/AMLVectorizer.java | 109 ++++ .../models/AzureOpenAIEmbeddingSkill.java | 81 ++- .../indexes/models/AzureOpenAIModelName.java | 63 +++ .../indexes/models/AzureOpenAIParameters.java | 30 +- .../documents/indexes/models/SearchField.java | 31 ++ .../indexes/models/SearchFieldDataType.java | 5 + .../models/SearchIndexerDataSourceType.java | 5 + .../indexes/models/SearchIndexerSkill.java | 2 + .../models/SearchResourceEncryptionKey.java | 29 +- .../indexes/models/SearchServiceLimits.java | 28 + .../indexes/models/VectorEncodingFormat.java | 48 ++ .../models/VectorSearchAlgorithmMetric.java | 18 +- .../models/VectorSearchVectorizer.java | 4 + .../models/VectorSearchVectorizerKind.java | 11 + .../indexes/models/VisionVectorizeSkill.java | 167 ++++++ .../models/HybridCountAndFacetMode.java | 56 ++ .../search/documents/models/HybridSearch.java | 128 +++++ .../models/SearchScoreThreshold.java | 95 ++++ .../search/documents/models/VectorQuery.java | 74 +++ .../models/VectorSimilarityThreshold.java | 96 ++++ .../documents/models/VectorThreshold.java | 82 +++ .../documents/models/VectorThresholdKind.java | 56 ++ .../models/VectorizableImageBinaryQuery.java | 170 ++++++ .../models/VectorizableImageUrlQuery.java | 168 ++++++ .../models/VectorizableTextQuery.java | 28 + .../documents/models/VectorizedQuery.java | 28 + .../azure-search-documents/swagger/README.md | 4 +- .../main/java/SearchIndexCustomizations.java | 4 + .../java/SearchServiceCustomizations.java | 99 ++-- 38 files changed, 2579 insertions(+), 341 deletions(-) create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionParameters.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionVectorizer.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIStudioModelCatalogName.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLParameters.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLVectorizer.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIModelName.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorEncodingFormat.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VisionVectorizeSkill.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridCountAndFacetMode.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridSearch.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorSimilarityThreshold.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThreshold.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThresholdKind.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java create mode 100644 sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchOptions.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchOptions.java index 828361325615..3849c6358757 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchOptions.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchOptions.java @@ -92,36 +92,6 @@ public final class SearchOptions implements JsonSerializable { */ private String scoringProfile; - /* - * Allows setting a separate search query that will be solely used for semantic reranking, semantic captions and - * semantic answers. Is useful for scenarios where there is a need to use different queries between the base - * retrieval and ranking phase, and the L2 semantic phase. - */ - private String semanticQuery; - - /* - * The name of the semantic configuration that lists which fields should be used for semantic ranking, captions, - * highlights, and answers - */ - private String semanticConfiguration; - - /* - * Allows the user to choose whether a semantic call should fail completely, or to return partial results - * (default). - */ - private SemanticErrorMode semanticErrorHandling; - - /* - * Allows the user to set an upper bound on the amount of time it takes for semantic enrichment to finish - * processing before the request fails. - */ - private Integer semanticMaxWaitInMilliseconds; - - /* - * Enables a debugging tool that can be used to further explore your search results. - */ - private QueryDebugMode debug; - /* * The list of field names to which to scope the full-text search. When using fielded search * (fieldName:searchExpression) in a full Lucene query, the field names of each fielded search expression take @@ -129,26 +99,6 @@ public final class SearchOptions implements JsonSerializable { */ private List searchFields; - /* - * The language of the query. - */ - private QueryLanguage queryLanguage; - - /* - * Improve search recall by spell-correcting individual search query terms. - */ - private QuerySpellerType speller; - - /* - * This parameter is only valid if the query type is `semantic`. If set, the query returns answers extracted from - * key passages in the highest ranked documents. The number of answers returned can be configured by appending the - * pipe character `|` followed by the `count-` option after the answers parameter value, such as - * `extractive|count-3`. Default count is 1. The confidence threshold can be configured by appending the pipe - * character `|` followed by the `threshold-` option after the answers parameter value, such - * as `extractive|threshold-0.9`. Default threshold is 0.7. - */ - private String answers; - /* * A value that specifies whether any or all of the search terms must be matched in order to count the document as * a match. @@ -189,6 +139,34 @@ public final class SearchOptions implements JsonSerializable { */ private Integer top; + /* + * The name of the semantic configuration that lists which fields should be used for semantic ranking, captions, + * highlights, and answers + */ + private String semanticConfiguration; + + /* + * Allows the user to choose whether a semantic call should fail completely, or to return partial results + * (default). + */ + private SemanticErrorMode semanticErrorHandling; + + /* + * Allows the user to set an upper bound on the amount of time it takes for semantic enrichment to finish + * processing before the request fails. + */ + private Integer semanticMaxWaitInMilliseconds; + + /* + * This parameter is only valid if the query type is `semantic`. If set, the query returns answers extracted from + * key passages in the highest ranked documents. The number of answers returned can be configured by appending the + * pipe character `|` followed by the `count-` option after the answers parameter value, such as + * `extractive|count-3`. Default count is 1. The confidence threshold can be configured by appending the pipe + * character `|` followed by the `threshold-` option after the answers parameter value, such + * as `extractive|threshold-0.9`. Default threshold is 0.7. + */ + private String answers; + /* * This parameter is only valid if the query type is `semantic`. If set, the query returns captions extracted from * key passages in the highest ranked documents. When Captions is set to `extractive`, highlighting is enabled by @@ -197,6 +175,28 @@ public final class SearchOptions implements JsonSerializable { */ private String captions; + /* + * Allows setting a separate search query that will be solely used for semantic reranking, semantic captions and + * semantic answers. Is useful for scenarios where there is a need to use different queries between the base + * retrieval and ranking phase, and the L2 semantic phase. + */ + private String semanticQuery; + + /* + * Enables a debugging tool that can be used to further explore your search results. + */ + private QueryDebugMode debug; + + /* + * The language of the query. + */ + private QueryLanguage queryLanguage; + + /* + * Improve search recall by spell-correcting individual search query terms. + */ + private QuerySpellerType speller; + /* * The list of field names used for semantic ranking. */ @@ -462,116 +462,6 @@ public SearchOptions setScoringProfile(String scoringProfile) { return this; } - /** - * Get the semanticQuery property: Allows setting a separate search query that will be solely used for semantic - * reranking, semantic captions and semantic answers. Is useful for scenarios where there is a need to use - * different queries between the base retrieval and ranking phase, and the L2 semantic phase. - * - * @return the semanticQuery value. - */ - public String getSemanticQuery() { - return this.semanticQuery; - } - - /** - * Set the semanticQuery property: Allows setting a separate search query that will be solely used for semantic - * reranking, semantic captions and semantic answers. Is useful for scenarios where there is a need to use - * different queries between the base retrieval and ranking phase, and the L2 semantic phase. - * - * @param semanticQuery the semanticQuery value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setSemanticQuery(String semanticQuery) { - this.semanticQuery = semanticQuery; - return this; - } - - /** - * Get the semanticConfiguration property: The name of the semantic configuration that lists which fields should be - * used for semantic ranking, captions, highlights, and answers. - * - * @return the semanticConfiguration value. - */ - public String getSemanticConfiguration() { - return this.semanticConfiguration; - } - - /** - * Set the semanticConfiguration property: The name of the semantic configuration that lists which fields should be - * used for semantic ranking, captions, highlights, and answers. - * - * @param semanticConfiguration the semanticConfiguration value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setSemanticConfiguration(String semanticConfiguration) { - this.semanticConfiguration = semanticConfiguration; - return this; - } - - /** - * Get the semanticErrorHandling property: Allows the user to choose whether a semantic call should fail - * completely, or to return partial results (default). - * - * @return the semanticErrorHandling value. - */ - public SemanticErrorMode getSemanticErrorHandling() { - return this.semanticErrorHandling; - } - - /** - * Set the semanticErrorHandling property: Allows the user to choose whether a semantic call should fail - * completely, or to return partial results (default). - * - * @param semanticErrorHandling the semanticErrorHandling value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setSemanticErrorHandling(SemanticErrorMode semanticErrorHandling) { - this.semanticErrorHandling = semanticErrorHandling; - return this; - } - - /** - * Get the semanticMaxWaitInMilliseconds property: Allows the user to set an upper bound on the amount of time it - * takes for semantic enrichment to finish processing before the request fails. - * - * @return the semanticMaxWaitInMilliseconds value. - */ - public Integer getSemanticMaxWaitInMilliseconds() { - return this.semanticMaxWaitInMilliseconds; - } - - /** - * Set the semanticMaxWaitInMilliseconds property: Allows the user to set an upper bound on the amount of time it - * takes for semantic enrichment to finish processing before the request fails. - * - * @param semanticMaxWaitInMilliseconds the semanticMaxWaitInMilliseconds value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setSemanticMaxWaitInMilliseconds(Integer semanticMaxWaitInMilliseconds) { - this.semanticMaxWaitInMilliseconds = semanticMaxWaitInMilliseconds; - return this; - } - - /** - * Get the debug property: Enables a debugging tool that can be used to further explore your search results. - * - * @return the debug value. - */ - public QueryDebugMode getDebug() { - return this.debug; - } - - /** - * Set the debug property: Enables a debugging tool that can be used to further explore your search results. - * - * @param debug the debug value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setDebug(QueryDebugMode debug) { - this.debug = debug; - return this; - } - /** * Get the searchFields property: The list of field names to which to scope the full-text search. When using * fielded search (fieldName:searchExpression) in a full Lucene query, the field names of each fielded search @@ -596,76 +486,6 @@ public SearchOptions setSearchFields(List searchFields) { return this; } - /** - * Get the queryLanguage property: The language of the query. - * - * @return the queryLanguage value. - */ - public QueryLanguage getQueryLanguage() { - return this.queryLanguage; - } - - /** - * Set the queryLanguage property: The language of the query. - * - * @param queryLanguage the queryLanguage value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setQueryLanguage(QueryLanguage queryLanguage) { - this.queryLanguage = queryLanguage; - return this; - } - - /** - * Get the speller property: Improve search recall by spell-correcting individual search query terms. - * - * @return the speller value. - */ - public QuerySpellerType getSpeller() { - return this.speller; - } - - /** - * Set the speller property: Improve search recall by spell-correcting individual search query terms. - * - * @param speller the speller value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setSpeller(QuerySpellerType speller) { - this.speller = speller; - return this; - } - - /** - * Get the answers property: This parameter is only valid if the query type is `semantic`. If set, the query - * returns answers extracted from key passages in the highest ranked documents. The number of answers returned can - * be configured by appending the pipe character `|` followed by the `count-<number of answers>` option after - * the answers parameter value, such as `extractive|count-3`. Default count is 1. The confidence threshold can be - * configured by appending the pipe character `|` followed by the `threshold-<confidence threshold>` option - * after the answers parameter value, such as `extractive|threshold-0.9`. Default threshold is 0.7. - * - * @return the answers value. - */ - public String getAnswers() { - return this.answers; - } - - /** - * Set the answers property: This parameter is only valid if the query type is `semantic`. If set, the query - * returns answers extracted from key passages in the highest ranked documents. The number of answers returned can - * be configured by appending the pipe character `|` followed by the `count-<number of answers>` option after - * the answers parameter value, such as `extractive|count-3`. Default count is 1. The confidence threshold can be - * configured by appending the pipe character `|` followed by the `threshold-<confidence threshold>` option - * after the answers parameter value, such as `extractive|threshold-0.9`. Default threshold is 0.7. - * - * @param answers the answers value to set. - * @return the SearchOptions object itself. - */ - public SearchOptions setAnswers(String answers) { - this.answers = answers; - return this; - } - /** * Get the searchMode property: A value that specifies whether any or all of the search terms must be matched in * order to count the document as a match. @@ -808,6 +628,102 @@ public SearchOptions setTop(Integer top) { return this; } + /** + * Get the semanticConfiguration property: The name of the semantic configuration that lists which fields should be + * used for semantic ranking, captions, highlights, and answers. + * + * @return the semanticConfiguration value. + */ + public String getSemanticConfiguration() { + return this.semanticConfiguration; + } + + /** + * Set the semanticConfiguration property: The name of the semantic configuration that lists which fields should be + * used for semantic ranking, captions, highlights, and answers. + * + * @param semanticConfiguration the semanticConfiguration value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setSemanticConfiguration(String semanticConfiguration) { + this.semanticConfiguration = semanticConfiguration; + return this; + } + + /** + * Get the semanticErrorHandling property: Allows the user to choose whether a semantic call should fail + * completely, or to return partial results (default). + * + * @return the semanticErrorHandling value. + */ + public SemanticErrorMode getSemanticErrorHandling() { + return this.semanticErrorHandling; + } + + /** + * Set the semanticErrorHandling property: Allows the user to choose whether a semantic call should fail + * completely, or to return partial results (default). + * + * @param semanticErrorHandling the semanticErrorHandling value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setSemanticErrorHandling(SemanticErrorMode semanticErrorHandling) { + this.semanticErrorHandling = semanticErrorHandling; + return this; + } + + /** + * Get the semanticMaxWaitInMilliseconds property: Allows the user to set an upper bound on the amount of time it + * takes for semantic enrichment to finish processing before the request fails. + * + * @return the semanticMaxWaitInMilliseconds value. + */ + public Integer getSemanticMaxWaitInMilliseconds() { + return this.semanticMaxWaitInMilliseconds; + } + + /** + * Set the semanticMaxWaitInMilliseconds property: Allows the user to set an upper bound on the amount of time it + * takes for semantic enrichment to finish processing before the request fails. + * + * @param semanticMaxWaitInMilliseconds the semanticMaxWaitInMilliseconds value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setSemanticMaxWaitInMilliseconds(Integer semanticMaxWaitInMilliseconds) { + this.semanticMaxWaitInMilliseconds = semanticMaxWaitInMilliseconds; + return this; + } + + /** + * Get the answers property: This parameter is only valid if the query type is `semantic`. If set, the query + * returns answers extracted from key passages in the highest ranked documents. The number of answers returned can + * be configured by appending the pipe character `|` followed by the `count-<number of answers>` option after + * the answers parameter value, such as `extractive|count-3`. Default count is 1. The confidence threshold can be + * configured by appending the pipe character `|` followed by the `threshold-<confidence threshold>` option + * after the answers parameter value, such as `extractive|threshold-0.9`. Default threshold is 0.7. + * + * @return the answers value. + */ + public String getAnswers() { + return this.answers; + } + + /** + * Set the answers property: This parameter is only valid if the query type is `semantic`. If set, the query + * returns answers extracted from key passages in the highest ranked documents. The number of answers returned can + * be configured by appending the pipe character `|` followed by the `count-<number of answers>` option after + * the answers parameter value, such as `extractive|count-3`. Default count is 1. The confidence threshold can be + * configured by appending the pipe character `|` followed by the `threshold-<confidence threshold>` option + * after the answers parameter value, such as `extractive|threshold-0.9`. Default threshold is 0.7. + * + * @param answers the answers value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setAnswers(String answers) { + this.answers = answers; + return this; + } + /** * Get the captions property: This parameter is only valid if the query type is `semantic`. If set, the query * returns captions extracted from key passages in the highest ranked documents. When Captions is set to @@ -834,6 +750,90 @@ public SearchOptions setCaptions(String captions) { return this; } + /** + * Get the semanticQuery property: Allows setting a separate search query that will be solely used for semantic + * reranking, semantic captions and semantic answers. Is useful for scenarios where there is a need to use + * different queries between the base retrieval and ranking phase, and the L2 semantic phase. + * + * @return the semanticQuery value. + */ + public String getSemanticQuery() { + return this.semanticQuery; + } + + /** + * Set the semanticQuery property: Allows setting a separate search query that will be solely used for semantic + * reranking, semantic captions and semantic answers. Is useful for scenarios where there is a need to use + * different queries between the base retrieval and ranking phase, and the L2 semantic phase. + * + * @param semanticQuery the semanticQuery value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setSemanticQuery(String semanticQuery) { + this.semanticQuery = semanticQuery; + return this; + } + + /** + * Get the debug property: Enables a debugging tool that can be used to further explore your search results. + * + * @return the debug value. + */ + public QueryDebugMode getDebug() { + return this.debug; + } + + /** + * Set the debug property: Enables a debugging tool that can be used to further explore your search results. + * + * @param debug the debug value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setDebug(QueryDebugMode debug) { + this.debug = debug; + return this; + } + + /** + * Get the queryLanguage property: The language of the query. + * + * @return the queryLanguage value. + */ + public QueryLanguage getQueryLanguage() { + return this.queryLanguage; + } + + /** + * Set the queryLanguage property: The language of the query. + * + * @param queryLanguage the queryLanguage value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setQueryLanguage(QueryLanguage queryLanguage) { + this.queryLanguage = queryLanguage; + return this; + } + + /** + * Get the speller property: Improve search recall by spell-correcting individual search query terms. + * + * @return the speller value. + */ + public QuerySpellerType getSpeller() { + return this.speller; + } + + /** + * Set the speller property: Improve search recall by spell-correcting individual search query terms. + * + * @param speller the speller value to set. + * @return the SearchOptions object itself. + */ + public SearchOptions setSpeller(QuerySpellerType speller) { + this.speller = speller; + return this; + } + /** * Get the semanticFields property: The list of field names used for semantic ranking. * @@ -870,16 +870,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeArrayField("ScoringParameters", this.scoringParameters, (writer, element) -> writer.writeString(element)); jsonWriter.writeStringField("scoringProfile", this.scoringProfile); - jsonWriter.writeStringField("semanticQuery", this.semanticQuery); - jsonWriter.writeStringField("semanticConfiguration", this.semanticConfiguration); - jsonWriter.writeStringField("semanticErrorHandling", - this.semanticErrorHandling == null ? null : this.semanticErrorHandling.toString()); - jsonWriter.writeNumberField("semanticMaxWaitInMilliseconds", this.semanticMaxWaitInMilliseconds); - jsonWriter.writeStringField("debug", this.debug == null ? null : this.debug.toString()); jsonWriter.writeArrayField("searchFields", this.searchFields, (writer, element) -> writer.writeString(element)); - jsonWriter.writeStringField("queryLanguage", this.queryLanguage == null ? null : this.queryLanguage.toString()); - jsonWriter.writeStringField("speller", this.speller == null ? null : this.speller.toString()); - jsonWriter.writeStringField("answers", this.answers); jsonWriter.writeStringField("searchMode", this.searchMode == null ? null : this.searchMode.toString()); jsonWriter.writeStringField("scoringStatistics", this.scoringStatistics == null ? null : this.scoringStatistics.toString()); @@ -887,7 +878,16 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeArrayField("$select", this.select, (writer, element) -> writer.writeString(element)); jsonWriter.writeNumberField("$skip", this.skip); jsonWriter.writeNumberField("$top", this.top); + jsonWriter.writeStringField("semanticConfiguration", this.semanticConfiguration); + jsonWriter.writeStringField("semanticErrorHandling", + this.semanticErrorHandling == null ? null : this.semanticErrorHandling.toString()); + jsonWriter.writeNumberField("semanticMaxWaitInMilliseconds", this.semanticMaxWaitInMilliseconds); + jsonWriter.writeStringField("answers", this.answers); jsonWriter.writeStringField("captions", this.captions); + jsonWriter.writeStringField("semanticQuery", this.semanticQuery); + jsonWriter.writeStringField("debug", this.debug == null ? null : this.debug.toString()); + jsonWriter.writeStringField("queryLanguage", this.queryLanguage == null ? null : this.queryLanguage.toString()); + jsonWriter.writeStringField("speller", this.speller == null ? null : this.speller.toString()); jsonWriter.writeArrayField("semanticFields", this.semanticFields, (writer, element) -> writer.writeString(element)); return jsonWriter.writeEndObject(); @@ -933,25 +933,9 @@ public static SearchOptions fromJson(JsonReader jsonReader) throws IOException { deserializedSearchOptions.scoringParameters = scoringParameters; } else if ("scoringProfile".equals(fieldName)) { deserializedSearchOptions.scoringProfile = reader.getString(); - } else if ("semanticQuery".equals(fieldName)) { - deserializedSearchOptions.semanticQuery = reader.getString(); - } else if ("semanticConfiguration".equals(fieldName)) { - deserializedSearchOptions.semanticConfiguration = reader.getString(); - } else if ("semanticErrorHandling".equals(fieldName)) { - deserializedSearchOptions.semanticErrorHandling = SemanticErrorMode.fromString(reader.getString()); - } else if ("semanticMaxWaitInMilliseconds".equals(fieldName)) { - deserializedSearchOptions.semanticMaxWaitInMilliseconds = reader.getNullable(JsonReader::getInt); - } else if ("debug".equals(fieldName)) { - deserializedSearchOptions.debug = QueryDebugMode.fromString(reader.getString()); } else if ("searchFields".equals(fieldName)) { List searchFields = reader.readArray(reader1 -> reader1.getString()); deserializedSearchOptions.searchFields = searchFields; - } else if ("queryLanguage".equals(fieldName)) { - deserializedSearchOptions.queryLanguage = QueryLanguage.fromString(reader.getString()); - } else if ("speller".equals(fieldName)) { - deserializedSearchOptions.speller = QuerySpellerType.fromString(reader.getString()); - } else if ("answers".equals(fieldName)) { - deserializedSearchOptions.answers = reader.getString(); } else if ("searchMode".equals(fieldName)) { deserializedSearchOptions.searchMode = SearchMode.fromString(reader.getString()); } else if ("scoringStatistics".equals(fieldName)) { @@ -965,8 +949,24 @@ public static SearchOptions fromJson(JsonReader jsonReader) throws IOException { deserializedSearchOptions.skip = reader.getNullable(JsonReader::getInt); } else if ("$top".equals(fieldName)) { deserializedSearchOptions.top = reader.getNullable(JsonReader::getInt); + } else if ("semanticConfiguration".equals(fieldName)) { + deserializedSearchOptions.semanticConfiguration = reader.getString(); + } else if ("semanticErrorHandling".equals(fieldName)) { + deserializedSearchOptions.semanticErrorHandling = SemanticErrorMode.fromString(reader.getString()); + } else if ("semanticMaxWaitInMilliseconds".equals(fieldName)) { + deserializedSearchOptions.semanticMaxWaitInMilliseconds = reader.getNullable(JsonReader::getInt); + } else if ("answers".equals(fieldName)) { + deserializedSearchOptions.answers = reader.getString(); } else if ("captions".equals(fieldName)) { deserializedSearchOptions.captions = reader.getString(); + } else if ("semanticQuery".equals(fieldName)) { + deserializedSearchOptions.semanticQuery = reader.getString(); + } else if ("debug".equals(fieldName)) { + deserializedSearchOptions.debug = QueryDebugMode.fromString(reader.getString()); + } else if ("queryLanguage".equals(fieldName)) { + deserializedSearchOptions.queryLanguage = QueryLanguage.fromString(reader.getString()); + } else if ("speller".equals(fieldName)) { + deserializedSearchOptions.speller = QuerySpellerType.fromString(reader.getString()); } else if ("semanticFields".equals(fieldName)) { List semanticFields = reader.readArray(reader1 -> reader1.getString()); deserializedSearchOptions.semanticFields = semanticFields; diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java index 54c80cddaa31..9693f4669688 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java @@ -223,6 +223,11 @@ public final class SearchRequest implements JsonSerializable { */ private VectorFilterMode vectorFilterMode; + /* + * The query parameters to configure hybrid search behaviors. + */ + private Object hybridSearch; + /** * Creates an instance of SearchRequest class. */ @@ -945,6 +950,26 @@ public SearchRequest setVectorFilterMode(VectorFilterMode vectorFilterMode) { return this; } + /** + * Get the hybridSearch property: The query parameters to configure hybrid search behaviors. + * + * @return the hybridSearch value. + */ + public Object getHybridSearch() { + return this.hybridSearch; + } + + /** + * Set the hybridSearch property: The query parameters to configure hybrid search behaviors. + * + * @param hybridSearch the hybridSearch value to set. + * @return the SearchRequest object itself. + */ + public SearchRequest setHybridSearch(Object hybridSearch) { + this.hybridSearch = hybridSearch; + return this; + } + @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); @@ -983,6 +1008,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeArrayField("vectorQueries", this.vectorQueries, (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("vectorFilterMode", this.vectorFilterMode == null ? null : this.vectorFilterMode.toString()); + jsonWriter.writeUntypedField("hybridSearch", this.hybridSearch); return jsonWriter.writeEndObject(); } @@ -1066,6 +1092,8 @@ public static SearchRequest fromJson(JsonReader jsonReader) throws IOException { deserializedSearchRequest.vectorQueries = vectorQueries; } else if ("vectorFilterMode".equals(fieldName)) { deserializedSearchRequest.vectorFilterMode = VectorFilterMode.fromString(reader.getString()); + } else if ("hybridSearch".equals(fieldName)) { + deserializedSearchRequest.hybridSearch = reader.readUntyped(); } else { reader.skipChildren(); } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/VectorQueryKind.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/VectorQueryKind.java index 76abc5440ab0..353bf77cd623 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/VectorQueryKind.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/VectorQueryKind.java @@ -23,6 +23,16 @@ public final class VectorQueryKind extends ExpandableStringEnum */ public static final VectorQueryKind TEXT = fromString("text"); + /** + * Vector query where an url that represents an image value that needs to be vectorized is provided. + */ + public static final VectorQueryKind IMAGE_URL = fromString("imageUrl"); + + /** + * Vector query where a base 64 encoded binary of an image that needs to be vectorized is provided. + */ + public static final VectorQueryKind IMAGE_BINARY = fromString("imageBinary"); + /** * Creates a new instance of VectorQueryKind value. * diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java index 62040f0d53c9..badd2cf3b11e 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java @@ -13,11 +13,7 @@ import com.azure.search.documents.indexes.FieldBuilderIgnore; import com.azure.search.documents.indexes.SearchableField; import com.azure.search.documents.indexes.SimpleField; -import com.azure.search.documents.indexes.models.FieldBuilderOptions; -import com.azure.search.documents.indexes.models.LexicalAnalyzerName; -import com.azure.search.documents.indexes.models.LexicalNormalizerName; -import com.azure.search.documents.indexes.models.SearchField; -import com.azure.search.documents.indexes.models.SearchFieldDataType; +import com.azure.search.documents.indexes.models.*; import reactor.util.annotation.Nullable; import java.lang.annotation.Annotation; @@ -279,6 +275,7 @@ private static SearchField enrichWithAnnotation(SearchField searchField, Member String normalizerName; Integer vectorSearchDimensions = null; String vectorSearchProfileName = null; + String vectorEncodingFormat = null; if (simpleField != null) { key = simpleField.isKey(); @@ -304,6 +301,8 @@ private static SearchField enrichWithAnnotation(SearchField searchField, Member ? searchableField.vectorSearchDimensions() : null; vectorSearchProfileName = CoreUtils.isNullOrEmpty(searchableField.vectorSearchProfileName()) ? null : searchableField.vectorSearchProfileName(); + vectorEncodingFormat = CoreUtils.isNullOrEmpty(searchableField.vectorEncodingFormat()) + ? null : searchableField.vectorEncodingFormat(); } StringBuilder errorMessage = new StringBuilder(); @@ -314,6 +313,7 @@ private static SearchField enrichWithAnnotation(SearchField searchField, Member boolean hasSearchAnalyzerName = !CoreUtils.isNullOrEmpty(searchAnalyzerName); boolean hasIndexAnalyzerName = !CoreUtils.isNullOrEmpty(indexAnalyzerName); boolean hasNormalizerName = !CoreUtils.isNullOrEmpty(normalizerName); + boolean hasVectorEncodingFormat = !CoreUtils.isNullOrEmpty(vectorEncodingFormat); if (searchable) { if (!isSearchableType) { errorMessage.append("SearchField can only be used on 'Edm.String', 'Collection(Edm.String)', or " @@ -371,6 +371,10 @@ private static SearchField enrichWithAnnotation(SearchField searchField, Member searchField.setNormalizerName(LexicalNormalizerName.fromString(normalizerName)); } + if (hasVectorEncodingFormat) { + searchField.setVectorEncodingFormat(VectorEncodingFormat.fromString(vectorEncodingFormat)); + } + if (!CoreUtils.isNullOrEmpty(synonymMapNames)) { List synonymMaps = Arrays.stream(searchableField.synonymMapNames()) .filter(synonym -> !synonym.trim().isEmpty()) diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java index 5b6c7ce6b7f1..8e05d6082c0b 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java @@ -3,11 +3,7 @@ package com.azure.search.documents.indexes; -import com.azure.search.documents.indexes.models.FieldBuilderOptions; -import com.azure.search.documents.indexes.models.LexicalAnalyzerName; -import com.azure.search.documents.indexes.models.LexicalNormalizerName; -import com.azure.search.documents.indexes.models.SearchField; -import com.azure.search.documents.indexes.models.SynonymMap; +import com.azure.search.documents.indexes.models.*; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -126,4 +122,12 @@ */ String vectorSearchProfileName() default ""; + /** + * A {@link VectorEncodingFormat} to be associated with the {@link SearchField field}. + *

+ * If the value is empty, the field won't have a {@link SearchField#getVectorEncodingFormat()} value. + * + * @return The {@link VectorEncodingFormat} that will be associated with the {@link SearchField field}. + */ + String vectorEncodingFormat() default ""; } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionParameters.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionParameters.java new file mode 100644 index 000000000000..154f3b7b1840 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionParameters.java @@ -0,0 +1,187 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.indexes.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Specifies the AI Services Vision parameters for vectorizing a query image or text. + */ +@Fluent +public final class AIServicesVisionParameters implements JsonSerializable { + /* + * The version of the model to use when calling the AI Services Vision service. It will default to the latest + * available when not specified. + */ + private final String modelVersion; + + /* + * The resource URI of the AI Services resource. + */ + private final String resourceUri; + + /* + * API key of the designated AI Services resource. + */ + private String apiKey; + + /* + * The user-assigned managed identity used for outbound connections. If an authResourceId is provided and it's not + * specified, the system-assigned managed identity is used. On updates to the index, if the identity is + * unspecified, the value remains unchanged. If set to "none", the value of this property is cleared. + */ + private SearchIndexerDataIdentity authIdentity; + + /** + * Creates an instance of AIServicesVisionParameters class. + * + * @param modelVersion the modelVersion value to set. + * @param resourceUri the resourceUri value to set. + */ + public AIServicesVisionParameters(String modelVersion, String resourceUri) { + this.modelVersion = modelVersion; + this.resourceUri = resourceUri; + } + + /** + * Get the modelVersion property: The version of the model to use when calling the AI Services Vision service. It + * will default to the latest available when not specified. + * + * @return the modelVersion value. + */ + public String getModelVersion() { + return this.modelVersion; + } + + /** + * Get the resourceUri property: The resource URI of the AI Services resource. + * + * @return the resourceUri value. + */ + public String getResourceUri() { + return this.resourceUri; + } + + /** + * Get the apiKey property: API key of the designated AI Services resource. + * + * @return the apiKey value. + */ + public String getApiKey() { + return this.apiKey; + } + + /** + * Set the apiKey property: API key of the designated AI Services resource. + * + * @param apiKey the apiKey value to set. + * @return the AIServicesVisionParameters object itself. + */ + public AIServicesVisionParameters setApiKey(String apiKey) { + this.apiKey = apiKey; + return this; + } + + /** + * Get the authIdentity property: The user-assigned managed identity used for outbound connections. If an + * authResourceId is provided and it's not specified, the system-assigned managed identity is used. On updates to + * the index, if the identity is unspecified, the value remains unchanged. If set to "none", the value of this + * property is cleared. + * + * @return the authIdentity value. + */ + public SearchIndexerDataIdentity getAuthIdentity() { + return this.authIdentity; + } + + /** + * Set the authIdentity property: The user-assigned managed identity used for outbound connections. If an + * authResourceId is provided and it's not specified, the system-assigned managed identity is used. On updates to + * the index, if the identity is unspecified, the value remains unchanged. If set to "none", the value of this + * property is cleared. + * + * @param authIdentity the authIdentity value to set. + * @return the AIServicesVisionParameters object itself. + */ + public AIServicesVisionParameters setAuthIdentity(SearchIndexerDataIdentity authIdentity) { + this.authIdentity = authIdentity; + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("modelVersion", this.modelVersion); + jsonWriter.writeStringField("resourceUri", this.resourceUri); + jsonWriter.writeStringField("apiKey", this.apiKey); + jsonWriter.writeJsonField("authIdentity", this.authIdentity); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AIServicesVisionParameters from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AIServicesVisionParameters if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the AIServicesVisionParameters. + */ + public static AIServicesVisionParameters fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean modelVersionFound = false; + String modelVersion = null; + boolean resourceUriFound = false; + String resourceUri = null; + String apiKey = null; + SearchIndexerDataIdentity authIdentity = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("modelVersion".equals(fieldName)) { + modelVersion = reader.getString(); + modelVersionFound = true; + } else if ("resourceUri".equals(fieldName)) { + resourceUri = reader.getString(); + resourceUriFound = true; + } else if ("apiKey".equals(fieldName)) { + apiKey = reader.getString(); + } else if ("authIdentity".equals(fieldName)) { + authIdentity = SearchIndexerDataIdentity.fromJson(reader); + } else { + reader.skipChildren(); + } + } + if (modelVersionFound && resourceUriFound) { + AIServicesVisionParameters deserializedAIServicesVisionParameters + = new AIServicesVisionParameters(modelVersion, resourceUri); + deserializedAIServicesVisionParameters.apiKey = apiKey; + deserializedAIServicesVisionParameters.authIdentity = authIdentity; + + return deserializedAIServicesVisionParameters; + } + List missingProperties = new ArrayList<>(); + if (!modelVersionFound) { + missingProperties.add("modelVersion"); + } + if (!resourceUriFound) { + missingProperties.add("resourceUri"); + } + + throw new IllegalStateException( + "Missing required property/properties: " + String.join(", ", missingProperties)); + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionVectorizer.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionVectorizer.java new file mode 100644 index 000000000000..7f1befda2497 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIServicesVisionVectorizer.java @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.indexes.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Specifies the AI Services Vision parameters for vectorizing a query image or text. + */ +@Fluent +public final class AIServicesVisionVectorizer extends VectorSearchVectorizer { + /* + * Contains the parameters specific to AI Services Vision embedding vectorization. + */ + private AIServicesVisionParameters aIServicesVisionParameters; + + /** + * Creates an instance of AIServicesVisionVectorizer class. + * + * @param name the name value to set. + */ + public AIServicesVisionVectorizer(String name) { + super(name); + } + + /** + * Get the aIServicesVisionParameters property: Contains the parameters specific to AI Services Vision embedding + * vectorization. + * + * @return the aIServicesVisionParameters value. + */ + public AIServicesVisionParameters getAIServicesVisionParameters() { + return this.aIServicesVisionParameters; + } + + /** + * Set the aIServicesVisionParameters property: Contains the parameters specific to AI Services Vision embedding + * vectorization. + * + * @param aIServicesVisionParameters the aIServicesVisionParameters value to set. + * @return the AIServicesVisionVectorizer object itself. + */ + public AIServicesVisionVectorizer + setAIServicesVisionParameters(AIServicesVisionParameters aIServicesVisionParameters) { + this.aIServicesVisionParameters = aIServicesVisionParameters; + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", VectorSearchVectorizerKind.AISERVICES_VISION == null ? null + : VectorSearchVectorizerKind.AISERVICES_VISION.toString()); + jsonWriter.writeStringField("name", getName()); + jsonWriter.writeJsonField("aiServicesVisionParameters", this.aIServicesVisionParameters); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AIServicesVisionVectorizer from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AIServicesVisionVectorizer if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties or the + * polymorphic discriminator. + * @throws IOException If an error occurs while reading the AIServicesVisionVectorizer. + */ + public static AIServicesVisionVectorizer fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean nameFound = false; + String name = null; + AIServicesVisionParameters aIServicesVisionParameters = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + String kind = reader.getString(); + if (!"aiServicesVision".equals(kind)) { + throw new IllegalStateException( + "'kind' was expected to be non-null and equal to 'aiServicesVision'. The found 'kind' was '" + + kind + "'."); + } + } else if ("name".equals(fieldName)) { + name = reader.getString(); + nameFound = true; + } else if ("aiServicesVisionParameters".equals(fieldName)) { + aIServicesVisionParameters = AIServicesVisionParameters.fromJson(reader); + } else { + reader.skipChildren(); + } + } + if (nameFound) { + AIServicesVisionVectorizer deserializedAIServicesVisionVectorizer + = new AIServicesVisionVectorizer(name); + deserializedAIServicesVisionVectorizer.aIServicesVisionParameters = aIServicesVisionParameters; + + return deserializedAIServicesVisionVectorizer; + } + throw new IllegalStateException("Missing required property: name"); + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIStudioModelCatalogName.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIStudioModelCatalogName.java new file mode 100644 index 000000000000..a73552fdd661 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AIStudioModelCatalogName.java @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.indexes.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The name of the embedding model from the Azure AI Studio Catalog that will be called. + */ +public final class AIStudioModelCatalogName extends ExpandableStringEnum { + /** + * Static value OpenAI-CLIP-Image-Text-Embeddings-vit-base-patch32 for AIStudioModelCatalogName. + */ + public static final AIStudioModelCatalogName OPEN_AICLIP_IMAGE_TEXT_EMBEDDINGS_VIT_BASE_PATCH32 + = fromString("OpenAI-CLIP-Image-Text-Embeddings-vit-base-patch32"); + + /** + * Static value OpenAI-CLIP-Image-Text-Embeddings-ViT-Large-Patch14-336 for AIStudioModelCatalogName. + */ + public static final AIStudioModelCatalogName OPEN_AICLIP_IMAGE_TEXT_EMBEDDINGS_VI_TLARGE_PATCH14336 + = fromString("OpenAI-CLIP-Image-Text-Embeddings-ViT-Large-Patch14-336"); + + /** + * Static value Facebook-DinoV2-Image-Embeddings-ViT-Base for AIStudioModelCatalogName. + */ + public static final AIStudioModelCatalogName FACEBOOK_DINO_V2IMAGE_EMBEDDINGS_VI_TBASE + = fromString("Facebook-DinoV2-Image-Embeddings-ViT-Base"); + + /** + * Static value Facebook-DinoV2-Image-Embeddings-ViT-Giant for AIStudioModelCatalogName. + */ + public static final AIStudioModelCatalogName FACEBOOK_DINO_V2IMAGE_EMBEDDINGS_VI_TGIANT + = fromString("Facebook-DinoV2-Image-Embeddings-ViT-Giant"); + + /** + * Static value Cohere-embed-v3-english for AIStudioModelCatalogName. + */ + public static final AIStudioModelCatalogName COHERE_EMBED_V3ENGLISH = fromString("Cohere-embed-v3-english"); + + /** + * Static value Cohere-embed-v3-multilingual for AIStudioModelCatalogName. + */ + public static final AIStudioModelCatalogName COHERE_EMBED_V3MULTILINGUAL + = fromString("Cohere-embed-v3-multilingual"); + + /** + * Creates a new instance of AIStudioModelCatalogName value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public AIStudioModelCatalogName() { + } + + /** + * Creates or finds a AIStudioModelCatalogName from its string representation. + * + * @param name a name to look for. + * @return the corresponding AIStudioModelCatalogName. + */ + public static AIStudioModelCatalogName fromString(String name) { + return fromString(name, AIStudioModelCatalogName.class); + } + + /** + * Gets known AIStudioModelCatalogName values. + * + * @return known AIStudioModelCatalogName values. + */ + public static Collection values() { + return values(AIStudioModelCatalogName.class); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLParameters.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLParameters.java new file mode 100644 index 000000000000..bce09e0d1505 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLParameters.java @@ -0,0 +1,248 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.indexes.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.search.documents.indexes.implementation.CoreToCodegenBridgeUtils; +import java.io.IOException; +import java.time.Duration; + +/** + * Specifies the properties for connecting to an AML vectorizer. + */ +@Fluent +public final class AMLParameters implements JsonSerializable { + /* + * (Required for no authentication or key authentication) The scoring URI of the AML service to which the JSON + * payload will be sent. Only the https URI scheme is allowed. + */ + private final String scoringUri; + + /* + * (Required for key authentication) The key for the AML service. + */ + private String authenticationKey; + + /* + * (Required for token authentication). The Azure Resource Manager resource ID of the AML service. It should be in + * the format + * subscriptions/{guid}/resourceGroups/{resource-group-name}/Microsoft.MachineLearningServices/workspaces/{workspace + * -name}/services/{service_name}. + */ + private String resourceId; + + /* + * (Optional) When specified, indicates the timeout for the http client making the API call. + */ + private Duration timeout; + + /* + * (Optional for token authentication). The region the AML service is deployed in. + */ + private String region; + + /* + * The name of the embedding model from the Azure AI Studio Catalog that is deployed at the provided endpoint. + */ + private AIStudioModelCatalogName modelName; + + /** + * Creates an instance of AMLParameters class. + * + * @param scoringUri the scoringUri value to set. + */ + public AMLParameters(String scoringUri) { + this.scoringUri = scoringUri; + } + + /** + * Get the scoringUri property: (Required for no authentication or key authentication) The scoring URI of the AML + * service to which the JSON payload will be sent. Only the https URI scheme is allowed. + * + * @return the scoringUri value. + */ + public String getScoringUri() { + return this.scoringUri; + } + + /** + * Get the authenticationKey property: (Required for key authentication) The key for the AML service. + * + * @return the authenticationKey value. + */ + public String getAuthenticationKey() { + return this.authenticationKey; + } + + /** + * Set the authenticationKey property: (Required for key authentication) The key for the AML service. + * + * @param authenticationKey the authenticationKey value to set. + * @return the AMLParameters object itself. + */ + public AMLParameters setAuthenticationKey(String authenticationKey) { + this.authenticationKey = authenticationKey; + return this; + } + + /** + * Get the resourceId property: (Required for token authentication). The Azure Resource Manager resource ID of the + * AML service. It should be in the format + * subscriptions/{guid}/resourceGroups/{resource-group-name}/Microsoft.MachineLearningServices/workspaces/{workspace-name}/services/{service_name}. + * + * @return the resourceId value. + */ + public String getResourceId() { + return this.resourceId; + } + + /** + * Set the resourceId property: (Required for token authentication). The Azure Resource Manager resource ID of the + * AML service. It should be in the format + * subscriptions/{guid}/resourceGroups/{resource-group-name}/Microsoft.MachineLearningServices/workspaces/{workspace-name}/services/{service_name}. + * + * @param resourceId the resourceId value to set. + * @return the AMLParameters object itself. + */ + public AMLParameters setResourceId(String resourceId) { + this.resourceId = resourceId; + return this; + } + + /** + * Get the timeout property: (Optional) When specified, indicates the timeout for the http client making the API + * call. + * + * @return the timeout value. + */ + public Duration getTimeout() { + return this.timeout; + } + + /** + * Set the timeout property: (Optional) When specified, indicates the timeout for the http client making the API + * call. + * + * @param timeout the timeout value to set. + * @return the AMLParameters object itself. + */ + public AMLParameters setTimeout(Duration timeout) { + this.timeout = timeout; + return this; + } + + /** + * Get the region property: (Optional for token authentication). The region the AML service is deployed in. + * + * @return the region value. + */ + public String getRegion() { + return this.region; + } + + /** + * Set the region property: (Optional for token authentication). The region the AML service is deployed in. + * + * @param region the region value to set. + * @return the AMLParameters object itself. + */ + public AMLParameters setRegion(String region) { + this.region = region; + return this; + } + + /** + * Get the modelName property: The name of the embedding model from the Azure AI Studio Catalog that is deployed at + * the provided endpoint. + * + * @return the modelName value. + */ + public AIStudioModelCatalogName getModelName() { + return this.modelName; + } + + /** + * Set the modelName property: The name of the embedding model from the Azure AI Studio Catalog that is deployed at + * the provided endpoint. + * + * @param modelName the modelName value to set. + * @return the AMLParameters object itself. + */ + public AMLParameters setModelName(AIStudioModelCatalogName modelName) { + this.modelName = modelName; + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("uri", this.scoringUri); + jsonWriter.writeStringField("key", this.authenticationKey); + jsonWriter.writeStringField("resourceId", this.resourceId); + jsonWriter.writeStringField("timeout", CoreToCodegenBridgeUtils.durationToStringWithDays(this.timeout)); + jsonWriter.writeStringField("region", this.region); + jsonWriter.writeStringField("modelName", this.modelName == null ? null : this.modelName.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AMLParameters from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AMLParameters if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the AMLParameters. + */ + public static AMLParameters fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean scoringUriFound = false; + String scoringUri = null; + String authenticationKey = null; + String resourceId = null; + Duration timeout = null; + String region = null; + AIStudioModelCatalogName modelName = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("uri".equals(fieldName)) { + scoringUri = reader.getString(); + scoringUriFound = true; + } else if ("key".equals(fieldName)) { + authenticationKey = reader.getString(); + } else if ("resourceId".equals(fieldName)) { + resourceId = reader.getString(); + } else if ("timeout".equals(fieldName)) { + timeout = reader.getNullable(nonNullReader -> Duration.parse(nonNullReader.getString())); + } else if ("region".equals(fieldName)) { + region = reader.getString(); + } else if ("modelName".equals(fieldName)) { + modelName = AIStudioModelCatalogName.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + if (scoringUriFound) { + AMLParameters deserializedAMLParameters = new AMLParameters(scoringUri); + deserializedAMLParameters.authenticationKey = authenticationKey; + deserializedAMLParameters.resourceId = resourceId; + deserializedAMLParameters.timeout = timeout; + deserializedAMLParameters.region = region; + deserializedAMLParameters.modelName = modelName; + + return deserializedAMLParameters; + } + throw new IllegalStateException("Missing required property: uri"); + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLVectorizer.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLVectorizer.java new file mode 100644 index 000000000000..505a34a8d926 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AMLVectorizer.java @@ -0,0 +1,109 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.indexes.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Specifies an Azure Machine Learning endpoint deployed via the Azure AI Studio Model Catalog for generating the + * vector embedding of a query string. + */ +@Fluent +public final class AMLVectorizer extends VectorSearchVectorizer { + /* + * Specifies the properties of the AML vectorizer. + */ + private AMLParameters aMLParameters; + + /** + * Creates an instance of AMLVectorizer class. + * + * @param name the name value to set. + */ + public AMLVectorizer(String name) { + super(name); + } + + /** + * Get the aMLParameters property: Specifies the properties of the AML vectorizer. + * + * @return the aMLParameters value. + */ + public AMLParameters getAMLParameters() { + return this.aMLParameters; + } + + /** + * Set the aMLParameters property: Specifies the properties of the AML vectorizer. + * + * @param aMLParameters the aMLParameters value to set. + * @return the AMLVectorizer object itself. + */ + public AMLVectorizer setAMLParameters(AMLParameters aMLParameters) { + this.aMLParameters = aMLParameters; + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", + VectorSearchVectorizerKind.AML == null ? null : VectorSearchVectorizerKind.AML.toString()); + jsonWriter.writeStringField("name", getName()); + jsonWriter.writeJsonField("amlParameters", this.aMLParameters); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AMLVectorizer from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AMLVectorizer if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties or the + * polymorphic discriminator. + * @throws IOException If an error occurs while reading the AMLVectorizer. + */ + public static AMLVectorizer fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean nameFound = false; + String name = null; + AMLParameters aMLParameters = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + String kind = reader.getString(); + if (!"aml".equals(kind)) { + throw new IllegalStateException( + "'kind' was expected to be non-null and equal to 'aml'. The found 'kind' was '" + kind + + "'."); + } + } else if ("name".equals(fieldName)) { + name = reader.getString(); + nameFound = true; + } else if ("amlParameters".equals(fieldName)) { + aMLParameters = AMLParameters.fromJson(reader); + } else { + reader.skipChildren(); + } + } + if (nameFound) { + AMLVectorizer deserializedAMLVectorizer = new AMLVectorizer(name); + deserializedAMLVectorizer.aMLParameters = aMLParameters; + + return deserializedAMLVectorizer; + } + throw new IllegalStateException("Missing required property: name"); + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIEmbeddingSkill.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIEmbeddingSkill.java index c3be045c074d..c1ed4c55ab13 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIEmbeddingSkill.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIEmbeddingSkill.java @@ -20,17 +20,23 @@ @Fluent public final class AzureOpenAIEmbeddingSkill extends SearchIndexerSkill { /* - * The resource URI for your Azure OpenAI resource. + * The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and + * later models. + */ + private Integer dimensions; + + /* + * The resource URI of the Azure OpenAI resource. */ private String resourceUri; /* - * ID of your Azure OpenAI model deployment on the designated resource. + * ID of the Azure OpenAI model deployment on the designated resource. */ private String deploymentId; /* - * API key for the designated Azure OpenAI resource. + * API key of the designated Azure OpenAI resource. */ private String apiKey; @@ -39,6 +45,11 @@ public final class AzureOpenAIEmbeddingSkill extends SearchIndexerSkill { */ private SearchIndexerDataIdentity authIdentity; + /* + * The name of the embedding model that is deployed at the provided deploymentId path. + */ + private AzureOpenAIModelName modelName; + /** * Creates an instance of AzureOpenAIEmbeddingSkill class. * @@ -50,7 +61,29 @@ public AzureOpenAIEmbeddingSkill(List inputs, List { + /** + * Static value text-embedding-ada-002 for AzureOpenAIModelName. + */ + public static final AzureOpenAIModelName TEXT_EMBEDDING_ADA002 = fromString("text-embedding-ada-002"); + + /** + * Static value text-embedding-3-large for AzureOpenAIModelName. + */ + public static final AzureOpenAIModelName TEXT_EMBEDDING3LARGE = fromString("text-embedding-3-large"); + + /** + * Static value text-embedding-3-small for AzureOpenAIModelName. + */ + public static final AzureOpenAIModelName TEXT_EMBEDDING3SMALL = fromString("text-embedding-3-small"); + + /** + * Static value experimental for AzureOpenAIModelName. + */ + public static final AzureOpenAIModelName EXPERIMENTAL = fromString("experimental"); + + /** + * Creates a new instance of AzureOpenAIModelName value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public AzureOpenAIModelName() { + } + + /** + * Creates or finds a AzureOpenAIModelName from its string representation. + * + * @param name a name to look for. + * @return the corresponding AzureOpenAIModelName. + */ + public static AzureOpenAIModelName fromString(String name) { + return fromString(name, AzureOpenAIModelName.class); + } + + /** + * Gets known AzureOpenAIModelName values. + * + * @return known AzureOpenAIModelName values. + */ + public static Collection values() { + return values(AzureOpenAIModelName.class); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIParameters.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIParameters.java index fb693158aca2..0f8b50ac10ef 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIParameters.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/AzureOpenAIParameters.java @@ -17,7 +17,7 @@ * Specifies the parameters for connecting to the Azure OpenAI resource. */ @Fluent -public final class AzureOpenAIParameters implements JsonSerializable { +public class AzureOpenAIParameters implements JsonSerializable { /* * The resource URI of the Azure OpenAI resource. */ @@ -38,6 +38,11 @@ public final class AzureOpenAIParameters implements JsonSerializable { */ private String vectorSearchProfileName; + /* + * The encoding format to interpret the field contents. + */ + private VectorEncodingFormat vectorEncodingFormat; + /* * A list of the names of synonym maps to associate with this field. This option can be used only with searchable * fields. Currently only one synonym map per field is supported. Assigning a synonym map to a field ensures that @@ -543,6 +548,26 @@ public SearchField setVectorSearchProfileName(String vectorSearchProfileName) { return this; } + /** + * Get the vectorEncodingFormat property: The encoding format to interpret the field contents. + * + * @return the vectorEncodingFormat value. + */ + public VectorEncodingFormat getVectorEncodingFormat() { + return this.vectorEncodingFormat; + } + + /** + * Set the vectorEncodingFormat property: The encoding format to interpret the field contents. + * + * @param vectorEncodingFormat the vectorEncodingFormat value to set. + * @return the SearchField object itself. + */ + public SearchField setVectorEncodingFormat(VectorEncodingFormat vectorEncodingFormat) { + this.vectorEncodingFormat = vectorEncodingFormat; + return this; + } + /** * Get the synonymMapNames property: A list of the names of synonym maps to associate with this field. This option * can be used only with searchable fields. Currently only one synonym map per field is supported. Assigning a @@ -613,6 +638,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("normalizer", this.normalizerName == null ? null : this.normalizerName.toString()); jsonWriter.writeNumberField("dimensions", this.vectorSearchDimensions); jsonWriter.writeStringField("vectorSearchProfile", this.vectorSearchProfileName); + jsonWriter.writeStringField("vectorEncoding", + this.vectorEncodingFormat == null ? null : this.vectorEncodingFormat.toString()); jsonWriter.writeArrayField("synonymMaps", this.synonymMapNames, (writer, element) -> writer.writeString(element)); jsonWriter.writeArrayField("fields", this.fields, (writer, element) -> writer.writeJson(element)); @@ -647,6 +674,7 @@ public static SearchField fromJson(JsonReader jsonReader) throws IOException { LexicalNormalizerName normalizerName = null; Integer vectorSearchDimensions = null; String vectorSearchProfileName = null; + VectorEncodingFormat vectorEncodingFormat = null; List synonymMapNames = null; List fields = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -684,6 +712,8 @@ public static SearchField fromJson(JsonReader jsonReader) throws IOException { vectorSearchDimensions = reader.getNullable(JsonReader::getInt); } else if ("vectorSearchProfile".equals(fieldName)) { vectorSearchProfileName = reader.getString(); + } else if ("vectorEncoding".equals(fieldName)) { + vectorEncodingFormat = VectorEncodingFormat.fromString(reader.getString()); } else if ("synonymMaps".equals(fieldName)) { synonymMapNames = reader.readArray(reader1 -> reader1.getString()); } else if ("fields".equals(fieldName)) { @@ -707,6 +737,7 @@ public static SearchField fromJson(JsonReader jsonReader) throws IOException { deserializedSearchField.normalizerName = normalizerName; deserializedSearchField.vectorSearchDimensions = vectorSearchDimensions; deserializedSearchField.vectorSearchProfileName = vectorSearchProfileName; + deserializedSearchField.vectorEncodingFormat = vectorEncodingFormat; deserializedSearchField.synonymMapNames = synonymMapNames; deserializedSearchField.fields = fields; return deserializedSearchField; diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchFieldDataType.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchFieldDataType.java index cd4bfc06a186..5932418c2a18 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchFieldDataType.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchFieldDataType.java @@ -75,6 +75,11 @@ public final class SearchFieldDataType extends ExpandableStringEnum { + /* * The name of your Azure Key Vault key to be used to encrypt your data at rest. */ @@ -53,7 +53,7 @@ public final class SearchResourceEncryptionKey implements JsonSerializable missingProperties = new ArrayList<>(); @@ -187,7 +185,6 @@ public static SearchResourceEncryptionKey fromJson(JsonReader jsonReader) throws if (!vaultUrlFound) { missingProperties.add("keyVaultUri"); } - throw new IllegalStateException( "Missing required property/properties: " + String.join(", ", missingProperties)); }); @@ -197,7 +194,7 @@ public static SearchResourceEncryptionKey fromJson(JsonReader jsonReader) throws * Get the applicationId property: An AAD Application ID that was granted the required access permissions to the * Azure Key Vault that is to be used when encrypting your data at rest. The Application ID should not be confused * with the Object ID for your AAD Application. - * + * * @return the applicationId value. */ public String getApplicationId() { @@ -208,7 +205,7 @@ public String getApplicationId() { * Set the applicationId property: An AAD Application ID that was granted the required access permissions to the * Azure Key Vault that is to be used when encrypting your data at rest. The Application ID should not be confused * with the Object ID for your AAD Application. - * + * * @param applicationId the applicationId value to set. * @return the SearchResourceEncryptionKey object itself. */ @@ -216,14 +213,13 @@ public SearchResourceEncryptionKey setApplicationId(String applicationId) { if (this.accessCredentials == null) { this.accessCredentials = new AzureActiveDirectoryApplicationCredentials(); } - this.accessCredentials.setApplicationId(applicationId); return this; } /** * Get the applicationSecret property: The authentication key of the specified AAD application. - * + * * @return the applicationSecret value. */ public String getApplicationSecret() { @@ -232,7 +228,7 @@ public String getApplicationSecret() { /** * Set the applicationSecret property: The authentication key of the specified AAD application. - * + * * @param applicationSecret the applicationSecret value to set. * @return the SearchResourceEncryptionKey object itself. */ @@ -240,7 +236,6 @@ public SearchResourceEncryptionKey setApplicationSecret(String applicationSecret if (this.accessCredentials == null) { this.accessCredentials = new AzureActiveDirectoryApplicationCredentials(); } - this.accessCredentials.setApplicationSecret(applicationSecret); return this; } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java index 0bf58d757717..393443a67c80 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java @@ -39,6 +39,11 @@ public final class SearchServiceLimits implements JsonSerializable { + /** + * Encoding format representing bits packed into a wider data type. + */ + public static final VectorEncodingFormat PACKED_BIT = fromString("packedBit"); + + /** + * Creates a new instance of VectorEncodingFormat value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public VectorEncodingFormat() { + } + + /** + * Creates or finds a VectorEncodingFormat from its string representation. + * + * @param name a name to look for. + * @return the corresponding VectorEncodingFormat. + */ + public static VectorEncodingFormat fromString(String name) { + return fromString(name, VectorEncodingFormat.class); + } + + /** + * Gets known VectorEncodingFormat values. + * + * @return known VectorEncodingFormat values. + */ + public static Collection values() { + return values(VectorEncodingFormat.class); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchAlgorithmMetric.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchAlgorithmMetric.java index 547612d0ae2c..eaf0fd6e125a 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchAlgorithmMetric.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchAlgorithmMetric.java @@ -10,24 +10,34 @@ import java.util.Collection; /** - * The similarity metric to use for vector comparisons. + * The similarity metric to use for vector comparisons. It is recommended to choose the same similarity metric as the + * embedding model was trained on. */ public final class VectorSearchAlgorithmMetric extends ExpandableStringEnum { /** - * Static value cosine for VectorSearchAlgorithmMetric. + * Measures the angle between vectors to quantify their similarity, disregarding magnitude. The smaller the angle, + * the closer the similarity. */ public static final VectorSearchAlgorithmMetric COSINE = fromString("cosine"); /** - * Static value euclidean for VectorSearchAlgorithmMetric. + * Computes the straight-line distance between vectors in a multi-dimensional space. The smaller the distance, the + * closer the similarity. */ public static final VectorSearchAlgorithmMetric EUCLIDEAN = fromString("euclidean"); /** - * Static value dotProduct for VectorSearchAlgorithmMetric. + * Calculates the sum of element-wise products to gauge alignment and magnitude similarity. The larger and more + * positive, the closer the similarity. */ public static final VectorSearchAlgorithmMetric DOT_PRODUCT = fromString("dotProduct"); + /** + * Only applicable to bit-packed binary data types. Determines dissimilarity by counting differing positions in + * binary vectors. The fewer differences, the closer the similarity. + */ + public static final VectorSearchAlgorithmMetric HAMMING = fromString("hamming"); + /** * Creates a new instance of VectorSearchAlgorithmMetric value. * diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizer.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizer.java index 39ebfd11823d..092234212721 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizer.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizer.java @@ -79,6 +79,10 @@ public static VectorSearchVectorizer fromJson(JsonReader jsonReader) throws IOEx return AzureOpenAIVectorizer.fromJson(readerToUse.reset()); } else if ("customWebApi".equals(discriminatorValue)) { return CustomVectorizer.fromJson(readerToUse.reset()); + } else if ("aiServicesVision".equals(discriminatorValue)) { + return AIServicesVisionVectorizer.fromJson(readerToUse.reset()); + } else if ("aml".equals(discriminatorValue)) { + return AMLVectorizer.fromJson(readerToUse.reset()); } else { return fromJsonKnownDiscriminator(readerToUse.reset()); } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizerKind.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizerKind.java index 70fda7d2384b..6beb6f78b105 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizerKind.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/VectorSearchVectorizerKind.java @@ -23,6 +23,17 @@ public final class VectorSearchVectorizerKind extends ExpandableStringEnum inputs, List outputs, + String modelVersion) { + super(inputs, outputs); + this.modelVersion = modelVersion; + } + + /** + * Get the modelVersion property: The version of the model to use when calling the AI Services Vision service. It + * will default to the latest available when not specified. + * + * @return the modelVersion value. + */ + public String getModelVersion() { + return this.modelVersion; + } + + /** + * {@inheritDoc} + */ + @Override + public VisionVectorizeSkill setName(String name) { + super.setName(name); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VisionVectorizeSkill setDescription(String description) { + super.setDescription(description); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VisionVectorizeSkill setContext(String context) { + super.setContext(context); + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("@odata.type", "#Microsoft.Skills.Vision.VectorizeSkill"); + jsonWriter.writeArrayField("inputs", getInputs(), (writer, element) -> writer.writeJson(element)); + jsonWriter.writeArrayField("outputs", getOutputs(), (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("name", getName()); + jsonWriter.writeStringField("description", getDescription()); + jsonWriter.writeStringField("context", getContext()); + jsonWriter.writeStringField("modelVersion", this.modelVersion); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VisionVectorizeSkill from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VisionVectorizeSkill if the JsonReader was pointing to an instance of it, or null if it + * was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties or the + * polymorphic discriminator. + * @throws IOException If an error occurs while reading the VisionVectorizeSkill. + */ + public static VisionVectorizeSkill fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean inputsFound = false; + List inputs = null; + boolean outputsFound = false; + List outputs = null; + String name = null; + String description = null; + String context = null; + boolean modelVersionFound = false; + String modelVersion = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("@odata.type".equals(fieldName)) { + String odataType = reader.getString(); + if (!"#Microsoft.Skills.Vision.VectorizeSkill".equals(odataType)) { + throw new IllegalStateException( + "'@odata.type' was expected to be non-null and equal to '#Microsoft.Skills.Vision.VectorizeSkill'. The found '@odata.type' was '" + + odataType + "'."); + } + } else if ("inputs".equals(fieldName)) { + inputs = reader.readArray(reader1 -> InputFieldMappingEntry.fromJson(reader1)); + inputsFound = true; + } else if ("outputs".equals(fieldName)) { + outputs = reader.readArray(reader1 -> OutputFieldMappingEntry.fromJson(reader1)); + outputsFound = true; + } else if ("name".equals(fieldName)) { + name = reader.getString(); + } else if ("description".equals(fieldName)) { + description = reader.getString(); + } else if ("context".equals(fieldName)) { + context = reader.getString(); + } else if ("modelVersion".equals(fieldName)) { + modelVersion = reader.getString(); + modelVersionFound = true; + } else { + reader.skipChildren(); + } + } + if (inputsFound && outputsFound && modelVersionFound) { + VisionVectorizeSkill deserializedVisionVectorizeSkill + = new VisionVectorizeSkill(inputs, outputs, modelVersion); + deserializedVisionVectorizeSkill.setName(name); + deserializedVisionVectorizeSkill.setDescription(description); + deserializedVisionVectorizeSkill.setContext(context); + + return deserializedVisionVectorizeSkill; + } + List missingProperties = new ArrayList<>(); + if (!inputsFound) { + missingProperties.add("inputs"); + } + if (!outputsFound) { + missingProperties.add("outputs"); + } + if (!modelVersionFound) { + missingProperties.add("modelVersion"); + } + + throw new IllegalStateException( + "Missing required property/properties: " + String.join(", ", missingProperties)); + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridCountAndFacetMode.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridCountAndFacetMode.java new file mode 100644 index 000000000000..303fe5ed8da5 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridCountAndFacetMode.java @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Determines whether the count and facets should includes all documents that matched the search query, or only the + * documents that are retrieved within the 'maxTextRecallSize' window. The default value is 'countAllResults'. + */ +public final class HybridCountAndFacetMode extends ExpandableStringEnum { + /** + * Only include documents that were matched within the 'maxTextRecallSize' retrieval window when computing 'count' + * and 'facets'. + */ + public static final HybridCountAndFacetMode COUNT_RETRIEVABLE_RESULTS = fromString("countRetrievableResults"); + + /** + * Include all documents that were matched by the search query when computing 'count' and 'facets', regardless of + * whether or not those documents are within the 'maxTextRecallSize' retrieval window. + */ + public static final HybridCountAndFacetMode COUNT_ALL_RESULTS = fromString("countAllResults"); + + /** + * Creates a new instance of HybridCountAndFacetMode value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public HybridCountAndFacetMode() { + } + + /** + * Creates or finds a HybridCountAndFacetMode from its string representation. + * + * @param name a name to look for. + * @return the corresponding HybridCountAndFacetMode. + */ + public static HybridCountAndFacetMode fromString(String name) { + return fromString(name, HybridCountAndFacetMode.class); + } + + /** + * Gets known HybridCountAndFacetMode values. + * + * @return known HybridCountAndFacetMode values. + */ + public static Collection values() { + return values(HybridCountAndFacetMode.class); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridSearch.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridSearch.java new file mode 100644 index 000000000000..3d606d35ad8b --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/HybridSearch.java @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * TThe query parameters to configure hybrid search behaviors. + */ +@Fluent +public final class HybridSearch implements JsonSerializable { + /* + * Determines the maximum number of documents to be retrieved by the text query portion of a hybrid search request. + * Those documents will be combined with the documents matching the vector queries to produce a single final list + * of results. Choosing a larger maxTextRecallSize value will allow retrieving and paging through more documents + * (using the top and skip parameters), at the cost of higher resource utilization and higher latency. The value + * needs to be between 1 and 10,000. Default is 1000. + */ + private Integer maxTextRecallSize; + + /* + * Determines whether the count and facets should includes all documents that matched the search query, or only the + * documents that are retrieved within the 'maxTextRecallSize' window. + */ + private HybridCountAndFacetMode countAndFacetMode; + + /** + * Creates an instance of HybridSearch class. + */ + public HybridSearch() { + } + + /** + * Get the maxTextRecallSize property: Determines the maximum number of documents to be retrieved by the text query + * portion of a hybrid search request. Those documents will be combined with the documents matching the vector + * queries to produce a single final list of results. Choosing a larger maxTextRecallSize value will allow + * retrieving and paging through more documents (using the top and skip parameters), at the cost of higher resource + * utilization and higher latency. The value needs to be between 1 and 10,000. Default is 1000. + * + * @return the maxTextRecallSize value. + */ + public Integer getMaxTextRecallSize() { + return this.maxTextRecallSize; + } + + /** + * Set the maxTextRecallSize property: Determines the maximum number of documents to be retrieved by the text query + * portion of a hybrid search request. Those documents will be combined with the documents matching the vector + * queries to produce a single final list of results. Choosing a larger maxTextRecallSize value will allow + * retrieving and paging through more documents (using the top and skip parameters), at the cost of higher resource + * utilization and higher latency. The value needs to be between 1 and 10,000. Default is 1000. + * + * @param maxTextRecallSize the maxTextRecallSize value to set. + * @return the HybridSearch object itself. + */ + public HybridSearch setMaxTextRecallSize(Integer maxTextRecallSize) { + this.maxTextRecallSize = maxTextRecallSize; + return this; + } + + /** + * Get the countAndFacetMode property: Determines whether the count and facets should includes all documents that + * matched the search query, or only the documents that are retrieved within the 'maxTextRecallSize' window. + * + * @return the countAndFacetMode value. + */ + public HybridCountAndFacetMode getCountAndFacetMode() { + return this.countAndFacetMode; + } + + /** + * Set the countAndFacetMode property: Determines whether the count and facets should includes all documents that + * matched the search query, or only the documents that are retrieved within the 'maxTextRecallSize' window. + * + * @param countAndFacetMode the countAndFacetMode value to set. + * @return the HybridSearch object itself. + */ + public HybridSearch setCountAndFacetMode(HybridCountAndFacetMode countAndFacetMode) { + this.countAndFacetMode = countAndFacetMode; + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeNumberField("maxTextRecallSize", this.maxTextRecallSize); + jsonWriter.writeStringField("countAndFacetMode", + this.countAndFacetMode == null ? null : this.countAndFacetMode.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of HybridSearch from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of HybridSearch if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the HybridSearch. + */ + public static HybridSearch fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + HybridSearch deserializedHybridSearch = new HybridSearch(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("maxTextRecallSize".equals(fieldName)) { + deserializedHybridSearch.maxTextRecallSize = reader.getNullable(JsonReader::getInt); + } else if ("countAndFacetMode".equals(fieldName)) { + deserializedHybridSearch.countAndFacetMode = HybridCountAndFacetMode.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedHybridSearch; + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java new file mode 100644 index 000000000000..f28a31b12e95 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java @@ -0,0 +1,95 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The results of the vector query will filter based on the '@search.score' value. Note this is the @search.score + * returned as part of the search response. The threshold direction will be chosen for higher @search.score. + */ +@Immutable +public final class SearchScoreThreshold extends VectorThreshold { + /* + * The threshold will filter based on the '@search.score' value. Note this is the @search.score returned as part of + * the search response. The threshold direction will be chosen for higher @search.score. + */ + private final double value; + + /** + * Creates an instance of SearchScoreThreshold class. + * + * @param value the value value to set. + */ + public SearchScoreThreshold(double value) { + this.value = value; + } + + /** + * Get the value property: The threshold will filter based on the '@search.score' value. Note this is the + * + * @search.score returned as part of the search response. The threshold direction will be chosen for higher + * @search.score. + * + * @return the value value. + */ + public double getValue() { + return this.value; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", + VectorThresholdKind.SEARCH_SCORE == null ? null : VectorThresholdKind.SEARCH_SCORE.toString()); + jsonWriter.writeDoubleField("value", this.value); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SearchScoreThreshold from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SearchScoreThreshold if the JsonReader was pointing to an instance of it, or null if it + * was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties or the + * polymorphic discriminator. + * @throws IOException If an error occurs while reading the SearchScoreThreshold. + */ + public static SearchScoreThreshold fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean valueFound = false; + double value = 0.0; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + String kind = reader.getString(); + if (!"searchScore".equals(kind)) { + throw new IllegalStateException( + "'kind' was expected to be non-null and equal to 'searchScore'. The found 'kind' was '" + + kind + "'."); + } + } else if ("value".equals(fieldName)) { + value = reader.getDouble(); + valueFound = true; + } else { + reader.skipChildren(); + } + } + if (valueFound) { + return new SearchScoreThreshold(value); + } + throw new IllegalStateException("Missing required property: value"); + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorQuery.java index 17e5acba8ef5..054fb56fe4f8 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorQuery.java @@ -41,6 +41,20 @@ public class VectorQuery implements JsonSerializable { */ private Double oversampling; + /* + * Relative weight of the vector query when compared to other vector query and/or the text query within the same + * search request. This value is used when combining the results of multiple ranking lists produced by the + * different vector queries and/or the results retrieved through the text query. The higher the weight, the higher + * the documents that matched that query will be in the final ranking. Default is 1.0 and the value needs to be a + * positive number larger than zero. + */ + private Float weight; + + /* + * The threshold used for vector queries. Note this can only be set if all 'fields' use the same similarity metric. + */ + private VectorThreshold threshold; + /** * Creates an instance of VectorQuery class. */ @@ -135,6 +149,56 @@ public VectorQuery setOversampling(Double oversampling) { return this; } + /** + * Get the weight property: Relative weight of the vector query when compared to other vector query and/or the text + * query within the same search request. This value is used when combining the results of multiple ranking lists + * produced by the different vector queries and/or the results retrieved through the text query. The higher the + * weight, the higher the documents that matched that query will be in the final ranking. Default is 1.0 and the + * value needs to be a positive number larger than zero. + * + * @return the weight value. + */ + public Float getWeight() { + return this.weight; + } + + /** + * Set the weight property: Relative weight of the vector query when compared to other vector query and/or the text + * query within the same search request. This value is used when combining the results of multiple ranking lists + * produced by the different vector queries and/or the results retrieved through the text query. The higher the + * weight, the higher the documents that matched that query will be in the final ranking. Default is 1.0 and the + * value needs to be a positive number larger than zero. + * + * @param weight the weight value to set. + * @return the VectorQuery object itself. + */ + public VectorQuery setWeight(Float weight) { + this.weight = weight; + return this; + } + + /** + * Get the threshold property: The threshold used for vector queries. Note this can only be set if all 'fields' use + * the same similarity metric. + * + * @return the threshold value. + */ + public VectorThreshold getThreshold() { + return this.threshold; + } + + /** + * Set the threshold property: The threshold used for vector queries. Note this can only be set if all 'fields' use + * the same similarity metric. + * + * @param threshold the threshold value to set. + * @return the VectorQuery object itself. + */ + public VectorQuery setThreshold(VectorThreshold threshold) { + this.threshold = threshold; + return this; + } + @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); @@ -142,6 +206,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("fields", this.fields); jsonWriter.writeBooleanField("exhaustive", this.exhaustive); jsonWriter.writeNumberField("oversampling", this.oversampling); + jsonWriter.writeNumberField("weight", this.weight); + jsonWriter.writeJsonField("threshold", this.threshold); return jsonWriter.writeEndObject(); } @@ -173,6 +239,10 @@ public static VectorQuery fromJson(JsonReader jsonReader) throws IOException { // Use the discriminator value to determine which subtype should be deserialized. if ("text".equals(discriminatorValue)) { return VectorizableTextQuery.fromJson(readerToUse.reset()); + } else if ("imageUrl".equals(discriminatorValue)) { + return VectorizableImageUrlQuery.fromJson(readerToUse.reset()); + } else if ("imageBinary".equals(discriminatorValue)) { + return VectorizableImageBinaryQuery.fromJson(readerToUse.reset()); } else if ("vector".equals(discriminatorValue)) { return VectorizedQuery.fromJson(readerToUse.reset()); } else { @@ -195,6 +265,10 @@ static VectorQuery fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOEx deserializedVectorQuery.exhaustive = reader.getNullable(JsonReader::getBoolean); } else if ("oversampling".equals(fieldName)) { deserializedVectorQuery.oversampling = reader.getNullable(JsonReader::getDouble); + } else if ("weight".equals(fieldName)) { + deserializedVectorQuery.weight = reader.getNullable(JsonReader::getFloat); + } else if ("threshold".equals(fieldName)) { + deserializedVectorQuery.threshold = VectorThreshold.fromJson(reader); } else { reader.skipChildren(); } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorSimilarityThreshold.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorSimilarityThreshold.java new file mode 100644 index 000000000000..87d77c75b63d --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorSimilarityThreshold.java @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The results of the vector query will be filtered based on the vector similarity metric. Note this is the canonical + * definition of similarity metric, not the 'distance' version. The threshold direction (larger or smaller) will be + * chosen automatically according to the metric used by the field. + */ +@Immutable +public final class VectorSimilarityThreshold extends VectorThreshold { + /* + * The threshold will filter based on the similarity metric value. Note this is the canonical definition of + * similarity metric, not the 'distance' version. The threshold direction (larger or smaller) will be chosen + * automatically according to the metric used by the field. + */ + private final double value; + + /** + * Creates an instance of VectorSimilarityThreshold class. + * + * @param value the value value to set. + */ + public VectorSimilarityThreshold(double value) { + this.value = value; + } + + /** + * Get the value property: The threshold will filter based on the similarity metric value. Note this is the + * canonical definition of similarity metric, not the 'distance' version. The threshold direction (larger or + * smaller) will be chosen automatically according to the metric used by the field. + * + * @return the value value. + */ + public double getValue() { + return this.value; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", + VectorThresholdKind.VECTOR_SIMILARITY == null ? null : VectorThresholdKind.VECTOR_SIMILARITY.toString()); + jsonWriter.writeDoubleField("value", this.value); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorSimilarityThreshold from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorSimilarityThreshold if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties or the + * polymorphic discriminator. + * @throws IOException If an error occurs while reading the VectorSimilarityThreshold. + */ + public static VectorSimilarityThreshold fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + boolean valueFound = false; + double value = 0.0; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + String kind = reader.getString(); + if (!"vectorSimilarity".equals(kind)) { + throw new IllegalStateException( + "'kind' was expected to be non-null and equal to 'vectorSimilarity'. The found 'kind' was '" + + kind + "'."); + } + } else if ("value".equals(fieldName)) { + value = reader.getDouble(); + valueFound = true; + } else { + reader.skipChildren(); + } + } + if (valueFound) { + return new VectorSimilarityThreshold(value); + } + throw new IllegalStateException("Missing required property: value"); + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThreshold.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThreshold.java new file mode 100644 index 000000000000..275649bc4324 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThreshold.java @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The threshold used for vector queries. + */ +@Immutable +public class VectorThreshold implements JsonSerializable { + /** + * Creates an instance of VectorThreshold class. + */ + public VectorThreshold() { + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorThreshold from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorThreshold if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing the polymorphic discriminator. + * @throws IOException If an error occurs while reading the VectorThreshold. + */ + public static VectorThreshold fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String discriminatorValue = null; + JsonReader readerToUse = reader.bufferObject(); + + readerToUse.nextToken(); // Prepare for reading + while (readerToUse.nextToken() != JsonToken.END_OBJECT) { + String fieldName = readerToUse.getFieldName(); + readerToUse.nextToken(); + if ("kind".equals(fieldName)) { + discriminatorValue = readerToUse.getString(); + break; + } else { + readerToUse.skipChildren(); + } + } + // Use the discriminator value to determine which subtype should be deserialized. + if ("vectorSimilarity".equals(discriminatorValue)) { + return VectorSimilarityThreshold.fromJson(readerToUse.reset()); + } else if ("searchScore".equals(discriminatorValue)) { + return SearchScoreThreshold.fromJson(readerToUse.reset()); + } else { + return fromJsonKnownDiscriminator(readerToUse.reset()); + } + }); + } + + static VectorThreshold fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorThreshold deserializedVectorThreshold = new VectorThreshold(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + reader.skipChildren(); + } + + return deserializedVectorThreshold; + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThresholdKind.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThresholdKind.java new file mode 100644 index 000000000000..7e33bb0a8ea3 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorThresholdKind.java @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The kind of vector query being performed. + */ +public final class VectorThresholdKind extends ExpandableStringEnum { + /** + * The results of the vector query will be filtered based on the vector similarity metric. Note this is the + * canonical definition of similarity metric, not the 'distance' version. The threshold direction (larger or + * smaller) will be chosen automatically according to the metric used by the field. + */ + public static final VectorThresholdKind VECTOR_SIMILARITY = fromString("vectorSimilarity"); + + /** + * The results of the vector query will filter based on the '@search.score' value. Note this is the @search.score + * returned as part of the search response. The threshold direction will be chosen for higher @search.score. + */ + public static final VectorThresholdKind SEARCH_SCORE = fromString("searchScore"); + + /** + * Creates a new instance of VectorThresholdKind value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public VectorThresholdKind() { + } + + /** + * Creates or finds a VectorThresholdKind from its string representation. + * + * @param name a name to look for. + * @return the corresponding VectorThresholdKind. + */ + public static VectorThresholdKind fromString(String name) { + return fromString(name, VectorThresholdKind.class); + } + + /** + * Gets known VectorThresholdKind values. + * + * @return known VectorThresholdKind values. + */ + public static Collection values() { + return values(VectorThresholdKind.class); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java new file mode 100644 index 000000000000..ea01de6bbc03 --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java @@ -0,0 +1,170 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.search.documents.implementation.models.VectorQueryKind; +import java.io.IOException; + +/** + * The query parameters to use for vector search when a base 64 encoded binary of an image that needs to be vectorized + * is provided. + */ +@Fluent +public final class VectorizableImageBinaryQuery extends VectorQuery { + /* + * The base 64 encoded binary of an image to be vectorized to perform a vector search query. + */ + private String base64Image; + + /** + * Creates an instance of VectorizableImageBinaryQuery class. + */ + public VectorizableImageBinaryQuery() { + } + + /** + * Get the base64Image property: The base 64 encoded binary of an image to be vectorized to perform a vector search + * query. + * + * @return the base64Image value. + */ + public String getBase64Image() { + return this.base64Image; + } + + /** + * Set the base64Image property: The base 64 encoded binary of an image to be vectorized to perform a vector search + * query. + * + * @param base64Image the base64Image value to set. + * @return the VectorizableImageBinaryQuery object itself. + */ + public VectorizableImageBinaryQuery setBase64Image(String base64Image) { + this.base64Image = base64Image; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageBinaryQuery setKNearestNeighborsCount(Integer kNearestNeighborsCount) { + super.setKNearestNeighborsCount(kNearestNeighborsCount); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageBinaryQuery setFields(String fields) { + super.setFields(fields); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageBinaryQuery setExhaustive(Boolean exhaustive) { + super.setExhaustive(exhaustive); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageBinaryQuery setOversampling(Double oversampling) { + super.setOversampling(oversampling); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageBinaryQuery setWeight(Float weight) { + super.setWeight(weight); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageBinaryQuery setThreshold(VectorThreshold threshold) { + super.setThreshold(threshold); + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", + VectorQueryKind.IMAGE_BINARY == null ? null : VectorQueryKind.IMAGE_BINARY.toString()); + jsonWriter.writeNumberField("k", getKNearestNeighborsCount()); + jsonWriter.writeStringField("fields", getFields()); + jsonWriter.writeBooleanField("exhaustive", isExhaustive()); + jsonWriter.writeNumberField("oversampling", getOversampling()); + jsonWriter.writeNumberField("weight", getWeight()); + jsonWriter.writeJsonField("threshold", getThreshold()); + jsonWriter.writeStringField("base64Image", this.base64Image); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorizableImageBinaryQuery from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorizableImageBinaryQuery if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing the polymorphic discriminator. + * @throws IOException If an error occurs while reading the VectorizableImageBinaryQuery. + */ + public static VectorizableImageBinaryQuery fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorizableImageBinaryQuery deserializedVectorizableImageBinaryQuery = new VectorizableImageBinaryQuery(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + String kind = reader.getString(); + if (!"imageBinary".equals(kind)) { + throw new IllegalStateException( + "'kind' was expected to be non-null and equal to 'imageBinary'. The found 'kind' was '" + + kind + "'."); + } + } else if ("k".equals(fieldName)) { + deserializedVectorizableImageBinaryQuery + .setKNearestNeighborsCount(reader.getNullable(JsonReader::getInt)); + } else if ("fields".equals(fieldName)) { + deserializedVectorizableImageBinaryQuery.setFields(reader.getString()); + } else if ("exhaustive".equals(fieldName)) { + deserializedVectorizableImageBinaryQuery.setExhaustive(reader.getNullable(JsonReader::getBoolean)); + } else if ("oversampling".equals(fieldName)) { + deserializedVectorizableImageBinaryQuery.setOversampling(reader.getNullable(JsonReader::getDouble)); + } else if ("weight".equals(fieldName)) { + deserializedVectorizableImageBinaryQuery.setWeight(reader.getNullable(JsonReader::getFloat)); + } else if ("threshold".equals(fieldName)) { + deserializedVectorizableImageBinaryQuery.setThreshold(VectorThreshold.fromJson(reader)); + } else if ("base64Image".equals(fieldName)) { + deserializedVectorizableImageBinaryQuery.base64Image = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedVectorizableImageBinaryQuery; + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java new file mode 100644 index 000000000000..f5f7533fa52a --- /dev/null +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java @@ -0,0 +1,168 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package com.azure.search.documents.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import com.azure.search.documents.implementation.models.VectorQueryKind; +import java.io.IOException; + +/** + * The query parameters to use for vector search when an url that represents an image value that needs to be vectorized + * is provided. + */ +@Fluent +public final class VectorizableImageUrlQuery extends VectorQuery { + /* + * The URL of an image to be vectorized to perform a vector search query. + */ + private String url; + + /** + * Creates an instance of VectorizableImageUrlQuery class. + */ + public VectorizableImageUrlQuery() { + } + + /** + * Get the url property: The URL of an image to be vectorized to perform a vector search query. + * + * @return the url value. + */ + public String getUrl() { + return this.url; + } + + /** + * Set the url property: The URL of an image to be vectorized to perform a vector search query. + * + * @param url the url value to set. + * @return the VectorizableImageUrlQuery object itself. + */ + public VectorizableImageUrlQuery setUrl(String url) { + this.url = url; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageUrlQuery setKNearestNeighborsCount(Integer kNearestNeighborsCount) { + super.setKNearestNeighborsCount(kNearestNeighborsCount); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageUrlQuery setFields(String fields) { + super.setFields(fields); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageUrlQuery setExhaustive(Boolean exhaustive) { + super.setExhaustive(exhaustive); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageUrlQuery setOversampling(Double oversampling) { + super.setOversampling(oversampling); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageUrlQuery setWeight(Float weight) { + super.setWeight(weight); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableImageUrlQuery setThreshold(VectorThreshold threshold) { + super.setThreshold(threshold); + return this; + } + + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", + VectorQueryKind.IMAGE_URL == null ? null : VectorQueryKind.IMAGE_URL.toString()); + jsonWriter.writeNumberField("k", getKNearestNeighborsCount()); + jsonWriter.writeStringField("fields", getFields()); + jsonWriter.writeBooleanField("exhaustive", isExhaustive()); + jsonWriter.writeNumberField("oversampling", getOversampling()); + jsonWriter.writeNumberField("weight", getWeight()); + jsonWriter.writeJsonField("threshold", getThreshold()); + jsonWriter.writeStringField("url", this.url); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorizableImageUrlQuery from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorizableImageUrlQuery if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing the polymorphic discriminator. + * @throws IOException If an error occurs while reading the VectorizableImageUrlQuery. + */ + public static VectorizableImageUrlQuery fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorizableImageUrlQuery deserializedVectorizableImageUrlQuery = new VectorizableImageUrlQuery(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + String kind = reader.getString(); + if (!"imageUrl".equals(kind)) { + throw new IllegalStateException( + "'kind' was expected to be non-null and equal to 'imageUrl'. The found 'kind' was '" + kind + + "'."); + } + } else if ("k".equals(fieldName)) { + deserializedVectorizableImageUrlQuery + .setKNearestNeighborsCount(reader.getNullable(JsonReader::getInt)); + } else if ("fields".equals(fieldName)) { + deserializedVectorizableImageUrlQuery.setFields(reader.getString()); + } else if ("exhaustive".equals(fieldName)) { + deserializedVectorizableImageUrlQuery.setExhaustive(reader.getNullable(JsonReader::getBoolean)); + } else if ("oversampling".equals(fieldName)) { + deserializedVectorizableImageUrlQuery.setOversampling(reader.getNullable(JsonReader::getDouble)); + } else if ("weight".equals(fieldName)) { + deserializedVectorizableImageUrlQuery.setWeight(reader.getNullable(JsonReader::getFloat)); + } else if ("threshold".equals(fieldName)) { + deserializedVectorizableImageUrlQuery.setThreshold(VectorThreshold.fromJson(reader)); + } else if ("url".equals(fieldName)) { + deserializedVectorizableImageUrlQuery.url = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedVectorizableImageUrlQuery; + }); + } +} diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableTextQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableTextQuery.java index b9be6cf439a8..36650886eab8 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableTextQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableTextQuery.java @@ -77,6 +77,24 @@ public VectorizableTextQuery setOversampling(Double oversampling) { return this; } + /** + * {@inheritDoc} + */ + @Override + public VectorizableTextQuery setWeight(Float weight) { + super.setWeight(weight); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizableTextQuery setThreshold(VectorThreshold threshold) { + super.setThreshold(threshold); + return this; + } + @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); @@ -85,6 +103,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("fields", getFields()); jsonWriter.writeBooleanField("exhaustive", isExhaustive()); jsonWriter.writeNumberField("oversampling", getOversampling()); + jsonWriter.writeNumberField("weight", getWeight()); + jsonWriter.writeJsonField("threshold", getThreshold()); jsonWriter.writeStringField("text", this.text); return jsonWriter.writeEndObject(); } @@ -105,6 +125,8 @@ public static VectorizableTextQuery fromJson(JsonReader jsonReader) throws IOExc String fields = null; Boolean exhaustive = null; Double oversampling = null; + Float weight = null; + VectorThreshold threshold = null; boolean textFound = false; String text = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -125,6 +147,10 @@ public static VectorizableTextQuery fromJson(JsonReader jsonReader) throws IOExc exhaustive = reader.getNullable(JsonReader::getBoolean); } else if ("oversampling".equals(fieldName)) { oversampling = reader.getNullable(JsonReader::getDouble); + } else if ("weight".equals(fieldName)) { + weight = reader.getNullable(JsonReader::getFloat); + } else if ("threshold".equals(fieldName)) { + threshold = VectorThreshold.fromJson(reader); } else if ("text".equals(fieldName)) { text = reader.getString(); textFound = true; @@ -138,6 +164,8 @@ public static VectorizableTextQuery fromJson(JsonReader jsonReader) throws IOExc deserializedVectorizableTextQuery.setFields(fields); deserializedVectorizableTextQuery.setExhaustive(exhaustive); deserializedVectorizableTextQuery.setOversampling(oversampling); + deserializedVectorizableTextQuery.setWeight(weight); + deserializedVectorizableTextQuery.setThreshold(threshold); return deserializedVectorizableTextQuery; } throw new IllegalStateException("Missing required property: text"); diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizedQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizedQuery.java index b523b504ccd8..9bb6b9a90677 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizedQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizedQuery.java @@ -78,6 +78,24 @@ public VectorizedQuery setOversampling(Double oversampling) { return this; } + /** + * {@inheritDoc} + */ + @Override + public VectorizedQuery setWeight(Float weight) { + super.setWeight(weight); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VectorizedQuery setThreshold(VectorThreshold threshold) { + super.setThreshold(threshold); + return this; + } + @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); @@ -86,6 +104,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("fields", getFields()); jsonWriter.writeBooleanField("exhaustive", isExhaustive()); jsonWriter.writeNumberField("oversampling", getOversampling()); + jsonWriter.writeNumberField("weight", getWeight()); + jsonWriter.writeJsonField("threshold", getThreshold()); jsonWriter.writeArrayField("vector", this.vector, (writer, element) -> writer.writeFloat(element)); return jsonWriter.writeEndObject(); } @@ -106,6 +126,8 @@ public static VectorizedQuery fromJson(JsonReader jsonReader) throws IOException String fields = null; Boolean exhaustive = null; Double oversampling = null; + Float weight = null; + VectorThreshold threshold = null; boolean vectorFound = false; List vector = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -126,6 +148,10 @@ public static VectorizedQuery fromJson(JsonReader jsonReader) throws IOException exhaustive = reader.getNullable(JsonReader::getBoolean); } else if ("oversampling".equals(fieldName)) { oversampling = reader.getNullable(JsonReader::getDouble); + } else if ("weight".equals(fieldName)) { + weight = reader.getNullable(JsonReader::getFloat); + } else if ("threshold".equals(fieldName)) { + threshold = VectorThreshold.fromJson(reader); } else if ("vector".equals(fieldName)) { vector = reader.readArray(reader1 -> reader1.getFloat()); vectorFound = true; @@ -139,6 +165,8 @@ public static VectorizedQuery fromJson(JsonReader jsonReader) throws IOException deserializedVectorizedQuery.setFields(fields); deserializedVectorizedQuery.setExhaustive(exhaustive); deserializedVectorizedQuery.setOversampling(oversampling); + deserializedVectorizedQuery.setWeight(weight); + deserializedVectorizedQuery.setThreshold(threshold); return deserializedVectorizedQuery; } throw new IllegalStateException("Missing required property: vector"); diff --git a/sdk/search/azure-search-documents/swagger/README.md b/sdk/search/azure-search-documents/swagger/README.md index faac14825de7..ba89d7aaf2e5 100644 --- a/sdk/search/azure-search-documents/swagger/README.md +++ b/sdk/search/azure-search-documents/swagger/README.md @@ -87,7 +87,7 @@ These settings apply only when `--tag=searchindex` is specified on the command l ``` yaml $(tag) == 'searchindex' namespace: com.azure.search.documents input-file: -- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/a0151afd7cd14913fc86cb793bde49c71122eb1e/specification/search/data-plane/Azure.Search/preview/2024-03-01-Preview/searchindex.json +- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/5a1fe448805429403c38a2637ee32c82ba755530/specification/search/data-plane/Azure.Search/preview/2024-05-01-preview/searchindex.json models-subpackage: models custom-types-subpackage: implementation.models custom-types: AutocompleteRequest,IndexAction,IndexBatch,RequestOptions,SearchDocumentsResult,SearchErrorException,SearchOptions,SearchRequest,SearchResult,SuggestDocumentsResult,SuggestRequest,SuggestResult,VectorQueryKind,ErrorAdditionalInfo,ErrorDetail,ErrorResponse,ErrorResponseException,ScalarQuantizationParameters,ScalarQuantizationCompressionConfiguration @@ -105,7 +105,7 @@ These settings apply only when `--tag=searchservice` is specified on the command ``` yaml $(tag) == 'searchservice' namespace: com.azure.search.documents.indexes input-file: -- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/a0151afd7cd14913fc86cb793bde49c71122eb1e/specification/search/data-plane/Azure.Search/preview/2024-03-01-Preview/searchservice.json +- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/5a1fe448805429403c38a2637ee32c82ba755530/specification/search/data-plane/Azure.Search/preview/2024-05-01-preview/searchservice.json models-subpackage: models custom-types-subpackage: implementation.models custom-types: AnalyzeRequest,AnalyzeResult,AzureActiveDirectoryApplicationCredentials,DataSourceCredentials,DocumentKeysOrIds,EdgeNGramTokenFilterV1,EdgeNGramTokenFilterV2,EntityRecognitionSkillV1,EntityRecognitionSkillV3,KeywordTokenizerV1,KeywordTokenizerV2,ListAliasesResult,ListDataSourcesResult,ListIndexersResult,ListIndexesResult,ListSkillsetsResult,ListSynonymMapsResult,LuceneStandardTokenizerV1,LuceneStandardTokenizerV2,NGramTokenFilterV1,NGramTokenFilterV2,RequestOptions,SearchErrorException,SentimentSkillV1,SentimentSkillV3,SkillNames,VectorSearchAlgorithmKind,ErrorAdditionalInfo,ErrorDetail,ErrorResponse,ErrorResponseException,ScalarQuantizationParameters,ScalarQuantizationCompressionConfiguration diff --git a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java index 0e98334d4871..45b7855293ec 100644 --- a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java +++ b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java @@ -243,6 +243,10 @@ private void customizeSearchError(ClassCustomization classCustomization) { }); } + private void customizeVectorizableImageUrlQuery(ClassCustomization classCustomization) { + classCustomization.getMethod("setFields").removeAnnotation("Override"); + } + private static void customizeAst(ClassCustomization classCustomization, Consumer consumer) { classCustomization.customizeAst(ast -> consumer.accept(ast.getClassByName(classCustomization.getClassName()) .orElseThrow(() -> new RuntimeException("Class not found. " + classCustomization.getClassName())))); diff --git a/sdk/search/azure-search-documents/swagger/src/main/java/SearchServiceCustomizations.java b/sdk/search/azure-search-documents/swagger/src/main/java/SearchServiceCustomizations.java index e2cbe06d9f04..dcd3d4d8c285 100644 --- a/sdk/search/azure-search-documents/swagger/src/main/java/SearchServiceCustomizations.java +++ b/sdk/search/azure-search-documents/swagger/src/main/java/SearchServiceCustomizations.java @@ -364,49 +364,62 @@ private void customizeSynonymMap(ClassCustomization classCustomization) { private void customizeSearchResourceEncryptionKey(ClassCustomization keyCustomization, ClassCustomization credentialCustomization) { keyCustomization.removeMethod("getAccessCredentials"); - - String setterReturnJavadoc = keyCustomization.getMethod("setAccessCredentials").getJavadoc().getReturn(); - keyCustomization.removeMethod("setAccessCredentials"); - - keyCustomization.addMethod(joinWithNewline( - "public String getApplicationId() {", - " return (this.accessCredentials == null) ? null : this.accessCredentials.getApplicationId();", - "}")) - .getJavadoc() - .replace(credentialCustomization.getMethod("getApplicationId").getJavadoc()); - - keyCustomization.addMethod(joinWithNewline( - "public SearchResourceEncryptionKey setApplicationId(String applicationId) {", - " if (this.accessCredentials == null) {", - " this.accessCredentials = new AzureActiveDirectoryApplicationCredentials();", - " }", - "", - " this.accessCredentials.setApplicationId(applicationId);", - " return this;", - "}")) - .getJavadoc() - .replace(credentialCustomization.getMethod("setApplicationId").getJavadoc()) - .setReturn(setterReturnJavadoc); - - keyCustomization.addMethod(joinWithNewline( - "public String getApplicationSecret() {", - " return (this.accessCredentials == null) ? null : this.accessCredentials.getApplicationSecret();", - "}")) - .getJavadoc() - .replace(credentialCustomization.getMethod("getApplicationSecret").getJavadoc()); - - keyCustomization.addMethod(joinWithNewline( - "public SearchResourceEncryptionKey setApplicationSecret(String applicationSecret) {", - " if (this.accessCredentials == null) {", - " this.accessCredentials = new AzureActiveDirectoryApplicationCredentials();", - " }", - "", - " this.accessCredentials.setApplicationSecret(applicationSecret);", - " return this;", - "}")) - .getJavadoc() - .replace(credentialCustomization.getMethod("setApplicationSecret").getJavadoc()) - .setReturn(setterReturnJavadoc); + customizeAst(keyCustomization, clazz -> { + clazz.getMethodsByName("setAccessCredentials").get(0).remove(); + + clazz.addMethod("getApplicationId", Modifier.Keyword.PUBLIC) + .setType(String.class) + .setBody(StaticJavaParser.parseBlock("{\n" + + " return (this.accessCredentials == null) ? null : this.accessCredentials.getApplicationId();\n" + + " }")) + .setJavadocComment(StaticJavaParser.parseJavadoc("* Get the applicationId property: An AAD Application ID that was granted the required access permissions to the\n" + + " * Azure Key Vault that is to be used when encrypting your data at rest. The Application ID should not be confused\n" + + " * with the Object ID for your AAD Application.\n" + + " * \n" + + " * @return the applicationId value.")); + + clazz.addMethod("setApplicationId", Modifier.Keyword.PUBLIC) + .setType(keyCustomization.getClassName()) + .addParameter(String.class, "applicationId") + .setBody(StaticJavaParser.parseBlock("{\n" + + " if (this.accessCredentials == null) {\n" + + " this.accessCredentials = new AzureActiveDirectoryApplicationCredentials();\n" + + " }\n" + + " this.accessCredentials.setApplicationId(applicationId);\n" + + " return this;\n" + + " }")) + .setJavadocComment(StaticJavaParser.parseJavadoc("* Set the applicationId property: An AAD Application ID that was granted the required access permissions to the\n" + + " * Azure Key Vault that is to be used when encrypting your data at rest. The Application ID should not be confused\n" + + " * with the Object ID for your AAD Application.\n" + + " * \n" + + " * @param applicationId the applicationId value to set.\n" + + " * @return the SearchResourceEncryptionKey object itself.")); + + clazz.addMethod("getApplicationSecret", Modifier.Keyword.PUBLIC) + .setType(String.class) + .setBody(StaticJavaParser.parseBlock("{\n" + + " return (this.accessCredentials == null) ? null : this.accessCredentials.getApplicationSecret();\n" + + " }")) + .setJavadocComment(StaticJavaParser.parseJavadoc("* Get the applicationSecret property: The authentication key of the specified AAD application.\n" + + " * \n" + + " * @return the applicationSecret value.")); + + + clazz.addMethod("setApplicationSecret", Modifier.Keyword.PUBLIC) + .setType(keyCustomization.getClassName()) + .addParameter(String.class, "applicationSecret") + .setBody(StaticJavaParser.parseBlock("{\n" + + " if (this.accessCredentials == null) {\n" + + " this.accessCredentials = new AzureActiveDirectoryApplicationCredentials();\n" + + " }\n" + + " this.accessCredentials.setApplicationSecret(applicationSecret);\n" + + " return this;\n" + + " }")) + .setJavadocComment(StaticJavaParser.parseJavadoc("* Set the applicationSecret property: The authentication key of the specified AAD application.\n" + + " * \n" + + " * @param applicationSecret the applicationSecret value to set.\n" + + " * @return the SearchResourceEncryptionKey object itself.")); + }); } private void customizeSearchSuggester(ClassCustomization classCustomization) { From 783ffc747e479fb9bd0f4472b8867875be49f86f Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 23 Apr 2024 09:13:15 -0700 Subject: [PATCH 02/10] Removing ovveride statements from `setFields` for `VectorizableImageUrlQuery` and `VectorizableImageBinaryQuery` --- .../documents/models/VectorizableImageUrlQuery.java | 5 +---- .../swagger/src/main/java/SearchIndexCustomizations.java | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java index f5f7533fa52a..069440100197 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java @@ -3,7 +3,6 @@ // // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. - package com.azure.search.documents.models; import com.azure.core.annotation.Fluent; @@ -19,6 +18,7 @@ */ @Fluent public final class VectorizableImageUrlQuery extends VectorQuery { + /* * The URL of an image to be vectorized to perform a vector search query. */ @@ -62,7 +62,6 @@ public VectorizableImageUrlQuery setKNearestNeighborsCount(Integer kNearestNeigh /** * {@inheritDoc} */ - @Override public VectorizableImageUrlQuery setFields(String fields) { super.setFields(fields); return this; @@ -134,7 +133,6 @@ public static VectorizableImageUrlQuery fromJson(JsonReader jsonReader) throws I while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { String kind = reader.getString(); if (!"imageUrl".equals(kind)) { @@ -161,7 +159,6 @@ public static VectorizableImageUrlQuery fromJson(JsonReader jsonReader) throws I reader.skipChildren(); } } - return deserializedVectorizableImageUrlQuery; }); } diff --git a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java index 45b7855293ec..eb4e4cdbf501 100644 --- a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java +++ b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java @@ -79,6 +79,8 @@ private void customizeModelsPackage(PackageCustomization packageCustomization) { customizeVectorQuery(packageCustomization.getClass("VectorQuery")); customizeVectorizedQuery(packageCustomization.getClass("VectorizedQuery")); customizeVectorizableTextQuery(packageCustomization.getClass("VectorizableTextQuery")); + customizeVectorizableImageUrlQuery(packageCustomization.getClass("VectorizableImageUrlQuery")); + customizeVectorizableImageBinaryQuery(packageCustomization.getClass("VectorizableImageBinaryQuery")); packageCustomization.getClass("QueryAnswerResult").removeMethod("setAdditionalProperties"); packageCustomization.getClass("QueryCaptionResult").removeMethod("setAdditionalProperties"); @@ -244,7 +246,11 @@ private void customizeSearchError(ClassCustomization classCustomization) { } private void customizeVectorizableImageUrlQuery(ClassCustomization classCustomization) { - classCustomization.getMethod("setFields").removeAnnotation("Override"); + classCustomization.getMethod("setFields").removeAnnotation("@Override"); + } + + private void customizeVectorizableImageBinaryQuery(ClassCustomization classCustomization) { + classCustomization.getMethod("setFields").removeAnnotation("@Override"); } private static void customizeAst(ClassCustomization classCustomization, Consumer consumer) { From 0d355175d8f7bd56347160f4ee9d90712a7516ee Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 23 Apr 2024 09:13:22 -0700 Subject: [PATCH 03/10] Removing ovveride statements from `setFields` for `VectorizableImageUrlQuery` and `VectorizableImageBinaryQuery` --- .../models/VectorizableImageBinaryQuery.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java index ea01de6bbc03..e6c795dd1a7b 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java @@ -3,7 +3,6 @@ // // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. - package com.azure.search.documents.models; import com.azure.core.annotation.Fluent; @@ -19,6 +18,7 @@ */ @Fluent public final class VectorizableImageBinaryQuery extends VectorQuery { + /* * The base 64 encoded binary of an image to be vectorized to perform a vector search query. */ @@ -33,7 +33,7 @@ public VectorizableImageBinaryQuery() { /** * Get the base64Image property: The base 64 encoded binary of an image to be vectorized to perform a vector search * query. - * + * * @return the base64Image value. */ public String getBase64Image() { @@ -43,7 +43,7 @@ public String getBase64Image() { /** * Set the base64Image property: The base 64 encoded binary of an image to be vectorized to perform a vector search * query. - * + * * @param base64Image the base64Image value to set. * @return the VectorizableImageBinaryQuery object itself. */ @@ -64,7 +64,6 @@ public VectorizableImageBinaryQuery setKNearestNeighborsCount(Integer kNearestNe /** * {@inheritDoc} */ - @Override public VectorizableImageBinaryQuery setFields(String fields) { super.setFields(fields); return this; @@ -123,7 +122,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of VectorizableImageBinaryQuery from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of VectorizableImageBinaryQuery if the JsonReader was pointing to an instance of it, or null * if it was pointing to JSON null. @@ -136,7 +135,6 @@ public static VectorizableImageBinaryQuery fromJson(JsonReader jsonReader) throw while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { String kind = reader.getString(); if (!"imageBinary".equals(kind)) { @@ -163,7 +161,6 @@ public static VectorizableImageBinaryQuery fromJson(JsonReader jsonReader) throw reader.skipChildren(); } } - return deserializedVectorizableImageBinaryQuery; }); } From e39a08b06d03dd5854533169ebbb802c08d6110d Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 23 Apr 2024 09:20:17 -0700 Subject: [PATCH 04/10] adding varargs --- .../models/VectorizableImageBinaryQuery.java | 2 +- .../documents/models/VectorizableImageUrlQuery.java | 2 +- .../src/main/java/SearchIndexCustomizations.java | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java index e6c795dd1a7b..9130d08fa661 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java @@ -64,7 +64,7 @@ public VectorizableImageBinaryQuery setKNearestNeighborsCount(Integer kNearestNe /** * {@inheritDoc} */ - public VectorizableImageBinaryQuery setFields(String fields) { + public VectorizableImageBinaryQuery setFields(String... fields) { super.setFields(fields); return this; } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java index 069440100197..525749f52473 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java @@ -62,7 +62,7 @@ public VectorizableImageUrlQuery setKNearestNeighborsCount(Integer kNearestNeigh /** * {@inheritDoc} */ - public VectorizableImageUrlQuery setFields(String fields) { + public VectorizableImageUrlQuery setFields(String... fields) { super.setFields(fields); return this; } diff --git a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java index eb4e4cdbf501..07a156504557 100644 --- a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java +++ b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java @@ -247,10 +247,22 @@ private void customizeSearchError(ClassCustomization classCustomization) { private void customizeVectorizableImageUrlQuery(ClassCustomization classCustomization) { classCustomization.getMethod("setFields").removeAnnotation("@Override"); + customizeAst(classCustomization, clazz -> clazz.getMethodsByName("setFields").get(0) + .setParameters(new NodeList<>(new Parameter().setType("String").setName("fields").setVarArgs(true))) + .setBody(StaticJavaParser.parseBlock("{\n" + + " super.setFields(fields);\n" + + " return this;\n" + + " }"))); } private void customizeVectorizableImageBinaryQuery(ClassCustomization classCustomization) { classCustomization.getMethod("setFields").removeAnnotation("@Override"); + customizeAst(classCustomization, clazz -> clazz.getMethodsByName("setFields").get(0) + .setParameters(new NodeList<>(new Parameter().setType("String").setName("fields").setVarArgs(true))) + .setBody(StaticJavaParser.parseBlock("{\n" + + " super.setFields(fields);\n" + + " return this;\n" + + " }"))); } private static void customizeAst(ClassCustomization classCustomization, Consumer consumer) { From 81d24431aeaa00c0f921c1a0f98b27aa24525dcf Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 23 Apr 2024 09:57:19 -0700 Subject: [PATCH 05/10] Additional adjustments to FieldBuilder and Search Index Customizations --- .../search/documents/implementation/util/FieldBuilder.java | 7 ++++++- .../documents/models/VectorizableImageBinaryQuery.java | 1 + .../search/documents/models/VectorizableImageUrlQuery.java | 1 + .../swagger/src/main/java/SearchIndexCustomizations.java | 2 -- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java index badd2cf3b11e..47680fb5bf86 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java @@ -13,7 +13,12 @@ import com.azure.search.documents.indexes.FieldBuilderIgnore; import com.azure.search.documents.indexes.SearchableField; import com.azure.search.documents.indexes.SimpleField; -import com.azure.search.documents.indexes.models.*; +import com.azure.search.documents.indexes.models.FieldBuilderOptions; +import com.azure.search.documents.indexes.models.LexicalAnalyzerName; +import com.azure.search.documents.indexes.models.LexicalNormalizerName; +import com.azure.search.documents.indexes.models.SearchField; +import com.azure.search.documents.indexes.models.SearchFieldDataType; +import com.azure.search.documents.indexes.models.VectorEncodingFormat; import reactor.util.annotation.Nullable; import java.lang.annotation.Annotation; diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java index 9130d08fa661..812ea943f84f 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageBinaryQuery.java @@ -64,6 +64,7 @@ public VectorizableImageBinaryQuery setKNearestNeighborsCount(Integer kNearestNe /** * {@inheritDoc} */ + @Override public VectorizableImageBinaryQuery setFields(String... fields) { super.setFields(fields); return this; diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java index 525749f52473..a9616bcf3657 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/VectorizableImageUrlQuery.java @@ -62,6 +62,7 @@ public VectorizableImageUrlQuery setKNearestNeighborsCount(Integer kNearestNeigh /** * {@inheritDoc} */ + @Override public VectorizableImageUrlQuery setFields(String... fields) { super.setFields(fields); return this; diff --git a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java index 07a156504557..a4ed74a59ce9 100644 --- a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java +++ b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java @@ -246,7 +246,6 @@ private void customizeSearchError(ClassCustomization classCustomization) { } private void customizeVectorizableImageUrlQuery(ClassCustomization classCustomization) { - classCustomization.getMethod("setFields").removeAnnotation("@Override"); customizeAst(classCustomization, clazz -> clazz.getMethodsByName("setFields").get(0) .setParameters(new NodeList<>(new Parameter().setType("String").setName("fields").setVarArgs(true))) .setBody(StaticJavaParser.parseBlock("{\n" + @@ -256,7 +255,6 @@ private void customizeVectorizableImageUrlQuery(ClassCustomization classCustomiz } private void customizeVectorizableImageBinaryQuery(ClassCustomization classCustomization) { - classCustomization.getMethod("setFields").removeAnnotation("@Override"); customizeAst(classCustomization, clazz -> clazz.getMethodsByName("setFields").get(0) .setParameters(new NodeList<>(new Parameter().setType("String").setName("fields").setVarArgs(true))) .setBody(StaticJavaParser.parseBlock("{\n" + From 2d2eab74f4427dcdaee7102db56dfb346c018bf6 Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 23 Apr 2024 10:24:41 -0700 Subject: [PATCH 06/10] Updating cspell.json --- .vscode/cspell.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.vscode/cspell.json b/.vscode/cspell.json index f2962f64ee6f..f3e78840a07f 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -452,7 +452,11 @@ "mylocation", "myloc", "dari", - "hitel" + "hitel", + "AISERVICES", + "AICLIP", + "TLARGE", + "TBASE" ] }, { From f33e46a240ec504c29bf2cdd1985f64a5182542a Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 23 Apr 2024 10:46:08 -0700 Subject: [PATCH 07/10] Adjust `SearchScoreThreshold` customization Re-enable code generation in CI --- .../models/SearchScoreThreshold.java | 19 ++++++++++--------- ...DISABLED.ps1 => Update-Codegeneration.ps1} | 0 .../main/java/SearchIndexCustomizations.java | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) rename sdk/search/azure-search-documents/swagger/{Update-Codegeneration-DISABLED.ps1 => Update-Codegeneration.ps1} (100%) diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java index f28a31b12e95..03b1f991afe8 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/SearchScoreThreshold.java @@ -3,7 +3,6 @@ // // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. - package com.azure.search.documents.models; import com.azure.core.annotation.Immutable; @@ -18,6 +17,7 @@ */ @Immutable public final class SearchScoreThreshold extends VectorThreshold { + /* * The threshold will filter based on the '@search.score' value. Note this is the @search.score returned as part of * the search response. The threshold direction will be chosen for higher @search.score. @@ -26,7 +26,7 @@ public final class SearchScoreThreshold extends VectorThreshold { /** * Creates an instance of SearchScoreThreshold class. - * + * * @param value the value value to set. */ public SearchScoreThreshold(double value) { @@ -34,12 +34,14 @@ public SearchScoreThreshold(double value) { } /** + * /** * Get the value property: The threshold will filter based on the '@search.score' value. Note this is the - * - * @search.score returned as part of the search response. The threshold direction will be chosen for higher - * @search.score. - * - * @return the value value. + * + * `@search.score` returned as part of the search response. The threshold direction will be chosen for higher + * `@search.score`. + * + * @return the value. + * / */ public double getValue() { return this.value; @@ -56,7 +58,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of SearchScoreThreshold from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of SearchScoreThreshold if the JsonReader was pointing to an instance of it, or null if it * was pointing to JSON null. @@ -71,7 +73,6 @@ public static SearchScoreThreshold fromJson(JsonReader jsonReader) throws IOExce while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("kind".equals(fieldName)) { String kind = reader.getString(); if (!"searchScore".equals(kind)) { diff --git a/sdk/search/azure-search-documents/swagger/Update-Codegeneration-DISABLED.ps1 b/sdk/search/azure-search-documents/swagger/Update-Codegeneration.ps1 similarity index 100% rename from sdk/search/azure-search-documents/swagger/Update-Codegeneration-DISABLED.ps1 rename to sdk/search/azure-search-documents/swagger/Update-Codegeneration.ps1 diff --git a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java index a4ed74a59ce9..b612c668b797 100644 --- a/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java +++ b/sdk/search/azure-search-documents/swagger/src/main/java/SearchIndexCustomizations.java @@ -3,6 +3,7 @@ import com.azure.autorest.customization.ClassCustomization; import com.azure.autorest.customization.Customization; +import com.azure.autorest.customization.JavadocCustomization; import com.azure.autorest.customization.LibraryCustomization; import com.azure.autorest.customization.PackageCustomization; import com.github.javaparser.StaticJavaParser; @@ -81,6 +82,7 @@ private void customizeModelsPackage(PackageCustomization packageCustomization) { customizeVectorizableTextQuery(packageCustomization.getClass("VectorizableTextQuery")); customizeVectorizableImageUrlQuery(packageCustomization.getClass("VectorizableImageUrlQuery")); customizeVectorizableImageBinaryQuery(packageCustomization.getClass("VectorizableImageBinaryQuery")); + customizeSearchScoreThreshold(packageCustomization.getClass("SearchScoreThreshold")); packageCustomization.getClass("QueryAnswerResult").removeMethod("setAdditionalProperties"); packageCustomization.getClass("QueryCaptionResult").removeMethod("setAdditionalProperties"); @@ -263,6 +265,21 @@ private void customizeVectorizableImageBinaryQuery(ClassCustomization classCusto " }"))); } + private void customizeSearchScoreThreshold(ClassCustomization classCustomization) { + customizeAst(classCustomization, clazz -> { + clazz.getMethodsByName("getValue").get(0).setJavadocComment(StaticJavaParser.parseJavadoc(joinWithNewline( + "/**", + " * Get the value property: The threshold will filter based on the '@search.score' value. Note this is the", + " *", + " * `@search.score` returned as part of the search response. The threshold direction will be chosen for higher", + " * `@search.score`.", + " *", + " * @return the value.", + " */" + ))); + }); + } + private static void customizeAst(ClassCustomization classCustomization, Consumer consumer) { classCustomization.customizeAst(ast -> consumer.accept(ast.getClassByName(classCustomization.getClassName()) .orElseThrow(() -> new RuntimeException("Class not found. " + classCustomization.getClassName())))); From 4870e1c3c745b7ce81cfce70731e17fa1107a186 Mon Sep 17 00:00:00 2001 From: jairmyree Date: Tue, 30 Apr 2024 16:02:07 -0700 Subject: [PATCH 08/10] Updates: - Updated Cspell - Rename `maxStoragePerIndex` property to `maxStoragePerIndexInBytes` in SearchServiceLimits - Set `hybridSearch` property to be type `HybridSearch` in SearchRequest - Add `hybridSearch` to SearchOptions and `SearchAsyncClient.createSearchRequest()` --- .vscode/cspell.json | 3 ++- .../search/documents/SearchAsyncClient.java | 2 ++ .../implementation/models/SearchRequest.java | 11 ++++---- .../documents/indexes/SearchableField.java | 7 +++++- .../indexes/models/SearchServiceLimits.java | 24 +++++++++--------- .../documents/models/SearchOptions.java | 25 +++++++++++++++++++ .../SearchClientJavaDocSnippets.java | 16 ++++++------ .../azure-search-documents/swagger/README.md | 24 ++++++++++++++++++ 8 files changed, 85 insertions(+), 27 deletions(-) diff --git a/.vscode/cspell.json b/.vscode/cspell.json index f3e78840a07f..e699bca6bbba 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -456,7 +456,8 @@ "AISERVICES", "AICLIP", "TLARGE", - "TBASE" + "TBASE", + "TGIANT" ] }, { diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java index d644e3ab9d01..5c6afb4e9221 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java @@ -1339,6 +1339,8 @@ static SearchRequest createSearchRequest(String searchText, SearchOptions option .setVectorQueries(vectorSearchOptions.getQueries()); } + request.setHybridSearch(options.getHybridSearch()); + return request; } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java index 9693f4669688..a6a0bcc804ed 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/models/SearchRequest.java @@ -11,6 +11,7 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; +import com.azure.search.documents.models.HybridSearch; import com.azure.search.documents.models.QueryDebugMode; import com.azure.search.documents.models.QueryLanguage; import com.azure.search.documents.models.QuerySpellerType; @@ -226,7 +227,7 @@ public final class SearchRequest implements JsonSerializable { /* * The query parameters to configure hybrid search behaviors. */ - private Object hybridSearch; + private HybridSearch hybridSearch; /** * Creates an instance of SearchRequest class. @@ -955,7 +956,7 @@ public SearchRequest setVectorFilterMode(VectorFilterMode vectorFilterMode) { * * @return the hybridSearch value. */ - public Object getHybridSearch() { + public HybridSearch getHybridSearch() { return this.hybridSearch; } @@ -965,7 +966,7 @@ public Object getHybridSearch() { * @param hybridSearch the hybridSearch value to set. * @return the SearchRequest object itself. */ - public SearchRequest setHybridSearch(Object hybridSearch) { + public SearchRequest setHybridSearch(HybridSearch hybridSearch) { this.hybridSearch = hybridSearch; return this; } @@ -1008,7 +1009,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeArrayField("vectorQueries", this.vectorQueries, (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("vectorFilterMode", this.vectorFilterMode == null ? null : this.vectorFilterMode.toString()); - jsonWriter.writeUntypedField("hybridSearch", this.hybridSearch); + jsonWriter.writeJsonField("hybridSearch", this.hybridSearch); return jsonWriter.writeEndObject(); } @@ -1093,7 +1094,7 @@ public static SearchRequest fromJson(JsonReader jsonReader) throws IOException { } else if ("vectorFilterMode".equals(fieldName)) { deserializedSearchRequest.vectorFilterMode = VectorFilterMode.fromString(reader.getString()); } else if ("hybridSearch".equals(fieldName)) { - deserializedSearchRequest.hybridSearch = reader.readUntyped(); + deserializedSearchRequest.hybridSearch = HybridSearch.fromJson(reader); } else { reader.skipChildren(); } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java index 8e05d6082c0b..0895ee565934 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchableField.java @@ -3,7 +3,12 @@ package com.azure.search.documents.indexes; -import com.azure.search.documents.indexes.models.*; +import com.azure.search.documents.indexes.models.FieldBuilderOptions; +import com.azure.search.documents.indexes.models.LexicalAnalyzerName; +import com.azure.search.documents.indexes.models.LexicalNormalizerName; +import com.azure.search.documents.indexes.models.SearchField; +import com.azure.search.documents.indexes.models.SynonymMap; +import com.azure.search.documents.indexes.models.VectorEncodingFormat; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java index 393443a67c80..1a7bd1686be1 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/SearchServiceLimits.java @@ -42,7 +42,7 @@ public final class SearchServiceLimits implements JsonSerializable hotels = new ArrayList<>(); hotels.add(new Hotel().setHotelId("100")); @@ -50,7 +50,7 @@ public static void uploadDocument() { * Merge a document in a SearchClient index. */ public static void mergeDocument() { - searchClient = createSearchClientWithSearcClientBuilder(); + searchClient = createSearchClientWithSearchClientBuilder(); // BEGIN: com.azure.search.documents.SearchClient-classLevelJavaDoc.mergeDocument#Map List hotels = new ArrayList<>(); hotels.add(new Hotel().setHotelId("100")); @@ -63,7 +63,7 @@ public static void mergeDocument() { * Delete a document in a SearchClient index. */ public static void deleteDocument() { - searchClient = createSearchClientWithSearcClientBuilder(); + searchClient = createSearchClientWithSearchClientBuilder(); // BEGIN: com.azure.search.documents.SearchClient-classLevelJavaDoc.deleteDocument#String SearchDocument documentId = new SearchDocument(); documentId.put("hotelId", "100"); @@ -75,7 +75,7 @@ public static void deleteDocument() { * Retrieve a document from a SearchClient index. */ public static void getDocument() { - searchClient = createSearchClientWithSearcClientBuilder(); + searchClient = createSearchClientWithSearchClientBuilder(); // BEGIN: com.azure.search.documents.SearchClient-classLevelJavaDoc.getDocument#String-Class Hotel hotel = searchClient.getDocument("100", Hotel.class); System.out.printf("Retrieved Hotel %s%n", hotel.getHotelId()); @@ -86,7 +86,7 @@ public static void getDocument() { * Search documents in a SearchClient index. */ public static void searchDocuments() { - searchClient = createSearchClientWithSearcClientBuilder(); + searchClient = createSearchClientWithSearchClientBuilder(); // BEGIN: com.azure.search.documents.SearchClient-classLevelJavaDoc.searchDocuments#String SearchDocument searchDocument = new SearchDocument(); searchDocument.put("hotelId", "8"); @@ -112,7 +112,7 @@ public static void searchDocuments() { * Make a suggestion query to a SearchClient index. */ public static void suggestDocuments() { - searchClient = createSearchClientWithSearcClientBuilder(); + searchClient = createSearchClientWithSearchClientBuilder(); // BEGIN: com.azure.search.documents.SearchClient-classLevelJavaDoc.suggestDocuments#String-String SuggestPagedIterable suggestPagedIterable = searchClient.suggest("searchText", "sg"); for (SuggestResult result: suggestPagedIterable) { @@ -125,7 +125,7 @@ public static void suggestDocuments() { * Autocomplete a query in a SearchClient index. */ public static void autocompleteDocuments() { - searchClient = createSearchClientWithSearcClientBuilder(); + searchClient = createSearchClientWithSearchClientBuilder(); // BEGIN: com.azure.search.documents.SearchClient-classLevelJavaDoc.autocomplete#String-String AutocompletePagedIterable autocompletePagedIterable = searchClient.autocomplete("searchText", "sg"); for (AutocompleteItem result: autocompletePagedIterable) { diff --git a/sdk/search/azure-search-documents/swagger/README.md b/sdk/search/azure-search-documents/swagger/README.md index ba89d7aaf2e5..9be65913d502 100644 --- a/sdk/search/azure-search-documents/swagger/README.md +++ b/sdk/search/azure-search-documents/swagger/README.md @@ -216,6 +216,30 @@ directive: return $; ``` +### Rename `maxStoragePerIndex` property to `maxStoragePerIndexInBytes` in ServiceLimits + +``` yaml $(tag) == 'searchservice' +directive: + - from: swagger-document + where: $.definitions.ServiceLimits.properties + transform: > + $.maxStoragePerIndexInBytes = $.maxStoragePerIndex; + delete $.maxStoragePerIndex; +``` + +### Set `hybridSearch` property to be type `HybridSearch` in SearchRequest + +``` yaml $(tag) == 'searchindex' +directive: + - from: swagger-document + where: $.definitions.SearchRequest.properties + transform: > + delete $.hybridSearch["type"]; + delete $.hybridSearch.items; + $.hybridSearch["$ref"] = "#/definitions/HybridSearch"; + +``` + ### Remove required from properties that are optional ``` yaml $(tag) == 'searchservice' From 72e059b21bc9c98518693b2426338550c03594a1 Mon Sep 17 00:00:00 2001 From: jairmyree Date: Fri, 3 May 2024 12:27:10 -0700 Subject: [PATCH 09/10] Adding Support and testing byte[] and List within field builder --- .../implementation/util/FieldBuilder.java | 2 ++ .../documents/indexes/FieldBuilderTests.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java index 47680fb5bf86..27b62030f428 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/implementation/util/FieldBuilder.java @@ -54,6 +54,7 @@ public final class FieldBuilder { private static final int MAX_DEPTH = 10000; private static final Map SUPPORTED_NONE_PARAMETERIZED_TYPE = new HashMap<>(); private static final Set UNSUPPORTED_TYPES = new HashSet<>(); + private static final Set UNSUPPORTED_SERVICE_TYPES = new HashSet<>(); private static final SearchFieldDataType COLLECTION_STRING = SearchFieldDataType.collection(SearchFieldDataType.STRING); @@ -83,6 +84,7 @@ public final class FieldBuilder { SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Byte.class, SearchFieldDataType.SBYTE); SUPPORTED_NONE_PARAMETERIZED_TYPE.put(short.class, SearchFieldDataType.INT16); SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Short.class, SearchFieldDataType.INT16); + UNSUPPORTED_SERVICE_TYPES.add(SearchFieldDataType.BYTE); } /** diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java index 7aad823cce5f..cabf836354f7 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java @@ -25,6 +25,7 @@ import java.time.OffsetDateTime; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -126,7 +127,7 @@ public void ignoredPropertyName() { public void supportedFields() { List fields = SearchIndexClient.buildSearchFields(AllSupportedFields.class, null); - assertEquals(23, fields.size()); + assertEquals(25, fields.size()); Map fieldToDataType = fields.stream() .collect(Collectors.toMap(SearchField::getName, SearchField::getType)); @@ -154,6 +155,9 @@ public void supportedFields() { assertEquals(SearchFieldDataType.INT16, fieldToDataType.get("primitiveShort")); assertEquals(SearchFieldDataType.SBYTE, fieldToDataType.get("nullableByte")); assertEquals(SearchFieldDataType.SBYTE, fieldToDataType.get("primitiveByte")); + assertEquals(SearchFieldDataType.collection(SearchFieldDataType.SBYTE), fieldToDataType.get("byteArray")); + assertEquals(SearchFieldDataType.collection(SearchFieldDataType.SBYTE), fieldToDataType.get("byteList")); + } @SuppressWarnings({"unused", "UseOfObsoleteDateTimeApi"}) @@ -296,6 +300,18 @@ public byte getPrimitiveByte() { public Byte getNullableByte() { return nullableByte; } + + // 24. name = 'byteArray', OData type = COMPLEX + private byte[] byteArray; + public byte[] getByteArray() { + return byteArray; + } + + // 25. name = 'byteList', OData type = COMPLEX + private List byteList; + public List getByteList() { + return byteList; + } } @Test public void validNormalizerField() { From 3019cb4b560668c8c062dc6a8f22db17bcb1829d Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Tue, 7 May 2024 13:12:58 -0400 Subject: [PATCH 10/10] Fix linting --- .../com/azure/search/documents/indexes/FieldBuilderTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java index cabf836354f7..f01ddf6a69b6 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/FieldBuilderTests.java @@ -25,7 +25,6 @@ import java.time.OffsetDateTime; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Date;