Skip to content

Commit d16e98c

Browse files
feat(voyageai): add output_dimension support for embeddings (#904)
1 parent 189b1cb commit d16e98c

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/Providers/VoyageAI/Embeddings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected function sendRequest(): void
5151
'model' => $this->request->model(),
5252
'input' => $this->request->inputs(),
5353
'input_type' => $providerOptions['inputType'] ?? null,
54+
'output_dimension' => $providerOptions['outputDimension'] ?? null,
5455
'truncation' => $providerOptions['truncation'] ?? null,
5556
]));
5657

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"object":"list","data":[{"object":"embedding","embedding":[0.1,0.2,0.3,0.4],"index":0}],"model":"voyage-3-lite","usage":{"total_tokens":8}}

tests/Providers/VoyageAI/EmbeddingsTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@
9898
expect($response->usage->tokens)->toBe(7);
9999
});
100100

101+
it('returns embeddings with outputDimension set', function (): void {
102+
FixtureResponse::fakeResponseSequence('*', 'voyageai/embeddings-with-output-dimension');
103+
104+
$response = Prism::embeddings()
105+
->using(Provider::VoyageAI, 'voyage-3-lite')
106+
->fromInput('The food was delicious and the waiter...')
107+
->withProviderOptions(['outputDimension' => 4])
108+
->asEmbeddings();
109+
110+
expect($response->embeddings)->toBeArray();
111+
expect($response->embeddings[0]->embedding)->toHaveCount(4);
112+
expect($response->usage->tokens)->toBe(8);
113+
114+
Http::assertSent(function ($request): bool {
115+
$body = json_decode((string) $request->body(), true);
116+
117+
return $body['output_dimension'] === 4;
118+
});
119+
});
120+
121+
it('does not include output_dimension when not set', function (): void {
122+
FixtureResponse::fakeResponseSequence('*', 'voyageai/embeddings-from-input');
123+
124+
Prism::embeddings()
125+
->using(Provider::VoyageAI, 'voyage-3-lite')
126+
->fromInput('The food was delicious and the waiter...')
127+
->asEmbeddings();
128+
129+
Http::assertSent(function ($request): bool {
130+
$body = json_decode((string) $request->body(), true);
131+
132+
return ! array_key_exists('output_dimension', $body);
133+
});
134+
});
135+
101136
it('throws a PrismRateLimitedException for a 429 response code', function (): void {
102137
Http::fake([
103138
'*' => Http::response(

0 commit comments

Comments
 (0)