Skip to content

Commit

Permalink
Merge pull request #36939 from jmartisk/redis-vector-arguments
Browse files Browse the repository at this point in the history
Redis vector fields and arguments
  • Loading branch information
cescoffier authored Nov 8, 2023
2 parents 59bc85b + 53c799c commit 3d7daa8
Show file tree
Hide file tree
Showing 54 changed files with 480 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
public interface RedisCommandExtraArguments {

/**
* @return the list of arguments, encoded as a list of String.
* @return the list of arguments.
*/
default List<String> toArgs() {
default List<Object> toArgs() {
return toArgs(null);
}

/**
* @param encoder an optional encoder to encode some of the values
* @return the list of arguments, encoded as a list of String.
* @return the list of arguments.
*/
default List<String> toArgs(Codec encoder) {
default List<Object> toArgs(Codec encoder) {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public SortArgs get(String get) {
return this;
}

public List<String> toArgs() {
List<String> args = new ArrayList<>();
public List<Object> toArgs() {
List<Object> args = new ArrayList<>();
if (by != null && !by.isBlank()) {
args.add("BY");
args.add(by);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public GetArgs withScores() {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();
if (fuzzy) {
list.add("FUZZY");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public String toString() {

}

private final List<String> commands = new ArrayList<>();
private final List<Object> commands = new ArrayList<>();
private BitFieldType previousBitFieldType;

/**
Expand Down Expand Up @@ -351,7 +351,7 @@ private BitFieldType getPreviousFieldType() {
}
}

public List<String> toArgs() {
public List<Object> toArgs() {
return commands;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public BfInsertArgs expansion(int expansion) {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();

if (capacity > 0) {
list.add("CAPACITY");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public BfReserveArgs expansion(int expansion) {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();
if (expansion > 0) {
list.add("EXPANSION");
list.add(Integer.toString(expansion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public CfInsertArgs nocreate() {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();
if (capacity > 0) {
list.add("CAPACITY");
list.add(Long.toString(capacity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public CfReserveArgs expansion(int expansion) {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();
if (bucketSize > 0) {
list.add("BUCKETSIZE");
list.add(Long.toString(bucketSize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public GeoAddArgs ch() {
return this;
}

public List<String> toArgs() {
public List<Object> toArgs() {
if (xx && nx) {
throw new IllegalArgumentException("Cannot set XX and NX together");
}
List<String> args = new ArrayList<>();
List<Object> args = new ArrayList<>();
if (xx) {
args.add("XX");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public GeoRadiusArgs any() {
}

@Override
public List<String> toArgs() {
public List<Object> toArgs() {
// Validation
if (any && count == -1) {
throw new IllegalArgumentException("ANY can only be used if COUNT is also set");
}

List<String> list = new ArrayList<>();
List<Object> list = new ArrayList<>();
if (withDistance) {
list.add("WITHDIST");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public GeoRadiusStoreArgs<K> storeDistKey(K storeDistKey) {
}

@Override
public List<String> toArgs(Codec codec) {
public List<Object> toArgs(Codec codec) {
// Validation
if (any && count == -1) {
throw new IllegalArgumentException("ANY can only be used if COUNT is also set");
Expand All @@ -136,7 +136,7 @@ public List<String> toArgs(Codec codec) {
throw new IllegalArgumentException("At least `STORE` or `STOREDIST` must be set");
}

List<String> list = new ArrayList<>();
List<Object> list = new ArrayList<>();
if (withDistance) {
list.add("WITHDIST");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public GeoSearchArgs<V> any() {
}

@Override
public List<String> toArgs(Codec codec) {
public List<Object> toArgs(Codec codec) {
// Validation
if (any && count == -1) {
throw new IllegalArgumentException("ANY can only be used if COUNT is also set");
Expand All @@ -198,7 +198,7 @@ public List<String> toArgs(Codec codec) {
throw new IllegalArgumentException("FROMMEMBER and FROMLONLAT cannot be used together");
}

List<String> list = new ArrayList<>();
List<Object> list = new ArrayList<>();
if (member != null) {
list.add("FROMMEMBER");
list.add(new String(codec.encode(member), StandardCharsets.UTF_8));
Expand Down Expand Up @@ -249,7 +249,7 @@ public boolean hasCoordinates() {
return withCoordinates;
}

private void putFlag(List<String> list, boolean flag, String value) {
private void putFlag(List<Object> list, boolean flag, String value) {
if (flag) {
list.add(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public GeoSearchStoreArgs<V> any() {
}

@Override
public List<String> toArgs(Codec codec) {
public List<Object> toArgs(Codec codec) {
// Validation
if (any && count == -1) {
throw new IllegalArgumentException("ANY can only be used if COUNT is also set");
Expand All @@ -160,7 +160,7 @@ public List<String> toArgs(Codec codec) {
throw new IllegalArgumentException("FROMMEMBER and FROMLONLAT cannot be used together");
}

List<String> list = new ArrayList<>();
List<Object> list = new ArrayList<>();
if (member != null) {
list.add("FROMMEMBER");
list.add(new String(codec.encode(member), StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public JsonSetArgs xx() {
}

@Override
public List<String> toArgs() {
public List<Object> toArgs() {
if (xx && nx) {
throw new IllegalArgumentException("Cannot set XX and NX together");
}
List<String> args = new ArrayList<>();
List<Object> args = new ArrayList<>();
if (xx) {
args.add("XX");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public CopyArgs replace(boolean replace) {
}

@Override
public List<String> toArgs() {
List<String> args = new ArrayList<>();
public List<Object> toArgs() {
List<Object> args = new ArrayList<>();
if (destinationDb != -1) {
args.add("DB");
args.add(Long.toString(destinationDb));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public ExpireArgs gt() {
return this;
}

public List<String> toArgs() {
List<String> args = new ArrayList<>();
public List<Object> toArgs() {
List<Object> args = new ArrayList<>();

boolean exclusion = false;
if (nx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public LPosArgs maxlen(long max) {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();
if (rank != 0) {
list.add("RANK");
list.add(Long.toString(rank));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ public AggregateArgs cursorMaxIdleTime(Duration maxIdleDuration) {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();
if (verbatim) {
list.add("VERBATIM");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ public CreateArgs indexedField(String field, String alias, FieldType type) {
}

@Override
public List<String> toArgs() {
List<String> list = new ArrayList<>();
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();

if (onHash) {
if (onJson) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.redis.datasource.search;

/**
* Metric for computing the distance between two vectors.
*/
public enum DistanceMetric {
L2,
IP,
COSINE
}
Loading

0 comments on commit 3d7daa8

Please sign in to comment.