dense_vector变为“float”类型

我在尝试使用Elasticsearch实现一个搜索引擎。为此,我创建了一个包含dense_vector字段的索引和映射。PUT {{elastic uri}}/{{index}}

{    "mappings": {        "properties": {            ...            "title_embeddings": {                "type": "dense_vector",                "index": true,                "similarity": "cosine",                "dims": 1024,                "index_options": {                    "type": "hnsw",                    "ef_construction": 100,                    "m": 16                }            },            "title": {                "type": "text"            },            ...        }    }}

问题是当我使用API检索时,该字段的类型变成了“float”,而不是dense_vector。

GET {{elastic-uri}}/{{index}}/_search

{    "{{index}}": {        "mappings": {            "properties": {                ...                "title": {                    "type": "text",                    "fields": {                        "keyword": {                            "type": "keyword",                            "ignore_above": 256                        }                    }                },                "title_embeddings": {                    "type": "float"                }                ...            }        }    }}

此外,由于类型不正确,我无法在其上使用KNN搜索:

GET {{elastic-uri}}/{{index}}/_search

{  "knn": {    "field": "title_embeddings",    "query_vector": [0.1, 3.2, 2.1],    "k": 2,    "num_candidates": 100  }}

错误:无法创建查询:[knn]查询仅支持在[dense_vector]字段上使用


回答:

我之前使用以下代码来索引我的数据:

es.index(            index='{{index}}',            document=json.dumps(page.__dict__),            error_trace=True        )

使用新的代码后,它可以正常工作:

 es.index(            index='{{index}}',            document={                "id": page.id,                "title": page.title,                "title_embeddings": page.title_embeddings,                ...            },            error_trace=True        )

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注