Semantic Embeddings with instructions
POSThttps://api.aleph-alpha.com/instructable_embed
Embeds the input using an instruction and a specific model. Resulting vectors that can be used for downstream tasks (e.g. semantic similarity) and models (e.g. classifiers). To obtain a valid model, use GET
/model-settings
.
Request
Query Parameters
Setting this to True, will signal to the API that you intend to be nice to other users by de-prioritizing your request below concurrent ones.
- application/json
Bodyrequired
Name of the model to use. A model name refers to a model's architecture (number of parameters among others). The most recent version of the model is always used. The model output contains information as to the model version. To find out which models support semantic embeddings with instructions, please refer to the /model-settings
endpoint.
Optional parameter that specifies which datacenters may process the request.
You can either set the parameter to "aleph-alpha" or omit it (defaulting to null
).
Not setting this value, or setting it to null
, gives us maximal flexibility in processing your request in our
own datacenters and on servers hosted with other providers. Choose this option for maximum availability.
Setting it to "aleph-alpha" allows us to only process the request in our own datacenters. Choose this option for maximal data privacy.
Possible values: [aleph-alpha
, null
]
input objectrequired
To further improve performance by steering the model, you can use instructions. Instructions can help the model understand nuances of your specific data and ultimately lead to embeddings that are more useful for your use-case. In this case, we aim to further increase the absolute difference between the cosine similarities. Instruction can also be the empty string.
Return normalized embeddings. This can be used to save on additional compute when applying a cosine similarity metric.
false
If set to null
, attention control parameters only apply to those tokens that have
explicitly been set in the request.
If set to a non-null value, we apply the control parameters to similar tokens as well.
Controls that have been applied to one token will then be applied to all other tokens
that have at least the similarity score defined by this parameter.
The similarity score is the cosine similarity of token embeddings.
null
true
: apply controls on prompt items by adding the log(control_factor)
to attention scores.
false
: apply controls on prompt items by (attention_scores - -attention_scores.min(-1)) * control_factor
true
Responses
- 200
OK
- application/json
- Schema
- Example (auto)
Schema
- Token ID arrays are used as as-is.
- Text prompt items are tokenized using the tokenizers specific to the model.
- Each image is converted into a fixed amount of tokens that depends on the chosen model.
model name and version (if any) of the used model for inference
A list of floats that can be used to compare against other embeddings.
Number of tokens in the prompt.
Tokenization:
{
"model_version": "2021-12",
"embedding": [
-0.053497314,
0.0053749084,
0.06427002,
0.05316162,
-0.0044059753,
"..."
],
"num_tokens_prompt_total": 42
}
Authorization: http
name: tokentype: httpscheme: bearerdescription: Can be generated in your [Aleph Alpha profile](https://app.aleph-alpha.com/profile)
- csharp
- curl
- dart
- go
- http
- java
- javascript
- kotlin
- c
- nodejs
- objective-c
- ocaml
- php
- powershell
- python
- r
- ruby
- rust
- shell
- swift
- HTTPCLIENT
- RESTSHARP
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.aleph-alpha.com/instructable_embed");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer <token>");
var content = new StringContent("{\n \"model\": \"pharia-1-embedding-4608-control\",\n \"input\": \"An apple a day keeps the doctor away.\",\n \"instruction\": \"Represent the user's question about rivers to find a relevant wikipedia paragraph\"\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());