Skip to content

Conversation

@mayya-sharipova
Copy link
Contributor

@mayya-sharipova mayya-sharipova commented Feb 22, 2019

Distance functions for dense and sparse vectors

Backport for #37947, #39313

* Distance measures for dense and sparse vectors

Introduce painless functions of
cosineSimilarity and dotProduct distance
measures for dense and sparse vector fields.

```js
{
  "query": {
    "script_score": {
      "query": {
        "match_all": {}
      },
      "script": {
        "source": "cosineSimilarity(params.queryVector, doc['my_dense_vector'].value)",
        "params": {
          "queryVector": [4, 3.4, -1.2]
        }
      }
    }
  }
}
```

```js
{
  "query": {
    "script_score": {
      "query": {
        "match_all": {}
      },
      "script": {
        "source": "cosineSimilaritySparse(params.queryVector, doc['my_sparse_vector'].value)",
        "params": {
          "queryVector": {"2": -0.5, "10" : 111.3, "50": -13.0, "113": 14.8, "4545": -156.0}
        }
      }
    }
  }
}
```

Closes elastic#31615
Create index with only 1 shard to ensure an expected request failure

Closes elastic#39218
@mayya-sharipova mayya-sharipova added backport :Search Relevance/Ranking Scoring, rescoring, rank evaluation. labels Feb 22, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@mayya-sharipova mayya-sharipova merged commit e802842 into elastic:7.x Feb 23, 2019
@mayya-sharipova mayya-sharipova deleted the backport-distance-functions-vectors branch February 23, 2019 16:52
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this pull request Jun 14, 2019
mayya-sharipova added a commit that referenced this pull request Jun 14, 2019
@jtibshirani jtibshirani added :Search Relevance/Vectors Vector search and removed :Search Relevance/Ranking Scoring, rescoring, rank evaluation. labels Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants