Faiss - 部署安装和演示
最编程
2024-06-07 12:10:23
...
1. 概述
Faiss is a library for efficient similarity search and clustering of dense vectors.
It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM.
It also contains supporting code for evaluation and parameter tuning.
Faiss is written in C++ with complete wrappers for Python/numpy. Some of the most useful algorithms are implemented on the GPU.
It is developed by Facebook AI Research.
- github repository
https://github.com/facebookresearch/faiss
2. Setup
2.1. 通过conda安装faiss,简单方便
- dockerfile已经ok,可以尝试下
ARG IMAGE
FROM ${IMAGE}
ARG FAISS_CPU_OR_GPU
ARG FAISS_VERSION
RUN apt-get update && \
apt-get install -y curl bzip2 && \
curl https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh > /tmp/conda.sh && \
bash /tmp/conda.sh -b -p /opt/conda && \
/opt/conda/bin/conda update -n base conda && \
/opt/conda/bin/conda install -y python=3.6.9 && \
/opt/conda/bin/conda install -y -c pytorch faiss-${FAISS_CPU_OR_GPU}=${FAISS_VERSION} && \
apt-get remove -y --auto-remove curl bzip2 && \
apt-get clean && \
rm -fr /tmp/conda.sh
ENV PATH="/opt/conda/bin:${PATH}"
ARG IMAGE
FROM ${IMAGE}
ARG FAISS_CPU_OR_GPU
ARG FAISS_VERSION
RUN apt-get update && \
apt-get install -y curl bzip2 && \
curl https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh > /tmp/conda.sh && \
bash /tmp/conda.sh -b -p /opt/conda && \
/opt/conda/bin/conda update -n base conda && \
/opt/conda/bin/conda install -y python=3.6.9 && \
/opt/conda/bin/conda install -y -c pytorch faiss-${FAISS_CPU_OR_GPU}=${FAISS_VERSION} && \
apt-get remove -y --auto-remove curl bzip2 && \
apt-get clean && \
rm -fr /tmp/conda.sh
ENV PATH="/opt/conda/bin:${PATH}"
how to build a faiss-docker image
- references
https://anaconda.org/pytorch/faiss-cpu
https://anaconda.org/pytorch/faiss-gpu
https://github.com/plippe/faiss-docker
2.2. 源码安装
- 测试没过,卡在cuda上,有机会再试试
RUN apt-get update -y && apt-get install -y libopenblas-dev python-numpy python-dev swig python-pip curl
ENV BLASLDFLAGS=/usr/lib/libopenblas.so.0 \
PYTHON=python
RUN cd /opt \
&& git clone https://github.com/facebookresearch/faiss.git \
&& cd faiss && git checkout v1.3.0 \
&& pip3 install matplotlib==2.2.3 python-config numpy -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
&& mv example_makefiles/makefile.inc.Linux ./makefile.inc \
&& ./configure --with-python=python3 \
&& make -j $(nproc) \
&& make install \
&& make -C gpu -j $(nproc) \
&& make -C gpu/test \
&& make -C python gpu \
&& make -C python build \
&& make -C python install
3. How to use
3.1. build a index
dimensions = 128
INDEX_KEY = "IDMap,Flat"
index = faiss.index_factory(dimensions, INDEX_KEY)
3.2. is GPU used
if USE_GPU:
res = faiss.StandardGpuResources()
index = faiss.index_cpu_to_gpu(res, 0, index)
3.3. add features to index with ids
index.add_with_ids(features, ids)
3.4. search
scores, neighbors = index.search(siftfeature, k=topN)
3.5. save index and reload
faiss.write_index(index, "large.index")
index1 = faiss.read_index("large.index")
4. More documents
- Faiss Practice
https://waltyou.github.io/Faiss-In-Project-English/
https://github.com/plippe/faiss-web-service
- Analysis Report
https://waltyou.github.io/Faiss-Indexs/
dimensions = 128
INDEX_KEY = "IDMap,Flat"
index = faiss.index_factory(dimensions, INDEX_KEY)
if USE_GPU:
res = faiss.StandardGpuResources()
index = faiss.index_cpu_to_gpu(res, 0, index)
index.add_with_ids(features, ids)
scores, neighbors = index.search(siftfeature, k=topN)
faiss.write_index(index, "large.index")
index1 = faiss.read_index("large.index")
- Faiss Practice
https://waltyou.github.io/Faiss-In-Project-English/
https://github.com/plippe/faiss-web-service - Analysis Report
https://waltyou.github.io/Faiss-Indexs/
推荐阅读
-
Kerberos的原理、安装部署和使用基础
-
一键部署LNMP环境并安装WordPress的完整指南(附带安装包和脚本)
-
一步一步详解:在Java和Tomcat环境中部署和安装的图文教程
-
3步搞定!在Linux上安装、配置和部署Tomcat Web应用
-
手把手教你在Ubuntu上安装Tomcat和部署静态网页
-
如何在Docker中部署和安装RocketMQ的简易教程
-
【2022新手指南】Java编程进阶之路 - 六、技术架构篇 ### MySQL索引底层解析与优化实战 - 你会讲解MySQL索引的数据结构吗?性能调优技巧知多少? - Redis深度揭秘:你知道多少?从基础到哨兵、主从复制全梳理 - Redis持久化及哨兵模式详解,还有集群搭建和Leader选举黑箱打开 - Zookeeper是个啥?特性和应用场景大公开 - ZooKeeper集群搭建攻略及 Leader选举、读写一致性、共享锁实现细节 - 探究ZooKeeper中的Leader选举机制及其在分布式环境中的作用 - Zab协议深入剖析:原理、功能与在Zookeeper中的核心地位 - RabbitMQ全方位解读:工作模式、消费限流、可靠投递与配置策略 - 设计者视角:RabbitMQ过期时间、死信队列与延时队列实践指南 - RocketMQ特性和应用场景揭示:理解其精髓与差异化优势 - Kafka详细介绍:特性及广泛应用于实时数据处理的场景解析 - ElasticSearch实力揭秘:特性概述与作为搜索引擎的广泛应用 - MongoDB认知升级:非关系型数据库的优势阐述,安装与使用实战教学 - BIO/NIO/AIO网络模型对比:掌握它们的区别与在网络编程中的实际应用 - Netty带你飞:理解其超快速度背后的秘密,包括线程模型分析 - 网络通信黑科技:Netty编解码原理与常用编解码器的应用,Protostuff实战演示 - 解密Netty粘包与拆包现象,怎样有效应对这一常见问题 - 自定义Netty心跳检测机制,轻松调整检测间隔时间的艺术 - Dubbo轻骑兵介绍:核心特性概览,服务降级实战与其实现益处 - Dubbo三大神器解读:本地存根与本地伪装的实战运用与优势呈现 ----------------------- 七、结语与回顾
-
Zabbix 安装部署和使用步骤
-
openGauss 5.0.0 企业版 一主一备 安装和部署
-
一篇文章:深入了解 Ansible 的常用模块、安装和部署