Skip to content

Commit

Permalink
Cottontail Fixes & Improvements (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanheller authored Mar 7, 2022
1 parent c1bd1ef commit fbc6c55
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ allprojects {
group = 'org.vitrivr'

/* Our current version, on dev branch this should always be release+1-SNAPSHOT */
version = '3.8.3'
version = '3.8.4'

apply plugin: 'java-library'
apply plugin: 'maven-publish'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ default <E extends DistanceElement> List<E> getNearestNeighboursGeneric(int k,
<T extends DistanceElement> List<T> getBatchedNearestNeighbours(int k, List<float[]> vectors,
String column, Class<T> distanceElementClass, List<ReadableQueryConfig> configs);

/**
* In contrast to {@link #getNearestNeighboursGeneric(int, float[], String, Class, ReadableQueryConfig)}, this method returns all elements of a row
*/
List<Map<String, PrimitiveTypeProvider>> getNearestNeighbourRows(int k, float[] vector,
String column, ReadableQueryConfig config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public <E extends DistanceElement> List<E> getBatchedNearestNeighbours(int k, Li

@Override
public List<Map<String, PrimitiveTypeProvider>> getNearestNeighbourRows(int k, float[] vector, String column, ReadableQueryConfig config) {
final Query query = knn(k, vector, column, config);
final Query query = knn(k, vector, column, config, "*");
try {
return processResults(this.cottontail.client.query(query));
} catch (StatusRuntimeException e) {
Expand Down Expand Up @@ -314,7 +314,7 @@ public List<PrimitiveTypeProvider> getUniqueValues(String column) {
}

public Map<String, Integer> countDistinctValues(String column) {
final Query query = new Query(this.fqn).select("*", null);
final Query query = new Query(this.fqn).select(column, null);
final Map<String, Integer> count = new HashMap<>();
try {
final TupleIterator results = this.cottontail.client.query(query);
Expand Down Expand Up @@ -375,14 +375,32 @@ public boolean ping() {
* @return {@link Query}
*/
private Query knn(int k, float[] vector, String column, ReadableQueryConfig config) {
return knn(k, vector, column, config, GENERIC_ID_COLUMN_QUALIFIER);
}

/**
* Creates and returns a basic {@link Query} object for the given kNN parameters.
*
* @param k The k parameter used for kNN
* @param vector The query vector (= float array).
* @param column The name of the column that should be queried.
* @param config The {@link ReadableQueryConfig} with additional parameters.
* @param select which rows should be selected
* @return {@link Query}
*/
private Query knn(int k, float[] vector, String column, ReadableQueryConfig config, String... select) {
final Set<String> relevant = config.getRelevantSegmentIds();
final Distances distance = toDistance(config.getDistance().orElse(Distance.manhattan));
final Query query = new Query(this.fqn)
.select(GENERIC_ID_COLUMN_QUALIFIER, null)
.distance(column, vector, distance, DB_DISTANCE_VALUE_QUALIFIER)
.order(DB_DISTANCE_VALUE_QUALIFIER, Direction.ASC)
.limit(k);

for (String s : select) {
query.select(s, null);
}


/* Add relevant segments (optional). */
if (!relevant.isEmpty()) {
query.where(new Literal(GENERIC_ID_COLUMN_QUALIFIER, "IN", relevant.toArray()));
Expand Down

0 comments on commit fbc6c55

Please sign in to comment.