【发布时间】:2020-04-22 22:43:45
【问题描述】:
我想在我的文档中存储一个 dense_vector 数组,但这不像其他数据类型那样有效。
PUT my_index
{
"mappings": {
"properties": {
"my_vectors": {
"type": "dense_vector",
"dims": 3
},
"my_text" : {
"type" : "keyword"
}
}
}
}
PUT my_index/_doc/1
{
"my_text" : "text1",
"my_vector" : [[0.5, 10, 6], [-0.5, 10, 10]]
}
返回:
'1 document(s) failed to index.',
{'_index': 'my_index', '_type': '_doc', '_id': 'some_id', 'status': 400, 'error':
{'type': 'mapper_parsing_exception', 'reason': 'failed to parse', 'caused_by':
{'type': 'parsing_exception',
'reason': 'Failed to parse object: expecting token of type [VALUE_NUMBER] but found [START_ARRAY]'
}
}
}
我如何实现这一目标?不同的文档会有不同数量的向量,但不会超过少数。
此外,我想通过为该数组中的每个值执行cosineSimilarity 来查询它。下面的代码是我在文档中只有一个向量时通常会这样做的方式。
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "(1.0+cosineSimilarity(params.query_vector, doc['my_vectors']))",
"params": {"query_vector": query_vector}
}
}
理想情况下,我想要最接近的相似度或平均值。
【问题讨论】:
标签: elasticsearch vector elasticsearch-query