HNSW nmslib
https://github.com/nmslib/hnsw
https://github.com/nmslib/nmslib
pip install nmslib
这个会自动安装 pip install pybind11,结果报错:没有安装成功
装这个成功了:
pip install nmslib==1.7
nmslib.cc(16): fatal error C1083: 无法打开包括文件: “pybind11/pybind11.h”: No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
HNSW
使用demo:
Example Usage
import nmslib
import numpy# create a random matrix to index
data = numpy.random.randn(10000, 100).astype(numpy.float32)# initialize a new index, using a HNSW index on Cosine Similarity
index = nmslib.init(method='hnsw', space='cosinesimil')
index.addDataPointBatch(data)
index.createIndex({'post': 2}, print_progress=True)# query for the nearest neighbours of the first datapoint
ids, distances = index.knnQuery(data[0], k=10)# get all nearest neighbours for all the datapoint
# using a pool of 4 threads to compute
neighbours = index.knnQueryBatch(data, k=10, num_threads=4)
来源: https://nmslib.github.io/nmslib/quickstart.html
pybind demo下载:
https://github.com/5455945/cpp_demo
测试效果:1w条数据,查询不需要时间,创建索引需要30ms左右import datetime
import numpy as np
import logging
# logging.basicConfig(level=logging.INFO)
import nmslib
for i in range(2):
# create a random matrix to index
data = np.random.randn(200, 128).astype(np.float32)
time1=datetime.datetime.now()
# initialize a new index, using a HNSW index on Cosine Similarity
index = nmslib.init(method='hnsw', space='cosinesimil')
index.addDataPointBatch(data)
index.createIndex({'post': 2}, print_progress=False)
print("init", (datetime.datetime.now() - time1).microseconds)
time1 = datetime.datetime.now()
index.addDataPointBatch(data)
index.createIndex({'post': 2}, print_progress=False)
print("add data", (datetime.datetime.now() - time1).microseconds)
time1 = datetime.datetime.now()
index.createIndex({'post': 2}, print_progress=False)
print("createIndex", (datetime.datetime.now() - time1).microseconds)
time1 = datetime.datetime.now()
# query for the nearest neighbours of the first datapoint
ids, distances = index.knnQuery(data[0], k=150)
print("time2",len(ids))
print(ids,distances)
# get all nearest neighbours for all the datapoint
# using a pool of 4 threads to compute
# neighbours = index.knnQueryBatch(data, k=10, num_threads=4)
# print(neighbours)
HNSW nmslib相关推荐
- 向量检索(一)Faiss 在工业界的应用和常见问题解决
一.向量检索的场景 传统的搜索,使用关键做精确的查找,利用倒排索引在索引库中搜索.日常在用的百度,Google都属于关键词搜索. 在 AI 时代,我们需要查找一张相似的图片,一个问题的答案,或者根据一 ...
- HNSW算法原理(二)之删除结点
原文:https://blog.csdn.net/CHIERYU/article/details/86647014 HNSW算法原理(二)之删除结点 本篇文章继之前的一篇文章 HNSW算法原理(一) ...
- HNSW算法原理(一)
原文链接:https://blog.csdn.net/CHIERYU/article/details/81989920 HNSW算法可类比于skip lists数据结构,对于增和查操作,其与skip ...
- HNSW算法----Hierarchcal Navigable Small World graphs,第一贡献者:Y.Malkov(俄)
原文地址:https://blog.csdn.net/u011233351/article/details/85116719 一.背景介绍 在浩渺的数据长河中做高效率相似性查找一直以来都是让人头疼的问 ...
- 检索模型-粗排HNSW
文章目录 HNSW 1. 近邻图(Proximity Graph) 2. NSW算法原理 2.1 NSW构图算法 2.2 NSW查找算法 NSW 中的贪婪搜索算法 NSW中的K-NNSearch算法 ...
- 邻近搜索(Annoy HNSW LSH KD tree)
大纲 Annoy:Approximate Nearest Neighbors Oh Yeah HNSW:Hierarchcal Navigable Small World graphs KD Tree ...
- pip install nmslib 失败 (error: command ‘x86_64-linux-gnu-gcc‘ failed with exit status 1)
1. 问题现象 使用 pip 安装 nmslib 命令时出现如下错误: sudo pip install nmslib ....ERROR: Complete output from command ...
- Milvus 揭秘| 向量索引算法HNSW和NSG的比较
随着机器学习.深度神经网络的不断发展,数据的向量化无处不在.而针对海量向量数据的搜索,无论是工业界还是学术界都做了大量的研究.本文主要讲解两个基于近邻图的向量搜索算法,并比较其适用场景. 这里不得不先 ...
- 图像检索:OPQ索引与HNSW索引
图像检索:OPQ索引与HNSW索引 http://yongyuan.name/blog/opq-and-hnsw.html 2018年07月15日 Image Retrieval CBIR 字数: ...
最新文章
- c语言孩子兄弟法存储一棵树,数据结构(C语言版)---树
- 7-30 字符串的冒泡排序 (C语言)
- 第八篇、盒子模型和距中的设置方法
- opencv cuda使用笔记
- XMemcached使用示例--转
- 亚洲食品市场挑战:了解亚洲新消费群体
- OpenCV多目标跟踪与视频分析
- 北信源管理网页卸载密码_怎么卸载找不到程序的流氓软件?
- mysql注入转义绕过_SQL注入防御绕过——二次注入
- SPI通信协议详解(五)
- Hashmap红黑树源码学习
- c语言 北京时间转换utc时间_UTC时间与北京时间相互转换
- Windows上使用VLC插件的方式在IE浏览器上播放RTSP视频流
- 店铺推广前准备工作有哪些?
- 分频器的Verilog实现(偶数分频、奇数分频)
- opencv:02 读取视频,显示视频,保存视频
- bnd -buildpath指令的用法
- 【观察】亚信科技:稳中求进开新局,继往开来创新篇
- 数据科学家小贴士:10个最佳的可视化工具
- c语言 输入职工工资资料,通过结构体的数组来进行操作 报告,c语言课程设计报告-职工工资管理系统...
热门文章
- linux 统一设备模型 pci,Linux设备驱动模型摘抄
- oracle表行列权限,Oracle行列互换 横表和纵表
- android 开发环境简书,Android Studio 开发环境快速搭建
- openstack 同一网络 多个subnet
- java mysql框架_盘点 Java 数据库访问框架——究竟哪个更适合你
- 扬州智能机器人项目股票代码_特种智能机器人项目落户前湾新区
- fon在计算机网络中代表什么,计算机网络自顶向下方法第一章学习
- 下载python的步骤ios_下载及安装Python详细步骤
- python3安装cocos2d_(3)在Windows7上搭建Cocos2d-x
- linux usb组合设备,USB组合设备(5)