2

I am currently using document inheritance to avoid having to include specific fields in every document type that I make. It works for most scenarios, but when an array of structs is inherited, using that field in ranking and searching seems to break things. For example, take the following application.

schema base {
    document base {
        field simple_base type string {
            indexing: summary | index
        }

        struct base_struct {
            field name type string {}
        }

        field complex_base type array<base_struct> {
            indexing: summary
            struct-field name { indexing: attribute }
        }
    }
}
schema sub {
    document sub inherits base {
        field simple_sub type string {
            indexing: summary | index
        }

        struct sub_struct {
            field name type string {}
        }

        field complex_sub type array<sub_struct> {
            indexing: summary
            struct-field name { indexing: attribute }
        }
    }

    rank-profile default inherits default {
        first-phase {
            expression: nativeRank(simple_sub, complex_sub.name, simple_base, complex_base.name)
        }
    }
}

If you try to prepare this application, you will get the error

WARNING: invalid rank feature 'nativeRank(simple_sub,complex_sub.name,simple_base,complex_base.name)': The parameter list used for setting up rank feature nativeRank is not valid: Param[3]: Field 'complex_base.name' was not found in the index environment

If you take out the complex_base.name from the nativeRank function, it will compile properly. Additionally if you try to search using the various fields after feeding the following json:

{
  "put": "id:content:sub::0",
  "fields": {
    "simple_base": "simple",
    "simple_sub": "simple",
    "complex_base": [
      {
        "name": "complex"
      }
    ],
    "complex_sub": [
      {
        "name": "complex"
      }
    ]
  }
}

Then the following are the results:

/search/?query=simple_sub:simple -> 1 result
/search/?query=complex_sub.name:complex -> 1 result
/search/?query=simple_base:simple -> 1 result
/search/?query=complex_base.name:complex -> 0 results

If this is the intended behavior then is there a workaround for this other than copy/pasting the complex_base field into every document that needs to inherit it? Thank you for your assistance.

Kyle Rowan
  • 87
  • 1
  • 4

1 Answers1

2

This is not related to inheritance. Vespa.ai does not support ranking for user defined struct fields. See https://github.com/vespa-engine/vespa/issues/11580.

Jo Kristian Bergum
  • 2,984
  • 5
  • 8
  • Ok thank you I'll keep that in mind for the ranking portion, but what about the searching aspect of the inheritance? In my example I show that it is possible to search based on a struct field when the struct is within the document itself, but not when it is inherited. It seems inconsistent with searching for non-struct inherited fields since as shown in the above example, I am able to search for the `simple_base` field but not in the `complex_base.name` field. – Kyle Rowan Oct 29 '20 at 08:18
  • 1
    It might be that inheritance (Which is just syntax in the document model) is badly integrated with complex structs. If you use &tracelevel=3 you can compare the execution against the backend. I'm guessing that the 0 result is that the complex_base.name is not recognized by the query parsing and you end up searching the default fieldset using 'complex base name complex'. If this is the case a github issue is welcome, or it's welcome anyway. – Jo Kristian Bergum Oct 29 '20 at 08:23
  • Ok, I'll look into what might be causing it and if it's a parsing issue I will create an issue for it. Thanks for the help! – Kyle Rowan Oct 29 '20 at 08:27