- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
执行此查询时,我使用的是Elasticsearch 7.9.0版:
curl -XGET 'https:somehost:9200/index_name/_search' -H 'Content-Type: application/json' -d '{
"size": 10,
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "cosineSimilarity(params.query_vector, \u0027title_embed\u0027) + 1.0",
"params": {
"query_vector": [-0.19277021288871765, 0.10494251549243927,.......]}
}
}
}
}'
注意:
query_vector
是Bert生成的768维 vector 。
\u0027
是Unicode,用于单引号。
"cosineSimilarity(params.query_vector, 'title_embed') + 1.0","
^---- HERE"],"script":"cosineSimilarity(params.query_vector, 'title_embed') +
1.0","lang":"painless","position":{"offset":38,"start":0,"end":58},"caused_by":
{"type":"class_cast_exception","reason":"class
org.elasticsearch.index.fielddata.ScriptDocValues$Doubles cannot be cast to class
org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$DenseVectorScriptDocValues
(org.elasticsearch.index.fielddata.ScriptDocValues$Doubles is in unnamed module of loader 'app';
org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$DenseVectorScriptDocValues is in
unnamed module of loader java.net.FactoryURLClassLoader @715fb77)"}}}]},"status":400}
虽然索引映射中
title_embed
的数据类型是Elasticsearch的
dense_vector
类型,但错误表明它是double,我不知道为什么?
"mappings": {
"properties": {
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"domain": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"link": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"pub_date": {
"type": "date"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"title_embed": {
"type": "dense_vector",
"dims": 768
},
"description_embed": {
"type": "dense_vector",
"dims": 768
}
}
}
当我尝试使用python执行此查询时,收到相同的错误:
status_code, error_message, additional_info
elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', "class_cast_exception: class org.elasticsearch.index.fielddata.ScriptDocValues$Doubles cannot be cast to class org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$DenseVectorScriptDocValues (org.elasticsearch.index.fielddata.ScriptDocValues$Doubles is in unnamed module of loader 'app'; org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$DenseVectorScriptDocValues is in unnamed module of loader java.net.FactoryURLClassLoader @6d91790b)")
最佳答案
如果可能,请检查变量数是否等于映射中的维数,即dims:768
“query_vector”中的值数等于768吗?
我建议通过运行以下命令再次检查映射,以查看映射是否良好:
GET index_name/_mapping
另外,您可能在传递“query_vector”时错过了一个值。
POST /index_name/_doc
{
"title_embed": [10.01,15,15]
}
我如上所述尝试用较低的 vector 尺寸复制您的查询:
{
"size": 10,
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "cosineSimilarity(params.query_vector,'title_embed') + 1.0",
"params": {
"query_vector": [-0.19277021288871765, 0.10494251549243927,12.202022]
}
}
}
}
}
注意:如Tom Elias所述,运行doc ['title_embed']可以运行,但在7.9.0版中已弃用。
"query_vector": [12,-1020.02000,10,-5.0000,2]
如果这不起作用,我认为可能对允许的尺寸数量有内部限制。
关于python - Elasticsearch脚本使用densed_vector查询余弦相似度给出 “class_cast_exception”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63678838/
我有一个例程,它将接受 union 参数 d、theta、a 和 alpha 作为输入,并将生成相应的 4x4 齐次矩阵作为输出。我已经测试了我的矩阵乘法,它确实工作正常。我将从输入中得到 5 个矩阵
我有以下代码使用预先计算的内存表执行 Sin/Cos 函数。在下面的例子中,表格有 1024*128 个项目,涵盖了从 0 到 2pi 的所有 Sin/Cos 值。我知道我可以使用 Sin/Cos 对
问题是不言自明的。我看过几个 pi 的例子,但没有看到 trigo 函数。也许可以使用泰勒级数 as done here但我不完全确定如何在 python 中实现它。特别是如何存储这么多数字。我应该提
我开始学习 Python 中的数学模块,并试图围绕 Python 中的正弦、余弦和正切的三角函数。 我花了一些时间学习更多关于三角学的知识,并了解了直角三角形的基本公式是如何工作的: 正弦函数: si
我一个月前才开始学习这门 C++ 类(class)。现在我被分配去写一个程序来计算这个。我不知道我做错了什么。 #include #include float gatherl1(); float
这个问题在这里已经有了答案: Python cos(90) and cos(270) not 0 (3 个答案) 关闭 9 年前。 有没有办法获得角度(以弧度为单位)的精确正切/余弦/正弦? mat
这个问题在这里已经有了答案: Java Math.cos(Math.toRadians()) returns weird values (4 个答案) 关闭 10 年前。 我正在编写一个程序,我必须
我做了一个简单的计算器作为我的第一个android程序,现在我想给它添加trigonometry,log等函数。在 C 中,我们必须包含 math library 才能这样做,我似乎无法弄清楚你是如何
我正面临 objective-c 中 cos 函数的奇怪问题。我安装了带有 iOS 4.3 SDK 的 xcode 4.1.1。 我正在计算一个数的余弦值: y= cos(x*M_PI/180) 这将
尝试将以下 php 方法转换为在 .less 样式表中使用: 在 Less 中,如何在不使用特定语言的 cos()/sin() 函数的情况下实现正弦/余弦方法? .rotate(@deg) {
可以使用 iPhone 3GS 或 Pandora 的人请测试我刚刚编写的以下组装程序吗? 它应该在 NEON 矢量 FPU 上非常快速地计算正弦和余弦。我知道它编译得很好,但没有足够的硬件我无法测试
我为泰勒级数编写了以下函数来计算余弦。 double cosine(int x) { x %= 360; // make it less than 360 double rad = x
我是一名优秀的程序员,十分优秀!