Skip to content

Commit

Permalink
fixes #1700 default limit for ANN find now 1k (#1706)
Browse files Browse the repository at this point in the history
  • Loading branch information
amorton authored Nov 13, 2024
1 parent 25c0998 commit cb83b97
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ protected void logStatement(Logger logger, String prefix, SimpleStatement statem
var floatPos = start;
for (int i = 0; i < 5; i++) {
var nextPos = cql.indexOf(",", floatPos + 1, end);
System.out.println(nextPos);
if (nextPos > -1) {
floatPos = nextPos;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ public interface OrderByCqlClause extends Function<Select, Select>, CQLClause {
default boolean fullyCoversCommand() {
return false;
}

/**
* Called to get the default limit for the query when using this order by.
*
* <p>ANN order by has a different default that regular queries to limit the number of rows in
* consideration.
*
* @return Default returns {@link Integer#MAX_VALUE} so queries can read all the rows in the
* table.
*/
default Integer getDefaultLimit() {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public class TableOrderByANNCqlClause implements OrderByCqlClause {

private final ApiColumnDef apiColumnDef;
private final CqlVector<Float> vector;
private final Integer defaultLimit;

public TableOrderByANNCqlClause(ApiColumnDef apiColumnDef, CqlVector<Float> vector) {
public TableOrderByANNCqlClause(
ApiColumnDef apiColumnDef, CqlVector<Float> vector, Integer defaultLimit) {
this.apiColumnDef = Objects.requireNonNull(apiColumnDef, "apiColumnDef must not be null");
this.vector = Objects.requireNonNull(vector, "vector must not be null");

this.defaultLimit = Objects.requireNonNull(defaultLimit, "defaultLimit must not be null");
// sanity check
if (apiColumnDef.type().typeName() != ApiTypeName.VECTOR) {
throw new IllegalArgumentException(
Expand All @@ -38,4 +40,9 @@ public Select apply(Select select) {
public boolean fullyCoversCommand() {
return true;
}

@Override
public Integer getDefaultLimit() {
return defaultLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected GenericOperation<TableSchemaObject, ReadAttempt<TableSchemaObject>> bu

// if the user did not provide a limit,we read all the possible rows. Paging is then handled
// by the driver pagination
int commandLimit = command.limit().orElseGet(() -> Integer.MAX_VALUE);
int commandLimit =
command.limit().orElseGet(() -> orderByWithWarnings.target().getDefaultLimit());

int commandSkip = command.skip().orElse(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ private WithWarnings<OrderByCqlClause> resolveVectorSort(
"Vector sorting on column {}", cqlIdentifierToMessageString(vectorSortColumn.name()));
var cqlVector = CqlVectorUtil.floatsToCqlVector(vectorSortExpression.vector());
return WithWarnings.of(
new TableOrderByANNCqlClause(vectorSortColumn, cqlVector),
new TableOrderByANNCqlClause(
vectorSortColumn,
cqlVector,
commandContext.getConfig(OperationsConfig.class).maxVectorSearchLimit()),
List.of(WarningException.Code.ZERO_FILTER_OPERATIONS));
}

Expand Down

0 comments on commit cb83b97

Please sign in to comment.