aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/derived/NearestNeighborTestCase.java
blob: 713da6f5cbe28df3f800fa549c5fde8247585e7d (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.derived;

import com.yahoo.component.ComponentId;
import com.yahoo.search.Query;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.schema.parser.ParseException;
import com.yahoo.vespa.model.container.search.QueryProfiles;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class NearestNeighborTestCase extends AbstractExportingTestCase {

    @Test
    void testNearestNeighbor() throws IOException, ParseException {
        try {
            ComponentId.resetGlobalCountersForTests();
            DerivedConfiguration c = assertCorrectDeriving("nearestneighbor");

            CompiledQueryProfileRegistry queryProfiles = CompiledQueryProfileRegistry.fromConfig(new QueryProfiles(c.getQueryProfiles(), (level, message) -> {
            }).getConfig());
            Query q = new Query("?ranking.features.query(q_vec)=[1,2,3,4,5,6]", // length is 6, not 5
                    queryProfiles.getComponent("default"));
            fail("This should fail when q_vec is parsed as a tensor");
        } catch (IllegalArgumentException e) {
            // success
            assertEquals("Could not set 'ranking.features.query(q_vec)' to '[1,2,3,4,5,6]'", e.getMessage());
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Test
    void test_nearest_neighbor_streaming() throws IOException, ParseException {
        assertCorrectDeriving("nearestneighbor_streaming");
    }

}