Search code examples
vespa

Vespa DB nearestNeighbor search -- Invalid query parameter -- Expected 'query(...)' to be a tensor, but it is the string


While trying to do nearestNeighbor search on embeddings I am getting a query error, though no error logs are present in Vespa container.

Documentation link: https://docs.vespa.ai/en/nearest-neighbor-search.html#querying-using-nearestneighbor-query-operator

Request:

{
    "yql": "SELECT * FROM products WHERE ([{\"targetHits\":10, \"approximate\": true}]nearestNeighbor(text_embedding, q_embedding))",
    "ranking": {
        "profile": "default",
        "listFeatures": true,
        "features": {
            "query(q_embedding)": [
                0.06836861371994019,
                0,
                0.005350692197680473,
                0.030558381229639053,
                0,
                0.010386962443590164,
                0.03204352408647537,
                0.03281643986701965,
                0.11372111737728119,
                0.10037083923816681,
                0,
                0.10755997896194458,
                0.043405745178461075,
                0.08697208017110825,
                0,
                0.01487557403743267,
                0.017064541578292847,
                0.050060052424669266,
                0.06158211827278137,
                0,
                0,
                0,
                0.1395300030708313,
                0.040378399193286896,
                0,
                0.0265999473631382,
                0,
                0.02867511473596096,
                0,
                0,
                0,
                0.10068237036466599,
                0.041657011955976486,
                0.06862851977348328,
                0,
                0.014019965194165707,
                0,
                0,
                0,
                0,
                0.1124025359749794,
                0.06834051012992859,
                0,
                0,
                0,
                0,
                0,
                0,
                0.01853846199810505,
                0.08900538831949234,
                0.09758827835321426,
                0,
                0.08243539184331894,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0.022744037210941315,
                0.08361546695232391,
                0,
                0.03171956539154053,
                0.04051847383379936,
                0,
                0.019974248483777046,
                0,
                0,
                0,
                0,
                0,
                0,
                0.08591245859861374,
                0.08787022531032562,
                0.02056828886270523,
                0.05086769163608551,
                0,
                0.09067854285240173,
                0.024191005155444145,
                0,
                0,
                0,
                0.07980427145957947,
                0.03894811123609543,
                0,
                0.0007913131266832352,
                0,
                0.050328031182289124,
                0.015318576246500015,
                0.0427778922021389,
                0.023335546255111694,
                0.09074989706277847,
                0.014131247065961361,
                0,
                0,
                0,
                0,
                0.06538441777229309,
                0.06360842287540436,
                0,
                0,
                0,
                0.03568531945347786,
                0.060780078172683716,
                0.05406676605343819,
                0.014647044241428375,
                0.0017168920021504164,
                0,
                0,
                0,
                0.020146727561950684,
                0.01121614407747984,
                0.018305499106645584,
                0.026444928720593452,
                0.050688087940216064,
                0,
                0,
                0.0071852304972708225,
                0,
                0,
                0.040417373180389404,
                0.017755649983882904,
                0.017129860818386078,
                0.043410494923591614,
                0.02412831038236618,
                0
            ]
        }
    }
}

response:

{
    "root": {
        "id": "toplevel",
        "relevance": 1.0,
        "fields": {
            "totalCount": 0
        },
        "errors": [
            {
                "code": 4,
                "summary": "Invalid query parameter",
                "source": "products",
                "message": "Expected 'query(q_embedding)' to be a tensor, but it is the string '[\n                0.06836861371994019,\n                0,\n                0.005350692197680473,\n                0.030558381229639053,\n                0,\n                0.010386962443590164,\n                0.03204352408647537,\n                0.03281643986701965,\n                0.11372111737728119,\n                0.10037083923816681,\n                0,\n                0.10755997896194458,\n                0.043405745178461075,\n                0.08697208017110825,\n                0,\n                0.01487557403743267,\n                0.017064541578292847,\n                0.050060052424669266,\n                0.06158211827278137,\n                0,\n                0,\n                0,\n                0.1395300030708313,\n                0.040378399193286896,\n                0,\n                0.0265999473631382,\n                0,\n                0.02867511473596096,\n                0,\n                0,\n                0,\n                0.10068237036466599,\n                0.041657011955976486,\n                0.06862851977348328,\n                0,\n                0.014019965194165707,\n                0,\n                0,\n                0,\n                0,\n                0.1124025359749794,\n                0.06834051012992859,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0.01853846199810505,\n                0.08900538831949234,\n                0.09758827835321426,\n                0,\n                0.08243539184331894,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0.022744037210941315,\n                0.08361546695232391,\n                0,\n                0.03171956539154053,\n                0.04051847383379936,\n                0,\n                0.019974248483777046,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0,\n                0.08591245859861374,\n                0.08787022531032562,\n                0.02056828886270523,\n                0.05086769163608551,\n                0,\n                0.09067854285240173,\n                0.024191005155444145,\n                0,\n                0,\n                0,\n                0.07980427145957947,\n                0.03894811123609543,\n                0,\n                0.0007913131266832352,\n                0,\n                0.050328031182289124,\n                0.015318576246500015,\n                0.0427778922021389,\n                0.023335546255111694,\n                0.09074989706277847,\n                0.014131247065961361,\n                0,\n                0,\n                0,\n                0,\n                0.06538441777229309,\n                0.06360842287540436,\n                0,\n                0,\n                0,\n                0.03568531945347786,\n                0.060780078172683716,\n                0.05406676605343819,\n                0.014647044241428375,\n                0.0017168920021504164,\n                0,\n                0,\n                0,\n                0.020146727561950684,\n                0.01121614407747984,\n                0.018305499106645584,\n                0.026444928720593452,\n                0.050688087940216064,\n                0,\n                0,\n                0.0071852304972708225,\n                0,\n                0,\n                0.040417373180389404,\n                0.017755649983882904,\n                0.017129860818386078,\n                0.043410494923591614,\n                0.02412831038236618,\n                0\n            ]'"
            }
        ]
    }
}

I am expecting to get a list of documents.

schema products {
    document products {
        field id type int {
        }
        field gender type string {
            indexing: summary | attribute
        }
        field masterCategory type string {
            indexing: summary | attribute
        }
        field subCategory type string {
            indexing: summary | attribute
        }
        field articleType type string {
            indexing: summary | attribute
        }
        field baseColour type string {
            indexing: summary | attribute
        }
        field season type string {
            indexing: summary | attribute
        }
        field year type int {
            indexing: summary | attribute
        }
        field usage type string {
            indexing: summary | attribute
        }
        field productDisplayName type string {
            indexing: summary | attribute
        }
        field image type string {
            indexing: summary | attribute
        }
        field image_embedding type tensor<float>(x[128]) {
            indexing: attribute
            attribute {
                distance-metric: euclidean
            }
        }
        field text_embedding type tensor<float>(x[128]) {
            indexing: attribute
            attribute {
                distance-metric: euclidean
            }
        }
    }

    fieldset default {
        fields: id, gender, masterCategory, subCategory, articleType, baseColour, season, year, usage, productDisplayName, image, image_embedding, text_embedding
    }

    rank-profile default {
        first-phase {
            expression: closeness(field, image_embedding) + closeness(field, text_embedding)
        }
    }
}

Solution

  • You need to declare the type of your input query feature. Add this to your rank profile in your products schema:

    inputs {
        query(q_embedding) tensor(x[128])
    }