Force brute vector query

We are currently having a normal search and want to experiment on vectors. We managed to have a normal knn search but want to create a search query using the brute force of a vector. The query receive a text to search on (converted to a vector using the trainee model).

Information:
Index field with embedding: textsearch_embedding
Trainee model: hugging_face_model

Problem:
There is an error of non compatible type:

"caused_by": {
"type": "class_cast_exception",
"reason": "class java.util.HashMap cannot be cast to class java.util.List (java.util.HashMap and java.util.List are in module java.base of loader 'bootstrap')"
}

Query:

{
  "query": {
    "script_score": {
      "query" : {
...
        }
      },
      "script": {
        "source": "cosineSimilarity(params.query_vector_builder, 'textsearch_embedding') + 1.0",
        "params": {
          "query_vector_builder": {
            "text_embedding": {
              "model_id": "hugging_face_model",
              "model_text": "coffee 4 cups"
            }
          }
        }
      }
    }
  }
}

Hey @Lone_Eagle ,

query_vector_builder is only supported in knn (approximate search) for now. That is why you are receiving a parsing error.

I tried to convert the type but still ran into issues. Is something like this possible?

    "source": """
      List mFloatList = new ArrayList();

      for (Map.Entry mFloat : params.query_vector_builder.entrySet())
      { 
          mFloatList.add(mFloat.getValue());
      }

      return cosineSimilarity(mFloatList, 'textsearch_embedding') + 1.0
      """,
    "params": {
      "query_vector_builder": {
        "text_embedding": {
          "model_id": "hugging_face_model",
          "model_text": "coffee 4 cups"
        }
      }
    }

Got that error:

"caused_by": {
  "type": "class_cast_exception",
  "reason": "class_cast_exception: class org.elasticsearch.script.field.EmptyField cannot be cast to class org.elasticsearch.script.field.vectors.DenseVectorDocValuesField (org.elasticsearch.script.field.EmptyField and org.elasticsearch.script.field.vectors.DenseVectorDocValuesField are in module org.elasticsearch.server@8.8.1 of loader 'app')"
}

@Lone_Eagle as I sad, query_vector_builder and the text_embedding part are not available in brute force nearest neighbor. Only in knn.

For now, if you want to use brute force, you must infer against the model in a separate API call.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.