adachsoft/embedding-openai

OpenAI Embeddings provider implementation for adachsoft/embedding-contracts.

Maintainers

Package info

gitlab.com/a.adach/embedding-openai

Issues

pkg:composer/adachsoft/embedding-openai

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-03-23 17:23 UTC

This package is not auto-updated.

Last update: 2026-03-24 14:43:36 UTC


README

Provider-specific implementation of adachsoft/embedding-contracts for the OpenAI Embeddings API.

This library provides a production-ready implementation of EmbedderInterface that talks to the official OpenAI HTTP API using Guzzle and exposes a simple, DTO-based contract for generating text embeddings.

Installation

composer require adachsoft/embedding-openai

This will also install adachsoft/embedding-contracts and guzzlehttp/guzzle as dependencies.

Usage

<?php declare(strict_types=1);

use AdachSoft\EmbeddingContracts\Dto\EmbeddingRequestDto;
use AdachSoft\EmbeddingContracts\Enum\EmbeddingEncodingFormatEnum;
use AdachSoft\EmbeddingContracts\Enum\EmbeddingInputTypeEnum;
use AdachSoft\EmbeddingOpenai\OpenAiEmbedder;
use GuzzleHttp\Client;

$client = new Client();
$apiKey = $_ENV['OPENAI_API_KEY'] ?? getenv('OPENAI_API_KEY');

$embedder = new OpenAiEmbedder($client, (string) $apiKey);

$request = new EmbeddingRequestDto(
    input: 'hello world',
    model: 'text-embedding-3-small',
    inputType: EmbeddingInputTypeEnum::Query,
    encodingFormat: EmbeddingEncodingFormatEnum::Float,
);

$response = $embedder->embed($request);

// $response->vector now contains the embedding for "hello world".

Testing

The project ships with a production integration test that talks to the real OpenAI API.

To run it, you must provide a valid API key via OPENAI_API_KEY in your environment (or .env file) and then execute:

vendor/bin/phpunit --group production

By default, this production test group is excluded from the regular test suite.