elasticsearch安装在服务器并进行向量检索

服务器安装elasticsearch

安装Elasticsearch的步骤通常包括以下几个阶段:

  1. 导入Elasticsearch公钥。

  2. 创建Elasticsearch仓库。

  3. 安装Elasticsearch。

  4. 启动Elasticsearch服务。

  5. 配置Elasticsearch开机自启。

以下是针对基于Debian/Ubuntu系统的安装示例:

1. 导入Elasticsearch公钥

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

2. 添加Elasticsearch源

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

更新包信息

sudo apt-get update

3. 安装Elasticsearch

sudo apt-get install elasticsearch

4. 启动Elasticsearch服务

sudo systemctl start elasticsearch.service

5. 配置Elasticsearch开机自启

sudo systemctl enable elasticsearch.service

bash 复制代码
PUT my_vectors
{
  "mappings": {
    "properties": {
      "my_vector": {
        "type": "dense_vector",
        "dims": 5  // 设置向量的维度
      }
    }
  }
}

#添加文档:
POST my_vectors/_doc/
{
  "my_vector": [0.5, 1.5, 0.5, 0.5, 1.5]
}
 
POST my_vectors/_doc/
{
  "my_vector": [1.0, 1.0, 1.0, 1.0, 1.0]
}

#执行向量搜索:
GET my_vectors/_search
{
  "query": {
    "script_score": {
      "query": {
        "match_all": {}
      },
      "script": {
        "source": "cosineSimilarity(params.query_vector, 'my_vector') + 1.0",
        "params": {
          "query_vector": [0.5, 1.5, 0.5, 0.5, 1.5]
        }
      }
    }
  }
}

在这个例子中,首先创建了一个名为my_vectors的索引,并定义了一个名为my_vectordense_vector字段,用于存储5维向量。然后,向索引中添加了两个文档,每个文档包含一个向量。最后执行了一个向量搜索,使用余弦相似度(cosine similarity)来评估与查询向量的相似度。这个查询会返回所有文档的相似度得分。

相关推荐
农村小镇哥14 分钟前
nginx服务器的介绍
运维·服务器·nginx
小夏子_riotous31 分钟前
Docker学习路径——3、常用命令
linux·运维·服务器·学习·docker·容器·centos
STLearner1 小时前
WSDM 2026 | 时间序列(Time Series)论文总结【预测,表示学习,因果】
大数据·论文阅读·人工智能·深度学习·学习·机器学习·数据挖掘
亚马逊云开发者2 小时前
【Bedrock AgentCore】AI Agent 回答不一致怎么办?双 Memory 架构实现服务标准化(附完整代码)
大数据·人工智能·架构
IMPYLH3 小时前
Linux 的 rm 命令
linux·运维·服务器·网络·bash
white-persist4 小时前
【vulhub shiro 漏洞复现】vulhub shiro CVE-2016-4437 Shiro反序列化漏洞复现详细分析解释
运维·服务器·网络·python·算法·安全·web安全
代码中介商4 小时前
手把手教你Linux 打包压缩与 gcc 编译详解
linux·运维·服务器·编译·打包·压缩
longerxin20204 小时前
阿里云AlmaLinux操作系统允许root登录配置步骤
linux·服务器·阿里云
xuanwenchao5 小时前
ROS2学习笔记 - 2、类的继承及使用
服务器·笔记·学习
大嘴皮猴儿5 小时前
从零开始学商品图翻译:小白也能快速掌握的多语言文字处理与上架技巧
大数据·ide·人工智能·macos·新媒体运营·xcode·自动翻译