1、elasticsearch使用的是8.5.0
索引和mapping构建:
PUT image-index
{
"mappings": {
"properties": {
"mydatavector": {
"type": "dense_vector",
"dims": 3,
"index": true,
"similarity": "dot_product"
},
"title": {
"type": "text"
}
}
}
}
2、数据入库:使用python的elasticsearch 包如果为7.11的,可以同时兼容6.x、7.x、8.x版本
from sentence_transformers import SentenceTransformer
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
encoder = SentenceTransformer('你的模型本地路径')
client2 = Elasticsearch(['http://用户名:密码@IP:PORT'])
def batch_write(data):
actions = [
{"_index": "index_name", # 替换为您的索引名称
&nb