Embeddings Call
Embeddings
Embeddings calls are calls that can generate vector outputs of weight for a text. While this might sound boring, it's an important part of RAG/vector search.
Example normalized Embeddings call
The following is an example of sending the text "What type of comedy is Steve Martin famous for?" into OpenAI using the text-embedding-3-small model. The output is an array of floats.
use Drupal\ai\OperationType\Embeddings\EmbeddingsInput;
$input = new EmbeddingsInput('What type of comedy is Steve Martin famous for');
/** @var \Drupal\ai\OperationType\Embeddings\EmbeddingsOutput $vector_object */
$vector_object = \Drupal::service('ai.provider')->createInstance('openai')->Embeddings($input, 'text-embedding-3-small', ['my-custom-call']);
print_r($vector_object->getNormalized());
// This will output an array of floats.
Embeddings Interfaces & Models
The following files define the methods available when doing an embeddings call as well as the input and output.
Embeddings Explorer
If you install the AI API Explorer, you can go to Configuration > AI > AI API Explorers > Embeddings Explorer at /admin/config/ai/explorers/embeddings_generator to try out calls and copy the code for them.