-
Notifications
You must be signed in to change notification settings - Fork 5
IBX-9846: Added embedding visitor to allow search by embeddings #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mikadamczyk
wants to merge
2
commits into
4.6
Choose a base branch
from
taxonomy-suggestions
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace Ibexa\Contracts\Solr\Query; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Embedding; | ||
|
||
abstract class EmbeddingVisitor | ||
{ | ||
abstract public function canVisit(Embedding $embedding): bool; | ||
|
||
abstract public function visit(Embedding $embedding, int $limit): string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace Ibexa\Solr\Query\Common\EmbeddingVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Embedding; | ||
use Ibexa\Contracts\Solr\Query\EmbeddingVisitor; | ||
|
||
class Aggregate extends EmbeddingVisitor | ||
{ | ||
/** | ||
* @var iterable<\Ibexa\Contracts\Solr\Query\EmbeddingVisitor> | ||
*/ | ||
protected iterable $visitors = []; | ||
|
||
/** | ||
* @param \Ibexa\Contracts\Solr\Query\EmbeddingVisitor[] $visitors | ||
*/ | ||
public function __construct(iterable $visitors = []) | ||
{ | ||
$this->visitors = $visitors; | ||
} | ||
|
||
public function canVisit(Embedding $embedding): bool | ||
{ | ||
return $this->findVisitor($embedding) !== null; | ||
} | ||
|
||
/** | ||
* Map field value to a proper Solr representation. | ||
* | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException | ||
*/ | ||
public function visit(Embedding $embedding, int $limit): string | ||
{ | ||
foreach ($this->visitors as $visitor) { | ||
if ($visitor->canVisit($embedding)) { | ||
return $visitor->visit($embedding, $limit); | ||
} | ||
} | ||
|
||
throw new NotImplementedException('No visitor available for: ' . \get_class($embedding)); | ||
} | ||
|
||
private function findVisitor(Embedding $embedding): ?EmbeddingVisitor | ||
{ | ||
foreach ($this->visitors as $visitor) { | ||
if ($visitor->canVisit($embedding)) { | ||
return $visitor; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE schema [ | ||
<!ENTITY langfields SYSTEM "language-fieldtypes.xml"> | ||
<!ENTITY customfields SYSTEM "custom-fields-types.xml"> | ||
]> | ||
<!-- | ||
This is the Solr schema file. This file should be named "schema.xml" and should | ||
be in the conf directory under the solr home (i.e. ./solr/conf/schema.xml by | ||
default) or located where the classloader for the Solr webapp can find it. | ||
|
||
It provides the default types and definitions for a functional Solr based | ||
search in eZ Publish 5. You may extend it with your own definitions, but you | ||
should not remove or drastically change the existing definitions. | ||
--> | ||
|
||
<schema name="eZ Publish 5 base schema" version="1.5"> | ||
<!-- | ||
language specific field types are included here, there should be at least | ||
a field type with the name "text" be defined" | ||
Included in the eZ platform distribution are configurations for various | ||
languages, including additional files like stopwords or other features | ||
under the directory "solr.languages" | ||
--> | ||
&langfields; | ||
|
||
<!-- | ||
custom field types and fields are included from a separate file to ease upgrades | ||
--> | ||
&customfields; | ||
|
||
<!-- | ||
Default types by Solr. Will be reused for dynamic fields. | ||
--> | ||
<fieldType name="string" class="solr.TextField" sortMissingLast="true"> | ||
<analyzer type="index"> | ||
<tokenizer class="solr.KeywordTokenizerFactory"/> | ||
<filter class="solr.LowerCaseFilterFactory"/> | ||
</analyzer> | ||
<analyzer type="query"> | ||
<tokenizer class="solr.KeywordTokenizerFactory"/> | ||
<filter class="solr.LowerCaseFilterFactory"/> | ||
</analyzer> | ||
</fieldType> | ||
|
||
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100" multiValued="true" sortMissingLast="true"> | ||
<analyzer type="index"> | ||
<tokenizer class="solr.KeywordTokenizerFactory"/> | ||
<filter class="solr.LowerCaseFilterFactory"/> | ||
</analyzer> | ||
<analyzer type="query"> | ||
<tokenizer class="solr.KeywordTokenizerFactory"/> | ||
<filter class="solr.LowerCaseFilterFactory"/> | ||
</analyzer> | ||
</fieldType> | ||
|
||
<fieldType name="pdate" class="solr.DatePointField" docValues="true"/> | ||
<fieldType name="pdates" class="solr.DatePointField" docValues="true" multiValued="true"/> | ||
<!-- | ||
Numeric field types that index values using KD-trees. | ||
Point fields don't support FieldCache, so they must have docValues="true" if needed for sorting, faceting, functions, etc. | ||
--> | ||
<fieldType name="pint" class="solr.IntPointField" docValues="true"/> | ||
<fieldType name="pfloat" class="solr.FloatPointField" docValues="true"/> | ||
<fieldType name="plong" class="solr.LongPointField" docValues="true"/> | ||
<fieldType name="pdouble" class="solr.DoublePointField" docValues="true"/> | ||
|
||
<fieldType name="pints" class="solr.IntPointField" docValues="true" multiValued="true"/> | ||
<fieldType name="pfloats" class="solr.FloatPointField" docValues="true" multiValued="true"/> | ||
<fieldType name="plongs" class="solr.LongPointField" docValues="true" multiValued="true"/> | ||
<fieldType name="pdoubles" class="solr.DoublePointField" docValues="true" multiValued="true"/> | ||
<fieldType name="random" class="solr.RandomSortField" indexed="true"/> | ||
|
||
<fieldType name="identifier" class="solr.StrField" sortMissingLast="true" /> | ||
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" multiValued="false"/> | ||
<fieldType name="booleans" class="solr.BoolField" sortMissingLast="true" multiValued="true"/> | ||
<fieldtype name="binary" class="solr.BinaryField"/> | ||
<fieldType name="int" class="solr.IntPointField" docValues="true"/> | ||
<fieldType name="float" class="solr.FloatPointField" docValues="true"/> | ||
<fieldType name="long" class="solr.LongPointField" docValues="true"/> | ||
<fieldType name="double" class="solr.DoublePointField" docValues="true"/> | ||
<fieldType name="date" class="solr.DatePointField" docValues="true"/> | ||
|
||
<fieldtype name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" /> | ||
<fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/> | ||
<fieldType name="location" class="solr.LatLonPointSpatialField" sortMissingLast="true"/> | ||
|
||
<!-- for 1536-dim models (ada-002 & 3-small) --> | ||
<fieldType name="vector_1536" | ||
class="solr.DenseVectorField" | ||
vectorDimension="1536" | ||
similarityFunction="cosine" | ||
indexed="true" | ||
stored="true" /> | ||
|
||
<!-- for the 3072-dim model (3-large) --> | ||
<fieldType name="vector_3072" | ||
class="solr.DenseVectorField" | ||
vectorDimension="3072" | ||
similarityFunction="cosine" | ||
indexed="true" | ||
stored="true"/> | ||
|
||
<!-- | ||
Required ID field. | ||
--> | ||
<field name="id" type="string" indexed="true" stored="true" required="true"/> | ||
|
||
<!-- | ||
Always contains the date a document was added to the index. Might be | ||
useful. | ||
--> | ||
<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/> | ||
|
||
<!-- | ||
Points to the root document of a block of nested documents. Required for nested document support. | ||
--> | ||
<field name="_root_" type="string" indexed="true" stored="true" required="false"/> | ||
|
||
<field name="document_type_id" type="string" indexed="true" stored="true" required="true"/> | ||
|
||
<!-- | ||
Dynamic field definitions. If a field name is not found, dynamicFields | ||
will be used if the name matches any of the patterns. RESTRICTION: the | ||
glob-like pattern in the name attribute must have a "*" only at the start | ||
or the end. EXAMPLE: name="*_i" will match any field ending in _i (like | ||
myid_i, z_i) Longer patterns will be matched first. if equal size | ||
patterns both match, the first appearing in the schema will be used. | ||
--> | ||
<dynamicField name="*_i" type="int" indexed="true" stored="true"/> | ||
<dynamicField name="*_mi" type="int" indexed="true" stored="true" multiValued="true"/> | ||
<dynamicField name="*_id" type="identifier" indexed="true" stored="true"/> | ||
<dynamicField name="*_mid" type="identifier" indexed="true" stored="true" multiValued="true"/> | ||
<dynamicField name="*_s" type="string" indexed="true" stored="true"/> | ||
<dynamicField name="*_ms" type="string" indexed="true" stored="true" multiValued="true"/> | ||
<dynamicField name="*_l" type="long" indexed="true" stored="true"/> | ||
<dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true" omitNorms="false"/> | ||
<dynamicField name="*_b" type="boolean" indexed="true" stored="true"/> | ||
<dynamicField name="*_mb" type="boolean" indexed="true" stored="true" multiValued="true"/> | ||
<dynamicField name="*_f" type="float" indexed="true" stored="true"/> | ||
<dynamicField name="*_d" type="double" indexed="true" stored="true"/> | ||
<dynamicField name="*_dt" type="date" indexed="true" stored="true"/> | ||
<dynamicField name="*_gl" type="location" indexed="true" stored="true"/> | ||
<dynamicField name="*_gl_0_coordinate" type="double" indexed="true" stored="true"/> | ||
<dynamicField name="*_gl_1_coordinate" type="double" indexed="true" stored="true"/> | ||
|
||
<!-- | ||
This field is required to allow random sorting | ||
--> | ||
<dynamicField name="random*" type="random" indexed="true" stored="false"/> | ||
|
||
<!-- | ||
This field is required for Embeddings | ||
--> | ||
<!-- 1536-dim suffix for ada-002 --> | ||
<dynamicField name="*_ada002_dv" type="vector_1536"/> | ||
|
||
<!-- 1536-dim suffix for 3-small --> | ||
<dynamicField name="*_3small_dv" type="vector_1536"/> | ||
|
||
<!-- 3072-dim suffix for 3-large --> | ||
<dynamicField name="*_3large_dv" type="vector_3072"/> | ||
|
||
<!-- | ||
This field is required since Solr 4 | ||
--> | ||
<field name="_version_" type="long" indexed="true" stored="true" multiValued="false" /> | ||
|
||
<uniqueKey>id</uniqueKey> | ||
</schema> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.