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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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