diff --git a/code_samples/api/public_php_api/src/Command/FindByTaxonomyEmbeddingCommand.php b/code_samples/api/public_php_api/src/Command/FindByTaxonomyEmbeddingCommand.php index bee4713486..d7b29e1be9 100644 --- a/code_samples/api/public_php_api/src/Command/FindByTaxonomyEmbeddingCommand.php +++ b/code_samples/api/public_php_api/src/Command/FindByTaxonomyEmbeddingCommand.php @@ -12,6 +12,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\EmbeddingQueryBuilder; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier; use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; +use Ibexa\Contracts\Core\Search\Embedding\EmbeddingProviderResolverInterface; use Ibexa\Contracts\Taxonomy\Search\Query\Value\TaxonomyEmbedding; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -25,8 +26,10 @@ )] final class FindByTaxonomyEmbeddingCommand extends Command { - public function __construct(private readonly SearchService $searchService) - { + public function __construct( + private readonly SearchService $searchService, + private readonly EmbeddingProviderResolverInterface $embeddingProviderResolver, + ) { parent::__construct(); } @@ -37,7 +40,7 @@ protected function execute( $io = new SymfonyStyle($input, $output); // Example embedding vector. - // In a real-life scenario, generate it with an embedding provider + // In a real-life scenario, generate it with an embedding provider as shown below // and make sure its dimensions match the configured model. $vector = [ 0.0123, @@ -46,8 +49,11 @@ protected function execute( 0.1111, ]; + $embeddingProvider = $this->embeddingProviderResolver->resolve(); + $embedding = $embeddingProvider->getEmbedding('example_content'); + $query = EmbeddingQueryBuilder::create() - ->withEmbedding(new TaxonomyEmbedding($vector)) + ->withEmbedding(new TaxonomyEmbedding($embedding)) ->setFilter(new ContentTypeIdentifier('article')) ->setLimit(10) ->setOffset(0) diff --git a/code_samples/api/public_php_api/src/Service/TaxonomyEmbeddingSearchService.php b/code_samples/api/public_php_api/src/Service/TaxonomyEmbeddingSearchService.php index 6a464c8f20..1f2d4ee521 100644 --- a/code_samples/api/public_php_api/src/Service/TaxonomyEmbeddingSearchService.php +++ b/code_samples/api/public_php_api/src/Service/TaxonomyEmbeddingSearchService.php @@ -14,9 +14,9 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult; use Ibexa\Contracts\Taxonomy\Search\Query\Value\TaxonomyEmbedding; -final class TaxonomyEmbeddingSearchService +final readonly class TaxonomyEmbeddingSearchService { - public function __construct(private readonly SearchService $searchService) + public function __construct(private SearchService $searchService) { } diff --git a/code_samples/api/public_php_api/src/embedding_fields.php b/code_samples/api/public_php_api/src/embedding_fields.php new file mode 100644 index 0000000000..6276bab30e --- /dev/null +++ b/code_samples/api/public_php_api/src/embedding_fields.php @@ -0,0 +1,11 @@ +create(); +echo $embeddingField->getType(); // for example, "ibexa_dense_vector_model_123" + +// Create a custom embedding field with a specific type +$customField = $factory->create('custom_embedding_type'); +echo $customField->getType(); // "custom_embedding_type" diff --git a/code_samples/back_office/limitation/src/Controller/CustomController.php b/code_samples/back_office/limitation/src/Controller/CustomController.php index 8806f635c9..4e60672cf5 100644 --- a/code_samples/back_office/limitation/src/Controller/CustomController.php +++ b/code_samples/back_office/limitation/src/Controller/CustomController.php @@ -52,6 +52,7 @@ private function getCustomLimitationValue(): bool return $customLimitationValues['value'] ?? false; } + #[\Override] public function performAccessCheck(): void { $this->traitPerformAccessCheck(); diff --git a/docs/search/search_api.md b/docs/search/search_api.md index ebfac7419b..72e3f117e6 100644 --- a/docs/search/search_api.md +++ b/docs/search/search_api.md @@ -465,19 +465,7 @@ Embedding vectors are stored in dedicated search fields that are created by `Ibe These fields are then used by the search engine to perform vector similarity comparisons when embedding queries are executed. ``` php -use Ibexa\Contracts\Core\Search\FieldType\EmbeddingFieldFactory; -use Ibexa\Contracts\Core\Search\Embedding\EmbeddingConfigurationInterface; - -// $config is an existing EmbeddingConfigurationInterface -$factory = new EmbeddingFieldFactory($config); - -// Create a default embedding field (type derived from config suffix) -$embeddingField = $factory->create(); -echo $embeddingField->getType(); // for example, "ibexa_dense_vector_model_123" - -// Create a custom embedding field with a specific type -$customField = $factory->create('custom_embedding_type'); -echo $customField->getType(); // "custom_embedding_type" +[[= include_file('code_samples/api/public_php_api/src/embedding_fields.php') =]] ``` For more information, see [Embeddings reference](embeddings_reference.md).