theablefew / stretchy

Elasticsearch Models for Rails with an ActiveRecord-like behavior
https://theablefew.github.io/stretchy/#/
MIT License
2 stars 0 forks source link

Add `hybrid` #89

Closed esmarkowski closed 3 months ago

esmarkowski commented 3 months ago

Hybrid

model.hybrid^1

Parameter Description
queries An array of one or more query clauses that are used to match documents. A document must match at least one query clause in order to be returned in the results. The documents’ relevance scores from all query clauses are combined into one score by applying a search pipeline. The maximum number of query clauses is 5. Required.
# model.hybrid.neural(field: 'query_text', **options)

# optimal
model.hybrid.neural(passage_embedding: "Hi world", k: 5)

# with model id
model.hybrid.neural(passage_embedding: "Hi world", k: 5, model_id: 'aVeif4oB5Vm0Tdw8zYO2')

# block
model.hybrid do
   # temp relation
   where(text: 'Hi world').neural(passage_embedding: 'Hi world', k:5)
   # hybrid calls build when control is returned
end
  "query": {
    "hybrid": {
      "queries": [
        {
          "match": {
            "text": {
              "query": "Hi world"
            }
          }
        },
        {
          "neural": {
            "passage_embedding": {
              "query_text": "Hi world",
              "model_id": "aVeif4oB5Vm0Tdw8zYO2",
              "k": 5
            }
          }
        }
      ]
    }
  }