Skip to content

Commit

Permalink
Forbid ANN options in SAI (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelapena committed Jan 24, 2025
1 parent d915bae commit fbc3e21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.apache.cassandra.dht.OrderPreservingPartitioner;
import org.apache.cassandra.dht.RandomPartitioner;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.index.ANNOptions;
import org.apache.cassandra.index.Index;
import org.apache.cassandra.index.IndexBuildDecider;
import org.apache.cassandra.index.IndexRegistry;
Expand Down Expand Up @@ -700,6 +701,10 @@ public void validate(ReadCommand command) throws InvalidRequestException
throw new InvalidRequestException(String.format("SAI based ORDER BY clause requires a LIMIT that is not greater than %s. LIMIT was %s",
MAX_TOP_K, command.limits().isUnlimited() ? "NO LIMIT" : command.limits().count()));

ANNOptions annOptions = command.rowFilter().annOptions;
if (annOptions != ANNOptions.NONE)
throw new InvalidRequestException("SAI doesn't support ANN options yet.");

indexContext.validate(command.rowFilter());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.apache.cassandra.schema.TableMetadata;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Throwables;
import org.assertj.core.api.Assertions;
import org.mockito.Mockito;

import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -1619,4 +1620,18 @@ public void shouldRejectLargeVector()
// "exceeding the max vector term size of 16.000KiB. " +
// "That sets an implicit limit of 4096 dimensions for float vectors.");
}

@Test
public void shouldRejectANNOptions()
{
createTable("CREATE TABLE %s (k int PRIMARY KEY, v vector<float, 1>)");
createIndex("CREATE CUSTOM INDEX ON %s(v) USING 'StorageAttachedIndex' " +
"WITH OPTIONS = {'similarity_function' : 'euclidean'}");
Assertions.assertThatThrownBy(() -> execute("SELECT * FROM %s " +
"ORDER BY v ANN OF [1.0] " +
"LIMIT 10 " +
"WITH ann_options = {'rerank_k': 10}"))
.isInstanceOf(InvalidRequestException.class)
.hasMessageContaining("SAI doesn't support ANN options yet.");
}
}

0 comments on commit fbc3e21

Please sign in to comment.