From 1cf5d7bada8aa350417974fe9159ecb6a84b029d Mon Sep 17 00:00:00 2001 From: Max Hniebergall Date: Wed, 3 Apr 2024 10:14:36 -0400 Subject: [PATCH 1/2] add rerank to _inference --- .../elasticsearch-serverless-openapi.json | 8 ++++++- output/schema/schema.json | 22 +++++++++++++++++-- output/typescript/types.ts | 3 ++- specification/inference/_types/TaskType.ts | 4 +++- .../inference/inference/InferenceRequest.ts | 5 +++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/output/openapi/elasticsearch-serverless-openapi.json b/output/openapi/elasticsearch-serverless-openapi.json index af0b6b3a15..9d189c1ce6 100644 --- a/output/openapi/elasticsearch-serverless-openapi.json +++ b/output/openapi/elasticsearch-serverless-openapi.json @@ -26343,6 +26343,10 @@ "schema": { "type": "object", "properties": { + "query": { + "description": "Query input, required for rerank task.\nNot required for other tasks.", + "type": "string" + }, "input": { "description": "Text input to the model.\nEither a string or an array of strings.", "oneOf": [ @@ -49592,7 +49596,9 @@ "type": "string", "enum": [ "sparse_embedding", - "text_embedding" + "text_embedding", + "rerank", + "completion" ] }, "inference._types:ModelConfigContainer": { diff --git a/output/schema/schema.json b/output/schema/schema.json index 55413ee362..5d7260d513 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -128565,13 +128565,19 @@ }, { "name": "text_embedding" + }, + { + "name": "rerank" + }, + { + "name": "completion" } ], "name": { "name": "TaskType", "namespace": "inference._types" }, - "specLocation": "inference/_types/TaskType.ts#L20-L26" + "specLocation": "inference/_types/TaskType.ts#L20-L28" }, { "description": "The text embedding result object for byte representation", @@ -128765,6 +128771,18 @@ "body": { "kind": "properties", "properties": [ + { + "description": "Query input, required for rerank task.\nNot required for other tasks.", + "name": "query", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + } + }, { "description": "Text input to the model.\nEither a string or an array of strings.", "name": "input", @@ -128845,7 +128863,7 @@ } ], "query": [], - "specLocation": "inference/inference/InferenceRequest.ts#L25-L53" + "specLocation": "inference/inference/InferenceRequest.ts#L25-L58" }, { "body": { diff --git a/output/typescript/types.ts b/output/typescript/types.ts index 0c7bb1ef5d..08a8de3ba7 100644 --- a/output/typescript/types.ts +++ b/output/typescript/types.ts @@ -11531,7 +11531,7 @@ export type InferenceSparseVector = Record export type InferenceTaskSettings = any -export type InferenceTaskType = 'sparse_embedding' | 'text_embedding' +export type InferenceTaskType = 'sparse_embedding' | 'text_embedding' | 'rerank' | 'completion' export interface InferenceTextEmbeddingByteResult { embedding: InferenceDenseByteVector @@ -11561,6 +11561,7 @@ export interface InferenceInferenceRequest extends RequestBase { task_type?: InferenceTaskType inference_id: Id body?: { + query?: string input: string | string[] task_settings?: InferenceTaskSettings } diff --git a/specification/inference/_types/TaskType.ts b/specification/inference/_types/TaskType.ts index c7c2e42a84..8bdc9f3727 100644 --- a/specification/inference/_types/TaskType.ts +++ b/specification/inference/_types/TaskType.ts @@ -22,5 +22,7 @@ */ export enum TaskType { sparse_embedding, - text_embedding + text_embedding, + rerank, + completion } diff --git a/specification/inference/inference/InferenceRequest.ts b/specification/inference/inference/InferenceRequest.ts index b98bb9f6e6..ee7dfe1f2d 100644 --- a/specification/inference/inference/InferenceRequest.ts +++ b/specification/inference/inference/InferenceRequest.ts @@ -40,6 +40,11 @@ export interface Request extends RequestBase { inference_id: Id } body: { + /** + * Query input, required for rerank task. + * Not required for other tasks. + */ + query?: string /** * Text input to the model. * Either a string or an array of strings. From d79756149887ce43210c590377ef64852e6e935f Mon Sep 17 00:00:00 2001 From: Max Hniebergall Date: Wed, 3 Apr 2024 10:54:42 -0400 Subject: [PATCH 2/2] Added rerank to inference Results --- .../elasticsearch-serverless-openapi.json | 24 ++++++++ output/schema/schema.json | 60 ++++++++++++++++++- output/typescript/types.ts | 7 +++ specification/inference/_types/Results.ts | 12 ++++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/output/openapi/elasticsearch-serverless-openapi.json b/output/openapi/elasticsearch-serverless-openapi.json index 9d189c1ce6..ae3f661524 100644 --- a/output/openapi/elasticsearch-serverless-openapi.json +++ b/output/openapi/elasticsearch-serverless-openapi.json @@ -49677,6 +49677,12 @@ "items": { "$ref": "#/components/schemas/inference._types:CompletionResult" } + }, + "rerank": { + "type": "array", + "items": { + "$ref": "#/components/schemas/inference._types:RankedDocument" + } } }, "minProperties": 1, @@ -49747,6 +49753,24 @@ "result" ] }, + "inference._types:RankedDocument": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "score": { + "type": "string" + }, + "text": { + "type": "string" + } + }, + "required": [ + "id", + "score" + ] + }, "_types:ElasticsearchVersionInfo": { "type": "object", "properties": { diff --git a/output/schema/schema.json b/output/schema/schema.json index 5d7260d513..d017fbed03 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -128392,9 +128392,23 @@ } } } + }, + { + "name": "rerank", + "required": false, + "type": { + "kind": "array_of", + "value": { + "kind": "instance_of", + "type": { + "name": "RankedDocument", + "namespace": "inference._types" + } + } + } } ], - "specLocation": "inference/_types/Results.ts#L66-L75", + "specLocation": "inference/_types/Results.ts#L77-L87", "variants": { "kind": "container" } @@ -128487,6 +128501,50 @@ ], "specLocation": "inference/_types/Services.ts#L41-L53" }, + { + "description": "The rerank result object representing a single ranked document\nid: the original index of the document in the request\nscore: the score of the document relative to the query\ntext: Optional, the text of the document, if requested", + "kind": "interface", + "name": { + "name": "RankedDocument", + "namespace": "inference._types" + }, + "properties": [ + { + "name": "id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + } + }, + { + "name": "score", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + } + }, + { + "name": "text", + "required": false, + "type": { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + } + } + ], + "specLocation": "inference/_types/Results.ts#L66-L76" + }, { "kind": "type_alias", "name": { diff --git a/output/typescript/types.ts b/output/typescript/types.ts index 08a8de3ba7..8e7d4596a8 100644 --- a/output/typescript/types.ts +++ b/output/typescript/types.ts @@ -11508,6 +11508,7 @@ export interface InferenceInferenceResult { text_embedding?: InferenceTextEmbeddingResult[] sparse_embedding?: InferenceSparseEmbeddingResult[] completion?: InferenceCompletionResult[] + rerank?: InferenceRankedDocument[] } export interface InferenceModelConfig { @@ -11521,6 +11522,12 @@ export interface InferenceModelConfigContainer extends InferenceModelConfig { task_type: InferenceTaskType } +export interface InferenceRankedDocument { + id: string + score: string + text?: string +} + export type InferenceServiceSettings = any export interface InferenceSparseEmbeddingResult { diff --git a/specification/inference/_types/Results.ts b/specification/inference/_types/Results.ts index 1b1741a236..0d5da84fea 100644 --- a/specification/inference/_types/Results.ts +++ b/specification/inference/_types/Results.ts @@ -63,6 +63,17 @@ export class CompletionResult { result: string } +/** + * The rerank result object representing a single ranked document + * id: the original index of the document in the request + * score: the score of the document relative to the query + * text: Optional, the text of the document, if requested + */ +export class RankedDocument { + id: string + score: string + text?: string +} /** * InferenceResult is an aggregation of mutually exclusive variants * @variants container @@ -72,4 +83,5 @@ export class InferenceResult { text_embedding?: Array sparse_embedding?: Array completion?: Array + rerank?: Array }