Package com.hazelcast.vector.jet
Class VectorTransforms
java.lang.Object
com.hazelcast.vector.jet.VectorTransforms
Transforms allowing to execute similarity search in Jet pipeline to enrich the stream.
Example usage:
StreamStage<String> inputStage = createInputStage();
StreamStage<String> outputStage = inputStage.apply(
mapUsingVectorSearch(collectionName,
// search options template
SearchOptions.of(new float[]{0}, 1, true, false),
// extract vector from the item
item -> item.getVector(),
// use results to enrich the item or replace it
(item, results) -> Map.entry(item, results)
));
With batch stages, mapUsingVectorSearchBatch(java.lang.String, com.hazelcast.vector.SearchOptions, com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues>, com.hazelcast.function.BiFunctionEx<T, com.hazelcast.vector.SearchResults<K, V>, R>)
has to be used instead mapUsingVectorSearch(java.lang.String, com.hazelcast.vector.SearchOptions, com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues>, com.hazelcast.function.BiFunctionEx<T, com.hazelcast.vector.SearchResults<K, V>, R>)
.- Since:
- 5.5
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
K, V, R> com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.StreamStage<T>, com.hazelcast.jet.pipeline.StreamStage<R>> mapUsingVectorSearch
(VectorCollection<K, V> collection, com.hazelcast.vector.SearchOptions options, com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for streaming pipelines.static <T,
K, V, R> com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.StreamStage<T>, com.hazelcast.jet.pipeline.StreamStage<R>> mapUsingVectorSearch
(String collectionName, com.hazelcast.vector.SearchOptions options, com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for streaming pipelines.static <T,
K, V, R> com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.BatchStage<T>, com.hazelcast.jet.pipeline.BatchStage<R>> mapUsingVectorSearchBatch
(VectorCollection<K, V> collection, com.hazelcast.vector.SearchOptions options, com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for batch pipelines.static <T,
K, V, R> com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.BatchStage<T>, com.hazelcast.jet.pipeline.BatchStage<R>> mapUsingVectorSearchBatch
(String collectionName, com.hazelcast.vector.SearchOptions options, com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for batch pipelines.
-
Method Details
-
mapUsingVectorSearch
@Nonnull public static <T,K, com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.StreamStage<T>,V, R> com.hazelcast.jet.pipeline.StreamStage<R>> mapUsingVectorSearch(@Nonnull String collectionName, @Nonnull com.hazelcast.vector.SearchOptions options, @Nonnull com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, @Nonnull com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for streaming pipelines.- Type Parameters:
T
- type of incoming stream itemK
- type of vector collection keyV
- type of vector collection valueR
- type of produced stream item- Parameters:
collectionName
- vector collection nameoptions
- search options prototype (vectors will be supplied for each item)toVectorFn
- function that extracts the vectors from the stream item. It must be stateless and cooperativeresultFn
- function that aggregates original item and search results. Search results are never null but may be empty. It must be stateless and cooperative- Returns:
- the newly attached stage
-
mapUsingVectorSearch
@Nonnull public static <T,K, com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.StreamStage<T>,V, R> com.hazelcast.jet.pipeline.StreamStage<R>> mapUsingVectorSearch(@Nonnull VectorCollection<K, V> collection, @Nonnull com.hazelcast.vector.SearchOptions options, @Nonnull com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, @Nonnull com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for streaming pipelines.- Type Parameters:
T
- type of incoming stream itemK
- type of vector collection keyV
- type of vector collection valueR
- type of produced stream item- Parameters:
collection
- vector collectionoptions
- search options prototype (vectors will be supplied for each item)toVectorFn
- function that extracts the vectors from the stream item. It must be stateless and cooperativeresultFn
- function that aggregates original item and search results. Search results are never null but may be empty. It must be stateless and cooperative- Returns:
- the newly attached stage
-
mapUsingVectorSearchBatch
@Nonnull public static <T,K, com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.BatchStage<T>,V, R> com.hazelcast.jet.pipeline.BatchStage<R>> mapUsingVectorSearchBatch(@Nonnull String collectionName, @Nonnull com.hazelcast.vector.SearchOptions options, @Nonnull com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, @Nonnull com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for batch pipelines.- Type Parameters:
T
- type of incoming stream itemK
- type of vector collection keyV
- type of vector collection valueR
- type of produced stream item- Parameters:
collectionName
- vector collection nameoptions
- search options prototype (vectors will be supplied for each item)toVectorFn
- function that extracts the vectors from the stream item. It must be stateless and cooperativeresultFn
- function that aggregates original item and search results. Search results are never null but may be empty. It must be stateless and cooperative- Returns:
- the newly attached stage
-
mapUsingVectorSearchBatch
@Nonnull public static <T,K, com.hazelcast.function.FunctionEx<com.hazelcast.jet.pipeline.BatchStage<T>,V, R> com.hazelcast.jet.pipeline.BatchStage<R>> mapUsingVectorSearchBatch(@Nonnull VectorCollection<K, V> collection, @Nonnull com.hazelcast.vector.SearchOptions options, @Nonnull com.hazelcast.function.FunctionEx<T, com.hazelcast.vector.VectorValues> toVectorFn, @Nonnull com.hazelcast.function.BiFunctionEx<T, SearchResults<K, V>, R> resultFn) A stage-transforming method that adds similarity search pipeline stage for batch pipelines.- Type Parameters:
T
- type of incoming stream itemK
- type of vector collection keyV
- type of vector collection valueR
- type of produced stream item- Parameters:
collection
- vector collectionoptions
- search options prototype (vectors will be supplied for each item)toVectorFn
- function that extracts the vectors from the stream item. It must be stateless and cooperativeresultFn
- function that aggregates original item and search results. Search results are never null but may be empty. It must be stateless and cooperative- Returns:
- the newly attached stage
-