Skip to content

Commit

Permalink
HSEARCH-5021 Remove the array check from a vector DefaultInitiator
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Dec 11, 2023
1 parent ce6e483 commit ec08362
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,9 @@ class IndexedEntity {
.satisfies( FailureReportUtils.hasFailureReport()
.typeContext( IndexedEntity.class.getName() )
.pathContext( ".notVector" )
.failure(
"Unable to apply property mapping: this property mapping must target an index field of vector type",
"but the resolved field type is non-vector",
"This generally means you need to use a different field annotation"
+ " or to convert property values using a custom ValueBridge or ValueBinder",
"If you are already using a custom ValueBridge or ValueBinder, check its field type",
"encountered type DSL step '",
"expected interface '" + VectorFieldTypeOptionsStep.class.getName() + "'"
) );
// NOTE: this is an exception from the IndexFieldTypeFactory implementation, hence it is backend-specific and in this case
// it is from the stub-backend.
.failure( "No built-in vector index field type for class: 'java.lang.Integer'." ) );
}

@Test
Expand All @@ -371,14 +365,9 @@ class IndexedEntity {
.satisfies( FailureReportUtils.hasFailureReport()
.typeContext( IndexedEntity.class.getName() )
.pathContext( ".bytes" )
.failure(
"Unable to apply property mapping: this property mapping must target an index field of vector type, but the resolved field type is non-vector",
"This generally means you need to use a different field annotation"
+ " or to convert property values using a custom ValueBridge or ValueBinder",
"If you are already using a custom ValueBridge or ValueBinder, check its field type",
"encountered type DSL step '",
"expected interface '" + VectorFieldTypeOptionsStep.class.getName() + "'"
) );
// NOTE: this is an exception from the IndexFieldTypeFactory implementation, hence it is backend-specific and in this case
// it is from the stub-backend.
.failure( "No built-in vector index field type for class: 'java.lang.Integer'." ) );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ public <F> IndexFieldTypeOptionsStep<?, F> initiate(IndexFieldTypeFactory factor
if ( dimension == null ) {
throw log.vectorDimensionNotSpecified();
}
// we consider arrays (byte[] and float[] in particular to be vector types, anything else will be
// treated as a non-vector field and delegated to a regular as(..) call.
if ( clazz.isArray() ) {
return factory.asVector( dimension, clazz );
}
else {
return factory.as( clazz );
}
return factory.asVector( dimension, clazz );
}
},
FieldModelContributorContext::vectorTypeOptionsStep );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hibernate.search.engine.backend.types.dsl.VectorFieldTypeOptionsStep;
import org.hibernate.search.engine.mapper.mapping.building.spi.IndexFieldTypeDefaultsProvider;
import org.hibernate.search.engine.spatial.GeoPoint;
import org.hibernate.search.util.common.SearchException;

public class StubIndexFieldTypeFactory implements IndexFieldTypeFactory {

Expand Down Expand Up @@ -167,7 +168,7 @@ public <F> VectorFieldTypeOptionsStep<?, F> asVector(int dimension, Class<F> val
if ( float[].class.equals( valueType ) ) {
return (VectorFieldTypeOptionsStep<?, F>) asFloatVector( dimension );
}
return new StubVectorFieldTypeOptionsStep<>( dimension, valueType );
throw new SearchException( "No built-in vector index field type for class: '" + valueType.getName() + "'." );
}

@Override
Expand Down

0 comments on commit ec08362

Please sign in to comment.