"Sets are not compatible."

Hi all,

has anyone come across an “invalid argument” error similar to the below:

Error: [
  {
"position": [
  "intersection"
],
"code": "invalid argument",
"description": "Sets are not compatible."
  }
]

The call I was running was looking for the Intersection of two indexes of the same collection as below:

   Intersection(
      Match(Index(Concat(["sortRecipeByRelevanceFor", "ujyvsaqlwg"]))),
      Match(Index("findRecipeByAllergen"), "egg")
    )

Indexes are defined and evaluated accordingly:
Index #1

{
  name: "sortRecipeByRelevanceForujyvsaqlwg",
  serialized: true,
  source: "Recipe",
  values: [
    {
      binding: "sort_result",
      reverse: true
    },
    {
      field: ["data", "recipe_processed"]
    },
    {
      field: ["data", "title"]
    },
    {
      field: ["data", "url"]
    },
    {
      field: ["data", "image"]
    },
    {
      field: ["data", "diet"]
    },
    {
      field: ["data", "contributor"]
    },
    {
      field: ["data", "allergens"]
    },
    {
      field: ["data", "potential_allergens"]
    },
    {
      field: ["ref"]
    }
  ]
}

Match(Index(Concat(["sortRecipeByRelevanceFor", "ujyvsaqlwg"])))

{
  "@set": {
    match: Index("sortRecipeByRelevanceForujyvsaqlwg")
  }
}

Index #2

{
  name: "findRecipeByAllergen",
  unique: false,
  serialized: true,
  source: "Recipe",
  terms: [
    {
      field: ["data", "allergens"]
    }
  ]
}

Match(Index("findRecipeByAllergen"), "egg")

{
  "@set": {
    match: Index("findRecipeByAllergen"),
    terms: "egg"
  }
}

I feel it’s there is definitely something I’m missing though it is not obvious to me. Any help welcome.

I haven’t seen that error before to be honest, maybe they added that without me being aware, which would be a good thing since the two sets you are currently intersecting doesn’t really make sense. The reason why:

There is one set with many values.
There is one set without values, which would mean it only returns a ref.

Think of values as arrays of data that an index contains and therefore will return (in a sorted fashion). In this case you are essentially trying to intersect two completely different arrays, a generic example:

  • set1: [[a,b,c,d,e,f,g,ref1], […]]
  • set2: [[ref1], [ref2], …]

There is clearly no intersection between these since [a,b,c,d,e,f,g,ref1] will never match with [ref1].
Set1 either has to become [[ref], […]] as wel or set2 will need to contain the other values.
Therefore what you have to do to intersect is get rid of the a,b,c,d,e,f,g in the first set or add those to the second one.

This is definitely not ideal and will probably change in the future of FQL. In the meantime, this post will probably help you: How to query by multiple conditions in faunadb? - Stack Overflow

1 Like

Of course @databrecht , whilst a little frustrating, that makes sense. I had anticipated that the SetRefs would produce a series of tuples corresponding to value fields (i.e. something like (“field name”, “field value”)) and any combination would seek to match the relevant fields across these tuples between sets. I feel this information you had provided through SE would be valuable in the documentation as I didn’t see anything to suggest what you have mentioned would be the case in current docs.

There was a lot that was helpful here though so thanks for the time taken to clarify. If I’m reading it correctly, it may mean that unique index bindings are lost once sets are combined or like in the creation of your 'all_values_by_ref'index, that one would be needed for every index that contains a unique binding as in my "sortRecipeByRelevanceForujyvsaqlwg" index. There are several of these types of indexes (1,000+ with time) in my database so a 2n solution doesn’t excite me.

I have one enduring question here that I can’t seem to solve myself now that the function is working properly and only returning the relevant "ref". Is it possible to receive the same output as provided by my index "sortRecipeByRelevanceForujyvsaqlwg" including the binding (i.e. in this case it is "sort_result") without creating another separate index? That is, whilst all other combined indexes do not have declared values (i.e. only "ref")? Could it be as simple as just adding a "ref" term to "sortRecipeByRelevanceForujyvsaqlwg" or would that impact my ability to provide a sorted output?

Only values influence sorting. Adding a term will in no way influence your output.
It will however make it impossible to retrieve data from the index without specifying the value for the term. So if you need both access patterns, you need two indexes.