NavigationContentFooter
Jump toSuggest an edit

How to query embedding models

Reviewed on 28 August 2024Published on 28 August 2024

Scaleway’s Generative APIs service allows users to interact with embedding models hosted on the platform. The embedding API provides a simple interface for generating vector representations (embeddings) based on your input data. The embedding service is OpenAI compatible. Refer to OpenAI’s embedding documentation for more detailed information.

Before you start

To complete the actions presented below, you must have:

  • Access to this service is restricted while in beta. You can request access to the product by filling out a form on the Scaleway’s betas page.
  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • A valid API key for API authentication
  • Python 3.7+ installed on your system

Querying embedding models via API

The embedding model inputs text and outputs a vector (list) of floating point numbers to use for tasks like similarity comparisons and search. The instructions below show you how to query the model programmatically using the OpenAI SDK.

Installing the OpenAI SDK

First, ensure you have the OpenAI SDK installed in your development environment. You can install it using pip:

pip install openai

Initializing the client

Initialize the OpenAI client with your base URL and API key:

from openai import OpenAI
# Initialize the client with your base URL and API key
client = OpenAI(
base_url="https://api.scaleway.ai/v1", # Scaleway's Generative APIs service URL
api_key="<SCW_API_KEY>" # Your unique API key from Scaleway
)

Generating embeddings with sentence-t5-xxl

You can now generate embeddings using the sentence-t5-xxl model, such as the following example:

# Generate embeddings using the 'sentence-t5-xxl' model
embedding_response = client.embeddings.create(
input= "Artificial Intelligence is transforming the world.",
model= "sentence-t5-xxl"
)
# Output the embedding vector
print(embedding_response.data[0].embedding)

This code sends input text to the sentence-t5-xxl embedding model and returns a vector representation of the text. The sentence-t5-xxl model is specifically designed for generating high-quality sentence embeddings.

Model parameters and their effects

The following parameters can be adjusted to influence the output of the embedding model:

  • input (string or array of strings): The text or data you want to convert into vectors.
  • model (string): The specific embedding model to use, find all our supported models.

If you encounter an error such as “Forbidden 403” refer to the API documentation for troubleshooting tips.

See also
How to query text models
Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway