UNPKG

@azure/search-documents

Version:
593 lines 24.8 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { parseCsvCollection } from "../../../../static-helpers/serialization/parse-csv-collection.js"; import { serializeRecord } from "../../../../static-helpers/serialization/serialize-record.js"; export function errorResponseDeserializer(item) { return { error: !item["error"] ? item["error"] : errorDetailDeserializer(item["error"]), }; } export function errorDetailDeserializer(item) { return { code: item["code"], message: item["message"], target: item["target"], details: !item["details"] ? item["details"] : errorDetailArrayDeserializer(item["details"]), additionalInfo: !item["additionalInfo"] ? item["additionalInfo"] : errorAdditionalInfoArrayDeserializer(item["additionalInfo"]), }; } export function errorDetailArrayDeserializer(result) { return result.map((item) => { return errorDetailDeserializer(item); }); } export function errorAdditionalInfoArrayDeserializer(result) { return result.map((item) => { return errorAdditionalInfoDeserializer(item); }); } export function errorAdditionalInfoDeserializer(item) { return { type: item["type"], info: !item["info"] ? item["info"] : Object.fromEntries(Object.entries(item["info"]).map(([k, p]) => [k, p])), }; } export function searchDocumentsResultSerializer(item) { return item; } export function searchDocumentsResultDeserializer(item) { return { count: item["@odata.count"], coverage: item["@search.coverage"], facets: !item["@search.facets"] ? item["@search.facets"] : facetResultArrayRecordDeserializer(item["@search.facets"]), answers: !item["@search.answers"] ? item["@search.answers"] : queryAnswerResultArrayDeserializer(item["@search.answers"]), nextPageParameters: !item["@search.nextPageParameters"] ? item["@search.nextPageParameters"] : searchRequestDeserializer(item["@search.nextPageParameters"]), results: searchResultArrayDeserializer(item["value"]), nextLink: item["@odata.nextLink"], semanticPartialResponseReason: item["@search.semanticPartialResponseReason"], semanticPartialResponseType: item["@search.semanticPartialResponseType"], }; } export function facetResultArrayRecordSerializer(item) { const result = {}; Object.keys(item).map((key) => { result[key] = !item[key] ? item[key] : facetResultArraySerializer(item[key]); }); return result; } export function facetResultArrayRecordDeserializer(item) { const result = {}; Object.keys(item).map((key) => { result[key] = !item[key] ? item[key] : facetResultArrayDeserializer(item[key]); }); return result; } export function facetResultArraySerializer(result) { return result.map((item) => { return facetResultSerializer(item); }); } export function facetResultArrayDeserializer(result) { return result.map((item) => { return facetResultDeserializer(item); }); } export function facetResultSerializer(item) { return { ...serializeRecord(item.additionalProperties ?? {}) }; } export function facetResultDeserializer(item) { return { additionalProperties: serializeRecord(item, ["count"]), count: item["count"], }; } export function queryAnswerResultArraySerializer(result) { return result.map((item) => { return queryAnswerResultSerializer(item); }); } export function queryAnswerResultArrayDeserializer(result) { return result.map((item) => { return queryAnswerResultDeserializer(item); }); } export function queryAnswerResultSerializer(item) { return { ...serializeRecord(item.additionalProperties ?? {}) }; } export function queryAnswerResultDeserializer(item) { return { additionalProperties: serializeRecord(item, ["score", "key", "text", "highlights"]), score: item["score"], key: item["key"], text: item["text"], highlights: item["highlights"], }; } export function searchRequestDeserializer(item) { return { includeTotalCount: item["count"], facets: !item["facets"] ? item["facets"] : item["facets"].map((p) => { return p; }), filter: item["filter"], highlightFields: item["highlight"] === null || item["highlight"] === undefined ? item["highlight"] : parseCsvCollection(item["highlight"]), highlightPostTag: item["highlightPostTag"], highlightPreTag: item["highlightPreTag"], minimumCoverage: item["minimumCoverage"], orderBy: item["orderby"], queryType: item["queryType"], scoringStatistics: item["scoringStatistics"], sessionId: item["sessionId"], scoringParameters: !item["scoringParameters"] ? item["scoringParameters"] : item["scoringParameters"].map((p) => { return p; }), scoringProfile: item["scoringProfile"], debug: item["debug"], searchText: item["search"], searchFields: item["searchFields"], searchMode: item["searchMode"], select: item["select"], skip: item["skip"], top: item["top"], semanticConfigurationName: item["semanticConfiguration"], semanticErrorHandling: item["semanticErrorHandling"], semanticMaxWaitInMilliseconds: item["semanticMaxWaitInMilliseconds"], semanticQuery: item["semanticQuery"], answers: item["answers"], captions: item["captions"], vectorQueries: !item["vectorQueries"] ? item["vectorQueries"] : vectorQueryUnionArrayDeserializer(item["vectorQueries"]), vectorFilterMode: item["vectorFilterMode"], }; } /** Specifies the syntax of the search query. The default is 'simple'. Use 'full' if your query uses the Lucene query syntax and 'semantic' if query syntax is not needed. */ export var KnownQueryType; (function (KnownQueryType) { /** Uses the simple query syntax for searches. Search text is interpreted using a simple query language that allows for symbols such as +, * and "". Queries are evaluated across all searchable fields by default, unless the searchFields parameter is specified. */ KnownQueryType["Simple"] = "simple"; /** Uses the full Lucene query syntax for searches. Search text is interpreted using the Lucene query language which allows field-specific and weighted searches, as well as other advanced features. */ KnownQueryType["Full"] = "full"; /** Best suited for queries expressed in natural language as opposed to keywords. Improves precision of search results by re-ranking the top search results using a ranking model trained on the Web corpus. */ KnownQueryType["Semantic"] = "semantic"; })(KnownQueryType || (KnownQueryType = {})); /** Enables a debugging tool that can be used to further explore your search results. You can enable multiple debug modes simultaneously by separating them with a | character, for example: semantic|queryRewrites. */ export var KnownQueryDebugMode; (function (KnownQueryDebugMode) { /** No query debugging information will be returned. */ KnownQueryDebugMode["Disabled"] = "disabled"; /** Allows the user to further explore their reranked results. */ KnownQueryDebugMode["Semantic"] = "semantic"; /** Allows the user to further explore their hybrid and vector query results. */ KnownQueryDebugMode["Vector"] = "vector"; /** Allows the user to explore the list of query rewrites generated for their search request. */ KnownQueryDebugMode["QueryRewrites"] = "queryRewrites"; /** Allows the user to retrieve scoring information regarding vectors matched within a collection of complex types. */ KnownQueryDebugMode["InnerHits"] = "innerHits"; /** Turn on all debug options. */ KnownQueryDebugMode["All"] = "all"; })(KnownQueryDebugMode || (KnownQueryDebugMode = {})); /** Allows the user to choose whether a semantic call should fail completely, or to return partial results. */ export var KnownSemanticErrorMode; (function (KnownSemanticErrorMode) { /** If the semantic processing fails, partial results still return. The definition of partial results depends on what semantic step failed and what was the reason for failure. */ KnownSemanticErrorMode["Partial"] = "partial"; /** If there is an exception during the semantic processing step, the query will fail and return the appropriate HTTP code depending on the error. */ KnownSemanticErrorMode["Fail"] = "fail"; })(KnownSemanticErrorMode || (KnownSemanticErrorMode = {})); /** 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. The maximum character length of answers can be configured by appending the pipe character '|' followed by the 'count-<number of maximum character length>', such as 'extractive|maxcharlength-600'. */ export var KnownQueryAnswerType; (function (KnownQueryAnswerType) { /** Do not return answers for the query. */ KnownQueryAnswerType["None"] = "none"; /** Extracts answer candidates from the contents of the documents returned in response to a query expressed as a question in natural language. */ KnownQueryAnswerType["Extractive"] = "extractive"; })(KnownQueryAnswerType || (KnownQueryAnswerType = {})); /** 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 default, and can be configured by appending the pipe character `|` followed by the `highlight-<true/false>` option, such as `extractive|highlight-true`. Defaults to `None`. The maximum character length of captions can be configured by appending the pipe character '|' followed by the 'count-<number of maximum character length>', such as 'extractive|maxcharlength-600'. */ export var KnownQueryCaptionType; (function (KnownQueryCaptionType) { /** Do not return captions for the query. */ KnownQueryCaptionType["None"] = "none"; /** Extracts captions from the matching documents that contain passages relevant to the search query. */ KnownQueryCaptionType["Extractive"] = "extractive"; })(KnownQueryCaptionType || (KnownQueryCaptionType = {})); export function vectorQueryUnionArraySerializer(result) { return result.map((item) => { return vectorQueryUnionSerializer(item); }); } export function vectorQueryUnionArrayDeserializer(result) { return result.map((item) => { return vectorQueryUnionDeserializer(item); }); } export function vectorQuerySerializer(item) { return { k: item["kNearestNeighborsCount"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], }; } export function vectorQueryDeserializer(item) { return { kNearestNeighborsCount: item["k"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], }; } export function vectorQueryUnionSerializer(item) { switch (item.kind) { case "vector": return vectorizedQuerySerializer(item); case "text": return vectorizableTextQuerySerializer(item); case "imageUrl": return vectorizableImageUrlQuerySerializer(item); case "imageBinary": return vectorizableImageBinaryQuerySerializer(item); default: return vectorQuerySerializer(item); } } export function vectorQueryUnionDeserializer(item) { switch (item["kind"]) { case "vector": return vectorizedQueryDeserializer(item); case "text": return vectorizableTextQueryDeserializer(item); case "imageUrl": return vectorizableImageUrlQueryDeserializer(item); case "imageBinary": return vectorizableImageBinaryQueryDeserializer(item); default: return vectorQueryDeserializer(item); } } /** The kind of vector query being performed. */ export var KnownVectorQueryKind; (function (KnownVectorQueryKind) { /** Vector query where a raw vector value is provided. */ KnownVectorQueryKind["Vector"] = "vector"; /** Vector query where a text value that needs to be vectorized is provided. */ KnownVectorQueryKind["Text"] = "text"; /** Vector query where an url that represents an image value that needs to be vectorized is provided. */ KnownVectorQueryKind["ImageUrl"] = "imageUrl"; /** Vector query where a base 64 encoded binary of an image that needs to be vectorized is provided. */ KnownVectorQueryKind["ImageBinary"] = "imageBinary"; })(KnownVectorQueryKind || (KnownVectorQueryKind = {})); export function vectorizedQuerySerializer(item) { return { k: item["kNearestNeighborsCount"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], vector: item["vector"].map((p) => { return p; }), }; } export function vectorizedQueryDeserializer(item) { return { kNearestNeighborsCount: item["k"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], vector: item["vector"].map((p) => { return p; }), }; } export function vectorizableTextQuerySerializer(item) { return { k: item["kNearestNeighborsCount"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], text: item["text"], }; } export function vectorizableTextQueryDeserializer(item) { return { kNearestNeighborsCount: item["k"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], text: item["text"], }; } export function vectorizableImageUrlQuerySerializer(item) { return { k: item["kNearestNeighborsCount"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], url: item["url"], }; } export function vectorizableImageUrlQueryDeserializer(item) { return { kNearestNeighborsCount: item["k"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], url: item["url"], }; } export function vectorizableImageBinaryQuerySerializer(item) { return { k: item["kNearestNeighborsCount"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], base64Image: item["base64Image"], }; } export function vectorizableImageBinaryQueryDeserializer(item) { return { kNearestNeighborsCount: item["k"], fields: item["fields"], exhaustive: item["exhaustive"], oversampling: item["oversampling"], weight: item["weight"], kind: item["kind"], base64Image: item["base64Image"], }; } /** Determines whether or not filters are applied before or after the vector search is performed. */ export var KnownVectorFilterMode; (function (KnownVectorFilterMode) { /** The filter will be applied after the candidate set of vector results is returned. Depending on the filter selectivity, this can result in fewer results than requested by the parameter 'k'. */ KnownVectorFilterMode["PostFilter"] = "postFilter"; /** The filter will be applied before the search query. */ KnownVectorFilterMode["PreFilter"] = "preFilter"; /** The filter will be applied after the global top-k candidate set of vector results is returned. This will result in fewer results than requested by the parameter 'k'. */ KnownVectorFilterMode["StrictPostFilter"] = "strictPostFilter"; })(KnownVectorFilterMode || (KnownVectorFilterMode = {})); export function searchResultArraySerializer(result) { return result.map((item) => { return searchResultSerializer(item); }); } export function searchResultArrayDeserializer(result) { return result.map((item) => { return searchResultDeserializer(item); }); } export function searchResultSerializer(item) { return { ...serializeRecord(item.additionalProperties ?? {}) }; } export function searchResultDeserializer(item) { return { additionalProperties: serializeRecord(item, [ "score", "rerankerScore", "rerankerBoostedScore", "highlights", "captions", "documentDebugInfo", ]), score: item["@search.score"], rerankerScore: item["@search.rerankerScore"], rerankerBoostedScore: item["@search.rerankerBoostedScore"], highlights: !item["@search.highlights"] ? item["@search.highlights"] : Object.fromEntries(Object.entries(item["@search.highlights"]).map(([k, p]) => [ k, p.map((p1) => { return p1; }), ])), captions: !item["@search.captions"] ? item["@search.captions"] : queryCaptionResultArrayDeserializer(item["@search.captions"]), documentDebugInfo: !item["@search.documentDebugInfo"] ? item["@search.documentDebugInfo"] : documentDebugInfoDeserializer(item["@search.documentDebugInfo"]), }; } export function queryCaptionResultArrayDeserializer(result) { return result.map((item) => { return queryCaptionResultDeserializer(item); }); } export function queryCaptionResultDeserializer(item) { return { additionalProperties: serializeRecord(item, ["text", "highlights"]), text: item["text"], highlights: item["highlights"], }; } export function documentDebugInfoDeserializer(item) { return { vectors: !item["vectors"] ? item["vectors"] : vectorsDebugInfoDeserializer(item["vectors"]), }; } export function vectorsDebugInfoDeserializer(item) { return { subscores: !item["subscores"] ? item["subscores"] : queryResultDocumentSubscoresDeserializer(item["subscores"]), }; } export function queryResultDocumentSubscoresDeserializer(item) { return { text: !item["text"] ? item["text"] : textResultDeserializer(item["text"]), vectors: !item["vectors"] ? item["vectors"] : singleVectorFieldResultRecordArrayDeserializer(item["vectors"]), documentBoost: item["documentBoost"], }; } export function textResultDeserializer(item) { return { searchScore: item["searchScore"], }; } export function singleVectorFieldResultRecordArrayDeserializer(result) { return result.map((item) => { return singleVectorFieldResultRecordDeserializer(item); }); } export function singleVectorFieldResultRecordDeserializer(item) { const result = {}; Object.keys(item).map((key) => { result[key] = !item[key] ? item[key] : singleVectorFieldResultDeserializer(item[key]); }); return result; } export function singleVectorFieldResultDeserializer(item) { return { searchScore: item["searchScore"], vectorSimilarity: item["vectorSimilarity"], }; } /** Reason that a partial response was returned for a semantic ranking request. */ export var KnownSemanticErrorReason; (function (KnownSemanticErrorReason) { /** If `semanticMaxWaitInMilliseconds` was set and the semantic processing duration exceeded that value. Only the base results were returned. */ KnownSemanticErrorReason["MaxWaitExceeded"] = "maxWaitExceeded"; /** The request was throttled. Only the base results were returned. */ KnownSemanticErrorReason["CapacityOverloaded"] = "capacityOverloaded"; /** At least one step of the semantic process failed. */ KnownSemanticErrorReason["Transient"] = "transient"; })(KnownSemanticErrorReason || (KnownSemanticErrorReason = {})); /** Type of partial response that was returned for a semantic ranking request. */ export var KnownSemanticSearchResultsType; (function (KnownSemanticSearchResultsType) { /** Results without any semantic enrichment or reranking. */ KnownSemanticSearchResultsType["BaseResults"] = "baseResults"; /** Results have been reranked with the reranker model and will include semantic captions. They will not include any answers, answers highlights or caption highlights. */ KnownSemanticSearchResultsType["RerankedResults"] = "rerankedResults"; })(KnownSemanticSearchResultsType || (KnownSemanticSearchResultsType = {})); export function lookupDocumentDeserializer(item) { return { additionalProperties: serializeRecord(item, []), }; } export function suggestDocumentsResultDeserializer(item) { return { results: suggestResultArrayDeserializer(item["value"]), coverage: item["@search.coverage"], }; } export function suggestResultArraySerializer(result) { return result.map((item) => { return suggestResultSerializer(item); }); } export function suggestResultArrayDeserializer(result) { return result.map((item) => { return suggestResultDeserializer(item); }); } export function suggestResultSerializer(item) { return { ...serializeRecord(item.additionalProperties ?? {}) }; } export function suggestResultDeserializer(item) { return { additionalProperties: serializeRecord(item, ["text"]), text: item["@search.text"], }; } export function indexDocumentsBatchSerializer(item) { return { value: indexActionArraySerializer(item["actions"]) }; } export function indexActionArraySerializer(result) { return result.map((item) => { return indexActionSerializer(item); }); } export function indexActionSerializer(item) { return { ...serializeRecord(item.additionalProperties ?? {}), "@search.action": item["actionType"], }; } export function indexDocumentsResultDeserializer(item) { return { results: indexingResultArrayDeserializer(item["value"]), }; } export function indexingResultArraySerializer(result) { return result.map((item) => { return indexingResultSerializer(item); }); } export function indexingResultArrayDeserializer(result) { return result.map((item) => { return indexingResultDeserializer(item); }); } export function indexingResultSerializer(item) { return item; } export function indexingResultDeserializer(item) { return { key: item["key"], errorMessage: item["errorMessage"], succeeded: item["status"], statusCode: item["statusCode"], }; } export function autocompleteResultDeserializer(item) { return { coverage: item["@search.coverage"], results: autocompleteItemArrayDeserializer(item["value"]), }; } export function autocompleteItemArraySerializer(result) { return result.map((item) => { return autocompleteItemSerializer(item); }); } export function autocompleteItemArrayDeserializer(result) { return result.map((item) => { return autocompleteItemDeserializer(item); }); } export function autocompleteItemSerializer(item) { return item; } export function autocompleteItemDeserializer(item) { return { text: item["text"], queryPlusText: item["queryPlusText"], }; } //# sourceMappingURL=models.js.map