Skip to content

Commit cef2af0

Browse files
committed
Contextual AI docs
1 parent 94b2f1a commit cef2af0

File tree

6 files changed

+194
-0
lines changed

6 files changed

+194
-0
lines changed

specification/inference/_types/CommonTypes.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,55 @@ export class CustomTaskSettings {
11951195
parameters?: UserDefinedValue
11961196
}
11971197

1198+
export enum ContextualAIServiceType {
1199+
contextualai
1200+
}
1201+
1202+
export class ContextualAIServiceSettings {
1203+
/**
1204+
* A valid API key for your Contexutual AI account.
1205+
*
1206+
* IMPORTANT: You need to provide the API key only once, during the inference model creation.
1207+
* The get inference endpoint API does not retrieve your API key.
1208+
* After creating the inference model, you cannot change the associated API key.
1209+
* If you want to use a different API key, delete the inference model and recreate it with the same name and the updated API key.
1210+
* @ext_doc_id contextualai-api-keys
1211+
*/
1212+
api_key: string
1213+
/**
1214+
* The name of the model to use for the inference task.
1215+
* Refer to the Contextual AI documentation for the list of available rerank models.
1216+
* @ext_doc_id contextualai-rerank
1217+
*/
1218+
model_id: string
1219+
/**
1220+
* This setting helps to minimize the number of rate limit errors returned from Contextual AI.
1221+
* The `contextualai` service sets a default number of requests allowed per minute depending on the task type.
1222+
* For `rerank`, it is set to `1000`.
1223+
*/
1224+
rate_limit?: RateLimitSetting
1225+
}
1226+
1227+
export class ContextualAITaskSettings {
1228+
/**
1229+
* Instructions for the reranking model. Refer to <https://docs.contextual.ai/api-reference/rerank/rerank#body-instruction>
1230+
* Only for the `rerank` task type.
1231+
*/
1232+
instruction?: string
1233+
/**
1234+
* Whether to return the source documents in the response.
1235+
* Only for the `rerank` task type.
1236+
* @server_default false
1237+
*/
1238+
return_documents?: boolean
1239+
/**
1240+
* The number of most relevant documents to return.
1241+
* If not specified, the reranking results of all documents will be returned.
1242+
* Only for the `rerank` task type.
1243+
*/
1244+
top_k?: integer
1245+
}
1246+
11981247
export class DeepSeekServiceSettings {
11991248
/**
12001249
* A valid API key for your DeepSeek account.

specification/inference/_types/Services.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
TaskTypeAzureAIStudio,
3030
TaskTypeAzureOpenAI,
3131
TaskTypeCohere,
32+
TaskTypeContextualAI,
3233
TaskTypeCustom,
3334
TaskTypeDeepSeek,
3435
TaskTypeElasticsearch,
@@ -168,6 +169,17 @@ export class InferenceEndpointInfoCohere extends InferenceEndpoint {
168169
task_type: TaskTypeCohere
169170
}
170171

172+
export class InferenceEndpointInfoContextualAi extends InferenceEndpoint {
173+
/**
174+
* The inference Id
175+
*/
176+
inference_id: string
177+
/**
178+
* The task type
179+
*/
180+
task_type: TaskTypeContextualAI
181+
}
182+
171183
export class InferenceEndpointInfoCustom extends InferenceEndpoint {
172184
/**
173185
* The inference Id
@@ -389,6 +401,7 @@ export class RateLimitSetting {
389401
* * `azureopenai` service and task type `text_embedding`: `1440`
390402
* * `azureopenai` service and task type `completion`: `120`
391403
* * `cohere` service: `10000`
404+
* * `contextualai` service: `1000`
392405
* * `elastic` service and task type `chat_completion`: `240`
393406
* * `googleaistudio` service: `360`
394407
* * `googlevertexai` service: `30000`

specification/inference/_types/TaskType.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export enum TaskTypeCohere {
7979
completion
8080
}
8181

82+
export enum TaskTypeContextualAI {
83+
rerank
84+
}
85+
8286
export enum TaskTypeCustom {
8387
text_embedding,
8488
sparse_embedding,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { RequestBase } from '@_types/Base'
21+
import { Id } from '@_types/common'
22+
import { Duration } from '@_types/Time'
23+
import { TaskTypeContextualAI } from '@inference/_types/TaskType'
24+
import {
25+
ContextualAIServiceSettings,
26+
ContextualAIServiceType,
27+
ContextualAITaskSettings,
28+
} from '@inference/_types/CommonTypes'
29+
import { InferenceChunkingSettings } from '@inference/_types/Services'
30+
31+
/**
32+
* Create an Contextual AI inference endpoint.
33+
*
34+
* Create an inference endpoint to perform an inference task with the `contexualai` service.
35+
*
36+
* To review the available `rerank` models, refer to <https://docs.contextual.ai/api-reference/rerank/rerank#body-model>.
37+
* @rest_spec_name inference.put_contextualai
38+
* @availability stack since=9.2.0 stability=stable visibility=public
39+
* @availability serverless stability=stable visibility=public
40+
* @cluster_privileges manage_inference
41+
* @doc_id inference-api-put-contextualai
42+
*/
43+
export interface Request extends RequestBase {
44+
urls: [
45+
{
46+
path: '/_inference/{task_type}/{contextualai_inference_id}'
47+
methods: ['PUT']
48+
}
49+
]
50+
path_parts: {
51+
/**
52+
* The type of the inference task that the model will perform.
53+
*/
54+
task_type: TaskTypeContextualAI
55+
/**
56+
* The unique identifier of the inference endpoint.
57+
*/
58+
contextualai_inference_id: Id
59+
}
60+
query_parameters: {
61+
/**
62+
* Specifies the amount of time to wait for the inference endpoint to be created.
63+
* @server_default 30s
64+
*/
65+
timeout?: Duration
66+
}
67+
body: {
68+
/**
69+
* The chunking configuration object.
70+
* @ext_doc_id inference-chunking
71+
*/
72+
chunking_settings?: InferenceChunkingSettings
73+
/**
74+
* The type of service supported for the specified task type. In this case, `contextualai`.
75+
*/
76+
service: ContextualAIServiceType
77+
/**
78+
* Settings used to install the inference model. These settings are specific to the `contextualai` service.
79+
*/
80+
service_settings: ContextualAIServiceSettings
81+
/**
82+
* Settings to configure the inference task.
83+
* These settings are specific to the task type you specified.
84+
*/
85+
task_settings?: ContextualAITaskSettings
86+
}
87+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { InferenceEndpointInfoContextualAi } from '@inference/_types/Services'
21+
22+
export class Response {
23+
/** @codegen_name endpoint_info */
24+
body: InferenceEndpointInfoContextualAi
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
summary: A rerank task
2+
description: Run `PUT _inference/rerank/contextualai-rerank` to create an inference endpoint for rerank tasks using the Contextual AI service.
3+
method_request: 'PUT _inference/rerank/contextualai-rerank'
4+
# type: "request"
5+
value: |-
6+
{
7+
"service": "contextualai",
8+
"service_settings": {
9+
"api_key": "ContextualAI-Api-key",
10+
"model_id": "ctxl-rerank-v2-instruct-multilingual-mini"
11+
},
12+
"task_settings": {
13+
"instruction": "Rerank the following documents based on their relevance to the query.",
14+
"top_k": 3
15+
}
16+
}

0 commit comments

Comments
 (0)