Hybrid Search resulting in GraphQL error

On doing a Hybrid Search by providing my own vectors, the query seems to fail. I’m using the python client to do the following query:

query = "jobs in research"
search_vector = model.encode("query: " + query)
response = (
    client.query.get(
        "Content",
        ["source_content"])
        .with_hybrid(query=query, alpha=0.75, vector=search_vector, fusion_type=HybridFusion.RELATIVE_SCORE)
        .with_additional("score")
        .with_autocut(3)
        .do()   
    )

The error response I get is as follows:

{'errors': [{'locations': [{'column': 92, 'line': 1}],
   'message': 'Syntax Error GraphQL request (1:92) Unexpected ...\n\n1: {Get{Title(hybrid:{query: "jobs in research", vector: [ 0.01308592 -0.04184871  0.03915516 ... -0.06351458  0.01686241\n                                                                                              ^\n2:   0.03818709], alpha: 0.75, fusionType: relativeScoreFusion}autocut: 3){source_title _additional {score }}}}\n',
   'path': None}]}

Doing another query like this results in no errors and the expected results.

response = (
    client.query.get(
        "Content",
        ["source_content", "hasCategory { ... on KnowledgeSource { uri } }"])
        .with_near_vector({'vector': search_vector})
        .with_autocut(1)
        .do()
    )

What is the reason behind this? Is there anyway I can look at the graphql query being sent by the python client?

Hi @alt-glitch

instead of calling .do() you can always call .build() to generate the resulting graphql query.

This might be a python client issue while generating the Graphql.

Let me know if this helps so we can dig further into this.

Thanks!

Hey!
Thanks for the help. The resulting GraphQL query is:

{
  Get {
    Title(
      hybrid: {
        query: "jobs in research",
        vector: [0.01308592, -0.04184871, 0.03915516, ..., -0.06351458, 0.01686241, 0.03818709],
        alpha: 0.75,
        fusionType: relativeScoreFusion
      },
      autocut: 3
    ) {
      source_title
      _additional {
        score
      }
    }
  }
}

And the full error i get is:

{
  "errors": [
    {
      "locations": [
        {
          "column": 55,
          "line": 6
        }
      ],
      "message": "Syntax Error GraphQL request (6:55) Unexpected ...\n\n5:         query: \"jobs in research\",\n6:         vector: [0.01308592, -0.04184871, 0.03915516, ..., -0.06351458, 0.01686241, 0.03818709],\n                                                         ^\n7:         alpha: 0.75,\n",
      "path": null
    }
  ]
}

What else can I do to debug/find the issue? My search vector is of size 1024, but that doesn’t seem to be a problem when I use near_vector

I was able to fix it by converting the array from model.encode() to a list and then doing the query as follows:

query = "jobs in research"
search_vector = model.encode("query: " + query)

response = (
    client.query.get(
        "Title",
        ["source_title"])
        .with_hybrid(query=query, alpha=0.75, vector=list(search_vector), fusion_type=HybridFusion.RELATIVE_SCORE)
        .with_additional("score")
        .with_autocut(3)
        .do()
    )

I am not sure why the array from the SentenceTransformer model here doesn’t work as it is though.