Skip to content

Commit

Permalink
refactor: Use FTCreateParams for ftCreate method, update Jedis consta…
Browse files Browse the repository at this point in the history
…nts for VSS
  • Loading branch information
bsbodden committed Jan 1, 2024
1 parent 63245d8 commit 1c8fd3d
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 330 deletions.
28 changes: 14 additions & 14 deletions demos/roms-vss/src/main/java/com/redis/om/vss/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -63,12 +63,12 @@ public class Product {


@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.HNSW, //
type = VectorType.FLOAT32, //
dimension = 512, //
distanceMetric = DistanceMetric.COSINE, //
initialCapacity = 10
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgorithm.HNSW, //
type = VectorType.FLOAT32, //
dimension = 512, //
distanceMetric = DistanceMetric.COSINE, //
initialCapacity = 10
)
private byte[] imageEmbedding;

Expand All @@ -77,12 +77,12 @@ public class Product {
private String imagePath;

@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.HNSW, //
type = VectorType.FLOAT32, //
dimension = 768, //
distanceMetric = DistanceMetric.COSINE, //
initialCapacity = 10
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgorithm.HNSW, //
type = VectorType.FLOAT32, //
dimension = 768, //
distanceMetric = DistanceMetric.COSINE, //
initialCapacity = 10
)
private byte[] sentenceEmbedding;

Expand All @@ -107,7 +107,7 @@ public static Product fromCSV(String line, boolean useLocalImages) {
String productDisplayName = values[9];
String imagePath = useLocalImages ? "classpath:/static/product-images/" + id + ".jpg" : values[10];
String productText = Stream.of(productDisplayName, "category", masterCategory, "subcategory", subCategory, "color", baseColour, "gender", gender).map(String::toLowerCase).collect(
Collectors.joining(" "));
Collectors.joining(" "));

Product p = Product.of(gender, masterCategory, subCategory, articleType, baseColour, season, year, usage, productDisplayName, imagePath, productText);
p.setId(id);
Expand Down
258 changes: 141 additions & 117 deletions redis-om-spring/src/main/java/com/redis/om/spring/RediSearchIndexer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public JedisConnectionFactory jedisConnectionFactory() {
sentinelConfig.setSentinels(redisNodes);

final JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMinEvictableIdleTime(Duration.ofMillis(60000));
poolConfig.setTimeBetweenEvictionRuns(Duration.ofMillis(30000));
poolConfig.setNumTestsPerEvictionRun(-1);
poolConfig.setTestWhileIdle(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.redis.om.spring.DistanceMetric;
import com.redis.om.spring.VectorType;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

import java.lang.annotation.*;

Expand Down Expand Up @@ -38,7 +38,7 @@
// -----------------

// Indexing methods
VectorAlgo algorithm() default VectorAlgo.FLAT;
VectorAlgorithm algorithm() default VectorAlgorithm.FLAT;

// Vector type. Current supported types are FLOAT32 and FLOAT64.
VectorType type() default VectorType.FLOAT32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.redis.om.spring.DistanceMetric;
import com.redis.om.spring.VectorType;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

import java.lang.annotation.*;

Expand All @@ -15,7 +15,7 @@
String alias() default "";

// Indexing methods
VectorAlgo algorithm() default VectorAlgo.FLAT;
VectorAlgorithm algorithm() default VectorAlgorithm.FLAT;

// Vector type. Current supported types are FLOAT32 and FLOAT64.
VectorType type() default VectorType.FLOAT32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private void readAssociation(String path, RedisData source, RedisPersistentEntit
* @see org.springframework.data.convert.EntityWriter#write(java.lang.Object,
* java.lang.Object) */
@Override
@SuppressWarnings({ "rawtypes" })
@SuppressWarnings({ "rawtypes", "ConstantValue" })
public void write(Object source, RedisData sink) {
if (source == null) return;

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

@Data
@RequiredArgsConstructor(staticName = "of")
Expand All @@ -24,7 +24,7 @@ public class Product {

@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.HNSW, //
algorithm = VectorAlgorithm.HNSW, //
type = VectorType.FLOAT32, //
dimension = 512, //
distanceMetric = DistanceMetric.COSINE, //
Expand All @@ -38,7 +38,7 @@ public class Product {

@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.HNSW, //
algorithm = VectorAlgorithm.HNSW, //
type = VectorType.FLOAT32, //
dimension = 768, //
distanceMetric = DistanceMetric.COSINE, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.redis.om.spring.annotations.document.fixtures.CompanyRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

@Data
@RequiredArgsConstructor(staticName = "of")
Expand All @@ -21,7 +21,7 @@ public class HashWithByteArrayFlatVector {

@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.FLAT, //
algorithm = VectorAlgorithm.FLAT, //
type = VectorType.FLOAT32, //
dimension = 100, //
distanceMetric = DistanceMetric.L2, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

@Data
@RequiredArgsConstructor(staticName = "of")
Expand All @@ -21,7 +21,7 @@ public class HashWithByteArrayHNSWVector {

@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.HNSW, //
algorithm = VectorAlgorithm.HNSW, //
type = VectorType.FLOAT32, //
dimension = 100, //
distanceMetric = DistanceMetric.L2, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

@Data
@RequiredArgsConstructor(staticName = "of")
Expand All @@ -20,18 +20,18 @@ public class HashWithVectors {
private String id;

@NonNull
@VectorIndexed(algorithm = VectorAlgo.FLAT, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
@VectorIndexed(algorithm = VectorAlgorithm.FLAT, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
private String flat;

@NonNull
@VectorIndexed(algorithm = VectorAlgo.HNSW, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
@VectorIndexed(algorithm = VectorAlgorithm.HNSW, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
private String hnsw;

@NonNull
@Indexed(schemaFieldType = SchemaFieldType.VECTOR, algorithm = VectorAlgo.FLAT, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
@Indexed(schemaFieldType = SchemaFieldType.VECTOR, algorithm = VectorAlgorithm.FLAT, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
private String flat2;

@NonNull
@Indexed(schemaFieldType = SchemaFieldType.VECTOR, algorithm = VectorAlgo.HNSW, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
@Indexed(schemaFieldType = SchemaFieldType.VECTOR, algorithm = VectorAlgorithm.HNSW, type = VectorType.FLOAT32, dimension = 2, distanceMetric = DistanceMetric.L2)
private String hnsw2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import redis.clients.jedis.search.Schema.VectorField.VectorAlgo;
import redis.clients.jedis.search.schemafields.VectorField.VectorAlgorithm;

@Data
@RequiredArgsConstructor(staticName = "of")
Expand All @@ -28,7 +28,7 @@ public class Product {

@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.HNSW, //
algorithm = VectorAlgorithm.HNSW, //
type = VectorType.FLOAT32, //
dimension = 512, //
distanceMetric = DistanceMetric.COSINE, //
Expand All @@ -42,7 +42,7 @@ public class Product {

@Indexed(//
schemaFieldType = SchemaFieldType.VECTOR, //
algorithm = VectorAlgo.HNSW, //
algorithm = VectorAlgorithm.HNSW, //
type = VectorType.FLOAT32, //
dimension = 768, //
distanceMetric = DistanceMetric.COSINE, //
Expand Down

0 comments on commit 1c8fd3d

Please sign in to comment.