Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
11 changes: 11 additions & 0 deletions code_samples/api/public_php_api/src/embedding_fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php declare(strict_types=1);

// Create an embedding field using the default embedding provider (type derived from configuration's field suffix)

/** @var Ibexa\Contracts\Core\Search\FieldType\EmbeddingFieldFactory $factory */
$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"
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private function getCustomLimitationValue(): bool
return $customLimitationValues['value'] ?? false;
}

#[\Override]
public function performAccessCheck(): void
{
$this->traitPerformAccessCheck();
Expand Down
14 changes: 1 addition & 13 deletions docs/search/search_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Loading