Embeddings

The embeddings endpoint generates embeddings from the input text and returns a vector.

Embeddings are used by data scientists to capture semantic information about language.

How to Call the Endpoint

Python SDK

First, make sure you are using the latest version of the SDK; the endpoint will not work on versions prior to 2.2.0. You can use this command to upgrade:

pip install scienceio --upgrade

After initializing the ScienceIO client, use scio.embeddings() to submit the request:

from scienceio import ScienceIO
scio = ScienceIO()

query_text = "The patient presents with a complaint of allergies to ragweed."

# Call the embeddings endpoint
response = scio.embeddings(query_text)

# Print and format the response
import json
print(json.dumps(response, indent=2))

View the JSON response.

HTTP

Update the endpoint in your POST request to embeddings as shown in the URL below:

curl https://api.aws.science.io/v2/embeddings \  
  --request POST \        
  --header "Content-type: application/json" \
  --header "x-api-id: $SCIENCEIO_KEY_ID" \
  --header "x-api-secret: $SCIENCEIO_KEY_SECRET" \
  --data '{ "input_text": "The patient presents with a complaint of allergies to ragweed."}'

You will receive a response containing a request_id and the inference_status. Use the request_id in your GET request as shown below to retrieve your results:

curl https://api.aws.science.io/v2/embeddings/<REQUEST_ID> \
  --request GET \
  --header "x-api-id: $SCIENCEIO_KEY_ID" \
  --header "x-api-secret: $SCIENCEIO_KEY_SECRET"

JSON Response

A response from the embeddings endpoint contains a vector with 1024 numbers.

Note: The JSON response below has been purposely truncated due to length; the actual response does contain 1024 numbers.

{
  "input_text": "The patient presents with a complaint of allergies to ragweed.",
  "embeddings": [
    1.8246774673461914,
    -0.844181478023529,
    -1.5076367855072021,
    -1.3067437410354614,
    -1.7539191246032715,
    -2.1734962463378906,
    -1.7270381450653076,
    -0.021796129643917084,
    1.8656187057495117,
    1.1780860424041748,
    2.352179527282715,
    4.2799072265625,
    1.001699686050415,
    4.147101402282715,
    1.4132367372512817,
    -0.5631498694419861,
    1.8193037509918213,
    1.82432222366333,
    0.13829514384269714,
    0.24757304787635803,
    -0.232064887881279,
    0.49826741218566895,
    1.6542580127716064,
    0.8582350015640259,
    -4.373599052429199,
    ...
  ]
}