Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing NearestNeighborRows only returning id column #274

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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