Skip to content

Commit 2a430a3

Browse files
mikadamczykGrabowskiM
authored andcommitted
Refactor embedding configuration methods for clarity and consistency
1 parent 44d3797 commit 2a430a3

File tree

7 files changed

+44
-44
lines changed

7 files changed

+44
-44
lines changed

src/contracts/Search/Embedding/EmbeddingConfigurationInterface.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ interface EmbeddingConfigurationInterface
1616
/**
1717
* @return array<string, array{name: string, dimensions: int, field_suffix: string, embedding_provider: string}>
1818
*/
19-
public function getEmbeddingModels(): array;
19+
public function getModels(): array;
2020

2121
/**
2222
* @return string[]
2323
*/
24-
public function getEmbeddingModelIdentifiers(): array;
24+
public function getModelIdentifiers(): array;
2525

2626
/**
2727
* @return array{name: string, dimensions: int, field_suffix: string, embedding_provider: string}
2828
*/
29-
public function getEmbeddingModel(string $identifier): array;
29+
public function getModel(string $identifier): array;
3030

31-
public function getDefaultEmbeddingModelIdentifier(): string;
31+
public function getDefaultModelIdentifier(): string;
3232

3333
/**
34-
* @return array{name: string, dimensions: int, field_suffix: string, 'embedding_provider': string}
34+
* @return array{name: string, dimensions: int, field_suffix: string, embedding_provider: string}
3535
*/
36-
public function getDefaultEmbeddingModel(): array;
36+
public function getDefaultModel(): array;
3737

38-
public function getDefaultEmbeddingProvider(): string;
38+
public function getDefaultProvider(): string;
3939

40-
public function getDefaultEmbeddingModelFieldSuffix(): string;
40+
public function getDefaultModelFieldSuffix(): string;
4141
}

src/contracts/Search/FieldType/EmbeddingFieldFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function create(?string $type = null): EmbeddingField
2525
return EmbeddingField::create($type);
2626
}
2727

28-
$suffix = $this->config->getDefaultEmbeddingModelFieldSuffix();
28+
$suffix = $this->config->getDefaultModelFieldSuffix();
2929

3030
return EmbeddingField::create('ibexa_dense_vector_' . $suffix);
3131
}

src/lib/Search/Embedding/EmbeddingConfiguration.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
/**
2626
* @return array<string, array{name: string, dimensions: int, field_suffix: string, embedding_provider: string}>
2727
*/
28-
public function getEmbeddingModels(): array
28+
public function getModels(): array
2929
{
3030
$models = $this->configResolver->getParameter('embedding_models');
3131

@@ -44,17 +44,17 @@ public function getEmbeddingModels(): array
4444
/**
4545
* @return string[]
4646
*/
47-
public function getEmbeddingModelIdentifiers(): array
47+
public function getModelIdentifiers(): array
4848
{
49-
return array_keys($this->getEmbeddingModels());
49+
return array_keys($this->getModels());
5050
}
5151

5252
/**
5353
* @return array{name: string, dimensions: int, field_suffix: string, embedding_provider: string}
5454
*/
55-
public function getEmbeddingModel(string $identifier): array
55+
public function getModel(string $identifier): array
5656
{
57-
$models = $this->getEmbeddingModels();
57+
$models = $this->getModels();
5858

5959
if (!isset($models[$identifier])) {
6060
throw new InvalidArgumentException(
@@ -65,7 +65,7 @@ public function getEmbeddingModel(string $identifier): array
6565
return $models[$identifier];
6666
}
6767

68-
public function getDefaultEmbeddingModelIdentifier(): string
68+
public function getDefaultModelIdentifier(): string
6969
{
7070
$identifier = $this->configResolver->getParameter('default_embedding_model');
7171

@@ -84,16 +84,16 @@ public function getDefaultEmbeddingModelIdentifier(): string
8484
/**
8585
* @return array{name: string, dimensions: int, field_suffix: string, embedding_provider: string}
8686
*/
87-
public function getDefaultEmbeddingModel(): array
87+
public function getDefaultModel(): array
8888
{
89-
return $this->getEmbeddingModel(
90-
$this->getDefaultEmbeddingModelIdentifier()
89+
return $this->getModel(
90+
$this->getDefaultModelIdentifier()
9191
);
9292
}
9393

94-
public function getDefaultEmbeddingProvider(): string
94+
public function getDefaultProvider(): string
9595
{
96-
$provider = $this->getDefaultEmbeddingModel()['embedding_provider'];
96+
$provider = $this->getDefaultModel()['embedding_provider'];
9797

9898
if (!is_string($provider)) {
9999
throw new InvalidArgumentException(
@@ -107,9 +107,9 @@ public function getDefaultEmbeddingProvider(): string
107107
return $provider;
108108
}
109109

110-
public function getDefaultEmbeddingModelFieldSuffix(): string
110+
public function getDefaultModelFieldSuffix(): string
111111
{
112-
$fieldSuffix = $this->getDefaultEmbeddingModel()['field_suffix'];
112+
$fieldSuffix = $this->getDefaultModel()['field_suffix'];
113113

114114
if (!is_string($fieldSuffix)) {
115115
throw new InvalidArgumentException(

src/lib/Search/Embedding/EmbeddingProviderResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030

3131
public function resolve(): EmbeddingProviderInterface
3232
{
33-
$defaultEmbeddingProvider = $this->embeddingConfiguration->getDefaultEmbeddingProvider();
33+
$defaultEmbeddingProvider = $this->embeddingConfiguration->getDefaultProvider();
3434

3535
if (!$this->registry->hasEmbeddingProvider($defaultEmbeddingProvider)) {
3636
throw new EmbeddingResolverNotFoundException(

tests/integration/Core/Search/FieldType/EmbeddingFieldFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testCreateUsesConfigSuffix(): void
2020
$config = $this->createMock(EmbeddingConfigurationInterface::class);
2121
$config
2222
->expects(self::once())
23-
->method('getDefaultEmbeddingModelFieldSuffix')
23+
->method('getDefaultModelFieldSuffix')
2424
->willReturn($suffix);
2525

2626
$factory = new EmbeddingFieldFactory($config);
@@ -39,7 +39,7 @@ public function testCreateWithCustomType(): void
3939
$config = $this->createMock(EmbeddingConfigurationInterface::class);
4040
$config
4141
->expects($this->never())
42-
->method('getDefaultEmbeddingModelFieldSuffix');
42+
->method('getDefaultModelFieldSuffix');
4343

4444
$factory = new EmbeddingFieldFactory($config);
4545
$customType = 'custom_model';

tests/lib/Search/Embedding/EmbeddingConfigurationTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function setUp(): void
3434
);
3535
}
3636

37-
public function testGetDefaultEmbeddingModel(): void
37+
public function testGetDefaultModel(): void
3838
{
3939
$this->configResolver
4040
->method('getParameter')
@@ -45,11 +45,11 @@ public function testGetDefaultEmbeddingModel(): void
4545

4646
self::assertSame(
4747
['name' => 'text-embedding-ada-002', 'dimensions' => 1536, 'field_suffix' => 'ada002', 'embedding_provider' => 'ibexa_openai'],
48-
$this->config->getDefaultEmbeddingModel()
48+
$this->config->getDefaultModel()
4949
);
5050
}
5151

52-
public function testGetEmbeddingModelIdentifiers(): void
52+
public function testGetModelIdentifiers(): void
5353
{
5454
$this->configResolver
5555
->method('getParameter')
@@ -60,25 +60,25 @@ public function testGetEmbeddingModelIdentifiers(): void
6060

6161
self::assertSame(
6262
['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002'],
63-
$this->config->getEmbeddingModelIdentifiers()
63+
$this->config->getModelIdentifiers()
6464
);
6565
}
6666

67-
public function testGetEmbeddingModels(): void
67+
public function testGetModels(): void
6868
{
6969
$this->configResolver
7070
->method('getParameter')
7171
->with('embedding_models')
7272
->willReturn(self::MODELS);
7373

74-
self::assertSame(self::MODELS, $this->config->getEmbeddingModels());
74+
self::assertSame(self::MODELS, $this->config->getModels());
7575
self::assertSame(
7676
['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002'],
77-
$this->config->getEmbeddingModelIdentifiers()
77+
$this->config->getModelIdentifiers()
7878
);
7979
}
8080

81-
public function testGetEmbeddingModel(): void
81+
public function testGetModel(): void
8282
{
8383
$this->configResolver
8484
->method('getParameter')
@@ -87,11 +87,11 @@ public function testGetEmbeddingModel(): void
8787

8888
self::assertSame(
8989
['name' => 'text-embedding-ada-002', 'dimensions' => 1536, 'field_suffix' => 'ada002', 'embedding_provider' => 'ibexa_openai'],
90-
$this->config->getEmbeddingModel('text-embedding-ada-002')
90+
$this->config->getModel('text-embedding-ada-002')
9191
);
9292
}
9393

94-
public function testGetEmbeddingModelWillThrowException(): void
94+
public function testGetModelWillThrowException(): void
9595
{
9696
$this->configResolver
9797
->method('getParameter')
@@ -101,20 +101,20 @@ public function testGetEmbeddingModelWillThrowException(): void
101101
$this->expectException(InvalidArgumentException::class);
102102
$this->expectExceptionMessage('Embedding model "non-existing-model" is not configured.');
103103

104-
$this->config->getEmbeddingModel('non-existing-model');
104+
$this->config->getModel('non-existing-model');
105105
}
106106

107-
public function testGetDefaultEmbeddingModelIdentifier(): void
107+
public function testGetDefaultModelIdentifier(): void
108108
{
109109
$this->configResolver
110110
->method('getParameter')
111111
->with('default_embedding_model')
112112
->willReturn('text-embedding-ada-002');
113113

114-
self::assertSame('text-embedding-ada-002', $this->config->getDefaultEmbeddingModelIdentifier());
114+
self::assertSame('text-embedding-ada-002', $this->config->getDefaultModelIdentifier());
115115
}
116116

117-
public function testGetDefaultEmbeddingProvider(): void
117+
public function testGetDefaultProvider(): void
118118
{
119119
$this->configResolver
120120
->method('getParameter')
@@ -123,10 +123,10 @@ public function testGetDefaultEmbeddingProvider(): void
123123
['embedding_models', null, null, self::MODELS],
124124
]);
125125

126-
self::assertSame('ibexa_openai', $this->config->getDefaultEmbeddingProvider());
126+
self::assertSame('ibexa_openai', $this->config->getDefaultProvider());
127127
}
128128

129-
public function getDefaultEmbeddingModelFieldSuffix(): void
129+
public function testGetDefaultModelFieldSuffix(): void
130130
{
131131
$this->configResolver
132132
->method('getParameter')
@@ -135,6 +135,6 @@ public function getDefaultEmbeddingModelFieldSuffix(): void
135135
['embedding_models', null, null, self::MODELS],
136136
]);
137137

138-
self::assertSame('ada002', $this->config->getDefaultEmbeddingModelFieldSuffix());
138+
self::assertSame('ada002', $this->config->getDefaultModelFieldSuffix());
139139
}
140140
}

tests/lib/Search/Embedding/EmbeddingProviderResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testResolveReturnsProviderWhenAvailable(): void
4141
$mockProvider = $this->createMock(EmbeddingProviderInterface::class);
4242

4343
$this->configuration
44-
->method('getDefaultEmbeddingProvider')
44+
->method('getDefaultProvider')
4545
->willReturn($embeddingProviderIdentifier);
4646

4747
$this->registry
@@ -64,7 +64,7 @@ public function testResolveThrowsWhenProviderMissing(): void
6464
$embeddingProviderIdentifier = 'foo';
6565

6666
$this->configuration
67-
->method('getDefaultEmbeddingProvider')
67+
->method('getDefaultProvider')
6868
->willReturn($embeddingProviderIdentifier);
6969

7070
$this->registry

0 commit comments

Comments
 (0)