You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过CURL POST请求在Solr中创建DensevectorField字段

解决Solr通过CURL创建DensevectorField字段的问题

DensevectorField对应的字段类型标识是dense_vector,但这个类型默认不会自动存在,你需要先通过Schema API创建该字段类型,再创建使用它的字段。

第一步:创建dense_vector字段类型

使用以下CURL命令提交请求,注意替换$core_name和你实际需要的向量维度(示例中为128维):

curl -s -X POST -H 'Content-type:application/json' --data-binary '{
  "add-field-type": {
    "name": "dense_vector",
    "class": "solr.DenseVectorField",
    "dimension": 128,
    "similarity": "cosine"
  }
}' "http://localhost:8984/solr/$core_name/schema"
  • dimension:必填参数,需和你的向量嵌入模型输出维度一致,比如768、1024等
  • similarity:可选参数,指定向量相似度计算方式,支持cosine、euclidean、dot_product三种

第二步:创建使用该类型的字段

参考你原有的命令,将type替换为dense_vector即可(向量字段无需termVectors参数,可直接去掉):

curl -s -X POST -H 'Content-type:application/json' --data-binary '{
  "add-field": {
    "name": "embedding_field",
    "type": "dense_vector",
    "multiValued": false,
    "stored": true,
    "indexed": true
  }
}' "http://localhost:8984/solr/$core_name/schema"

内容的提问来源于stack exchange,提问作者JohnJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 16:02:05