Skip to content

Commit 6512ff2

Browse files
committed
Implemented reviewer comments
1 parent c12ae0e commit 6512ff2

File tree

2 files changed

+78
-43
lines changed

2 files changed

+78
-43
lines changed

docs/search/embeddings_reference/embeddings_reference.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ Embedding queries do not support criteria, Sort Clauses, facet builders, or spel
1616

1717
## Embedding
1818

19-
- [`Ibexa\Contracts\Core\Repository\Values\Content\Query\Embedding`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Query-Embedding.html): Represents the semantic input used for similarity search.
20-
Depending on the embedding provider, it can encapsulate text or vector data
19+
- [`Ibexa\Contracts\Core\Repository\Values\Content\Query\Embedding`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Query-Embedding.html): Represents the vector input used
20+
for similarity search.
21+
It stores embedding values as float arrays, while providers generate those vectors from text input
2122

2223
## Embedding providers
2324

2425
Embedding providers generate vector representations for inputs.
26+
Out of the box, embedding search integration is provided for TaxonomyEmbedding.
27+
If you use a custom embedding value type, implement matching embedding
28+
visitors for your search engine (Solr/Elasticsearch).
29+
Otherwise, query execution may fail with "No visitor available".
2530

2631
### Provider contracts
2732

docs/search/search_api.md

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ Instead of comparing keywords, the system compares vectors that represent the se
371371

372372
!!! note "Taxonomy suggestions"
373373

374-
Embedding queries have been introduced primarily to support the [Taxonomy suggestions](taxonomy.md#taxonomy-suggestions) feature but you can use them in other scenarios.
374+
Embedding queries have been introduced primarily to support the [Taxonomy suggestions](taxonomy.md#taxonomy-suggestions) feature, therefore embedding search integration is provided for `TaxonomyEmbedding`.
375+
To use them in other scenarios that use a custom embedding value type, implement matching embedding
376+
visitors for your search engine.
375377

376378
Searching with embeddings can be combined with filtering, which allows the semantic search results to be constrained by content type, location, permissions, or other criteria.
377379

@@ -387,71 +389,99 @@ The following components are used to build and validate embedding-based queries:
387389

388390
- [EmbeddingQueryBuilder](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-EmbeddingQueryBuilder.html):
389391
A fluent builder for constructing `EmbeddingQuery` instances.
390-
It enforces required parameters and integrates embedding queries with the search query pipeline
392+
It helps construct queries consistently and integrates embedding queries with the search query pipeline, but you must still provide the required embedding value
391393

392394
- [QueryValidatorInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-QueryValidatorInterface.html):
393-
Validates embedding queries before they are passed to the search engine.
394-
Implementations ensure that the embedding model exists and that vector dimensions match the configured embedding field
395+
Validates embedding query structure before execution.
396+
The provider/model configuration and vector compatibility are resolved at runtime by the configured embedding and search engine component
395397

396398
### Use embedding queries in search
397399

398400
Embedding queries are executed through the search API in the same way as other search requests.
399401
You build an `EmbeddingQuery` instance by using a builder and pass it to the search service.
400402
Embedding queries can also be combined with filters to narrow down results, such as by content type, location, or permissions.
401403

404+
This example shows a minimal embedding query executed directly through the search service:
405+
402406
``` php
407+
<?php
408+
409+
declare(strict_types=1);
410+
411+
use Ibexa\Contracts\Core\Repository\Repository;
403412
use Ibexa\Contracts\Core\Repository\Values\Content\EmbeddingQueryBuilder;
404413
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier;
405414
use Ibexa\Contracts\Taxonomy\Search\Query\Value\TaxonomyEmbedding;
406415

416+
/** @var Repository $repository */
417+
$searchService = $repository->getSearchService();
418+
419+
// Example of a vector generated by an embedding provider
407420
$vector = [
408-
0.0123,
409-
-0.9876,
410-
0.4567,
411-
...
421+
0.0123,
422+
-0.9876,
423+
0.4567,
424+
// ...
412425
];
413426

414-
$embedding = new TaxonomyEmbedding($vector);
427+
$query = EmbeddingQueryBuilder::create()
428+
->withEmbedding(new TaxonomyEmbedding($vector))
429+
->setFilter(new ContentTypeIdentifier('article'))
430+
->setLimit(10)
431+
->setOffset(0)
432+
->setPerformCount(true)
433+
->build();
434+
435+
$result = $searchService->findContent($query);
436+
437+
foreach ($result->searchHits as $hit) {
438+
// Handle result
439+
}
440+
```
441+
442+
This example shows how to encapsulate an embedding query inside a reusable service class:
443+
444+
``` php
445+
<?php
446+
447+
declare(strict_types=1);
415448

416-
$embeddingQuery = EmbeddingQueryBuilder::create()
417-
->withEmbedding($embedding)
418-
->setFilter(new ContentTypeIdentifier('article'))
419-
->setLimit(10)
420-
->setOffset(0)
421-
->setPerformCount(true)
422-
->build();
449+
namespace App\Service;
423450

424-
// Execute the query via the repository
425451
use Ibexa\Contracts\Core\Repository\Repository;
426452
use Ibexa\Contracts\Core\Repository\SearchService;
427453
use Ibexa\Contracts\Core\Repository\Values\Content\EmbeddingQueryBuilder;
454+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier;
428455
use Ibexa\Contracts\Taxonomy\Search\Query\Value\TaxonomyEmbedding;
429456

430457
final class ExampleService
431-
{
432-
private SearchService $searchService;
433-
434-
public function __construct(Repository $repository)
435-
{
436-
$this->searchService = $repository->getSearchService();
437-
}
438-
439-
public function searchByEmbedding(array $vector): void
440-
{
441-
$query = EmbeddingQueryBuilder::create()
442-
->withEmbedding(new TaxonomyEmbedding($vector))
443-
->setLimit(10)
444-
->setOffset(0)
445-
->build();
446-
447-
$result = $this->searchService->findContent($query);
448-
449-
foreach ($result->searchHits as $hit) {
450-
// ...
451-
}
452-
}
453-
}
454-
458+
{
459+
private SearchService $searchService;
460+
461+
public function __construct(Repository $repository)
462+
{
463+
$this->searchService = $repository->getSearchService();
464+
}
465+
466+
/**
467+
* @param float[] $vector
468+
*/
469+
public function searchByEmbedding(array $vector): void
470+
{
471+
$query = EmbeddingQueryBuilder::create()
472+
->withEmbedding(new TaxonomyEmbedding($vector))
473+
->setFilter(new ContentTypeIdentifier('article'))
474+
->setLimit(10)
475+
->setOffset(0)
476+
->build();
477+
478+
$result = $this->searchService->findContent($query);
479+
480+
foreach ($result->searchHits as $hit) {
481+
// Handle result
482+
}
483+
}
484+
}
455485
```
456486

457487
The `EmbeddingQueryBuilder` ensures that the query is correctly configured before execution.

0 commit comments

Comments
 (0)