当前位置: 首页 > news >正文

【ElasticSearch】ES 5.6.15 向量插件支持

参考 :
https://github.com/lior-k/fast-elasticsearch-vector-scoring

  1. 下载插件

  2. 安装插件
    插件目录:
    elasticsearch/plugins,
    安装后的目录如下

     plugins└── vector├── elasticsearch-binary-vector-scoring-5.6.9.jar└── plugin-descriptor.properties
    

    修改 plugin-descriptor.properties 中的 elasticsearch.version 为 5.6.15(因为这里使用的是5.6.15版本ES),安装完成后重启ES。

  3. 构建测试索引

    PUT /vector_test
    {"settings": {"index": {"number_of_shards": 3,"number_of_replicas": 0}},"mappings": {"resume": {"dynamic": "strict","properties": {"file_hash": {"type": "keyword"},"embedding_vector": {"type": "binary","doc_values": true},"doc": {"type": "text"}}}}
    }
    
  4. 构建测试数据

使用如下方法生成向量base64字符串

import base64
import numpy as npdfloat32 = np.dtype('>f4')def decode_float_list(base64_string):bytes = base64.b64decode(base64_string)return np.frombuffer(bytes, dtype=dfloat32).tolist()def encode_array(arr):base64_str = base64.b64encode(np.array(arr).astype(dfloat32)).decode("utf-8")return base64_strprint(encode_array([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]))
print(encode_array([0.001,0.002,0.003,0.004,0.005,0.006,0.007,0.008,0.009,0.010]))

将上述得到的结果放到下面内容(embedding_vector)中,这里 embedding_vector 要求传入上述方式base64生成的字符串

PUT /vector_test/resume/1
{"file_hash": "hash1","embedding_vector": "PczMzT5MzM0+mZmaPszMzT8AAAA/GZmaPzMzMz9MzM0/ZmZmP4AAAA==","doc": "This is the content of the first document."
}PUT /vector_test/resume/2
{"file_hash": "hash2","embedding_vector": "OoMSbzsDEm87RJumO4MSbzuj1wo7xJumO+VgQjwDEm88E3S8PCPXCg==","doc": "This is the content of the second document."
}
  1. 查询测试

    POST /vector_test/resume/_search
    {"query": {"function_score": {"boost_mode": "replace","script_score": {"script": {"source": "binary_vector_score","lang": "knn","params": {"cosine": true,"field": "embedding_vector","vector": [1.0,0.8,0.2223,0.7,0.6,0.5,0.4,0.3,0.2,0.1]}}}}},"size": 2,"_source": ["file_hash"]
    }
    

    查询结果

    {"took": 1,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 4,"max_score": 0.998783,"hits": [{"_index": "vector_test","_type": "resume","_id": "4","_score": 0.998783,"_source": {"file_hash": "hash4"}},{"_index": "vector_test","_type": "resume","_id": "1","_score": 0.5818508,"_source": {"file_hash": "hash1"}}]}
    }
    
http://www.lryc.cn/news/399860.html

相关文章:

  • Kafka 高并发设计之数据压缩与批量消息处理
  • 设计模式使用场景实现示例及优缺点(行为型模式——模板方法模式)
  • ETL数据集成丨主流ETL工具(ETLCloud、DataX、Kettle)数据传输性能大PK
  • eNSP:防火墙设置模拟公司配置(二)
  • vue3 两个组件之间传值
  • 基于matlab的深度学习案例及基础知识专栏前言
  • 机器学习——L1 L2 范数 —>L1 L2正则化
  • 大模型时代,还需要跨端framework吗?
  • ASP.NET Core----基础学习05----将数据传递给视图文件的五种情况
  • Flutter实现局部刷新的几种方式
  • 力扣题解(回文子串)
  • 对数的基本概念
  • C双指针滑动窗口算法
  • WPF学习(6) -- WPF命令和通知
  • 升级到LVGL9的一些变化(后续发现再补充)
  • 当在多线程环境中使用 C++进行编程时,怎样确保线程安全以及如何处理线程之间的同步和通信?
  • 博物馆地图导航系统:高精度地图引擎与AR/VR融合,实现博物馆数字化转型
  • liunx作业笔记1
  • 大话C语言:第31篇 指针和数组的关系
  • Mysql-索引应用
  • Facebook 开源计算机视觉 (CV) 和 增强现实 (AR) 框架 Ocean
  • 【接口自动化_13课_接口自动化总结】
  • 安防管理平台LntonCVS视频汇聚融合云平台智慧火电厂安全生产管理应用方案
  • 【Web性能优化】在Vue项目中使用defer优化白屏,秒加载!
  • springboot上传图片
  • python入门:python及PyCharm安装
  • 链接追踪系列-04.linux服务器docker安装elk
  • 深入探讨微服务架构设计模式与常见实践
  • 【java】合并数组的两种方法
  • [图解]分析模式-01-概述1