blob: 1ae7f5cdfde0f39d892659768caed34fd2db5b77 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.client.dsl;
public class NearestNeighbor extends QueryChain {
private final String docVectorName;
private final String queryVectorName;
private Annotation annotation;
public NearestNeighbor(String docVectorName, String queryVectorName) {
this.docVectorName = docVectorName;
this.queryVectorName = queryVectorName;
this.nonEmpty = true;
}
NearestNeighbor annotate(Annotation annotation) {
this.annotation = annotation;
return this;
}
@Override
boolean hasPositiveSearchField(String fieldName) {
return this.docVectorName.equals(fieldName);
}
@Override
boolean hasPositiveSearchField(String fieldName, Object value) {
return this.docVectorName.equals(fieldName) && queryVectorName.equals(value);
}
@Override
boolean hasNegativeSearchField(String fieldName) {
return false;
}
@Override
boolean hasNegativeSearchField(String fieldName, Object value) {
return false;
}
@Override
public String toString() {
boolean hasAnnotation = A.hasAnnotation(annotation);
if (!hasAnnotation || !annotation.contains("targetHits")) {
throw new IllegalArgumentException("must specify target hits in nearest neighbor query");
}
String s = Text.format("nearestNeighbor(%s, %s)", docVectorName, queryVectorName);
return Text.format("([%s]%s)", annotation, s);
}
}
|