Go-Faiss安装教程

Go-Faiss安装教程

本文主要讲述如何解决以下问题

autotunefaiss/c_api/AutoTune_c.h: No such file or directory
5 | #include <faiss/c_api/AutoTune_c.h>
  |            ^~~~~~~~~~~~~~~~~~~~~~~~~~

1. 正常安装

这里是按照官网的说法来安装go-faiss。

git clone https://github.com/facebookresearch/faiss.git
cd faiss
cmake -B build -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_C_API=ON -DBUILD_SHARED_LIBS=ON .
make -C build
sudo make -C build install

之后,再运行下列这行代码

sudo cp build/c_api/libfaiss_c.so /usr/local/lib

这样,你就可以在Go中安装module了

go get github.com/DataIntelligenceCrew/go-faiss

安装官网的说法,在执行完这步后,就可以在Go中使用Faiss了。如何你可以成功运行官网example,就不再需要往下看了,如果你出现了我开始提到的问题,你可以尝试进行下述操作

2. 解决方法

目前网上的主要解决方法分为两种

  1. 设置环境变量

     export CGO_CFLAGS="-I /usr/local/include"
    
  2. 你的系统可能为macOS,则可能需要运行下列代码Issuse(本人未尝试,但很多点赞的)

     sudo cp build/c_api/libfaiss_c.dylib /usr/local/lib/libfaiss_c.dylib
    

由于我的系统是Linux系统,所以我只尝试的第一种方法,但是还是一样的报错,后来,我尝试了下面的方法。

  1. 我打开/usr/local/include/faiss/文件夹,发现AutoTune_c.h文件的路径并不是在faiss/c_api/AutoTune_c.h,而是在faiss/c_api/c_api/AutoTune_c.h里。中间多了一个c_api文件夹嵌套。

  2. 在发现上述问题后,我手动的改变的faiss文件夹里的c_api结构,把中间的那一层嵌套给删了,最终faiss文件的树状结构如下。可以看到,AutoTune_c.h文件的路径已经是faiss/c_api/AutoTune_c.h了。

    Faiss文件的树状结构
         .
         ├── AutoTune.h
         ├── c_api
         │   ├── AutoTune_c.h
         │   ├── clone_index_c.h
         │   ├── Clustering_c.h
         │   ├── error_c.h
         │   ├── error_impl.h
         │   ├── faiss_c.h
         │   ├── gpu
         │   │   ├── DeviceUtils_c.h
         │   │   ├── GpuAutoTune_c.h
         │   │   ├── GpuClonerOptions_c.h
         │   │   ├── GpuIndex_c.h
         │   │   ├── GpuIndicesOptions_c.h
         │   │   ├── GpuResources_c.h
         │   │   ├── macros_impl.h
         │   │   └── StandardGpuResources_c.h
         │   ├── impl
         │   │   ├── AuxIndexStructures_c.h
         │   │   └── c_api
         │   │       ├── AutoTune_c.h
         │   │       ├── clone_index_c.h
         │   │       ├── Clustering_c.h
         │   │       ├── error_c.h
         │   │       ├── error_impl.h
         │   │       ├── faiss_c.h
         │   │       ├── gpu
         │   │       │   ├── DeviceUtils_c.h
         │   │       │   ├── GpuAutoTune_c.h
         │   │       │   ├── GpuClonerOptions_c.h
         │   │       │   ├── GpuIndex_c.h
         │   │       │   ├── GpuIndicesOptions_c.h
         │   │       │   ├── GpuResources_c.h
         │   │       │   ├── macros_impl.h
         │   │       │   └── StandardGpuResources_c.h
         │   │       ├── impl
         │   │       │   └── AuxIndexStructures_c.h
         │   │       ├── Index_c.h
         │   │       ├── index_factory_c.h
         │   │       ├── IndexFlat_c.h
         │   │       ├── index_io_c.h
         │   │       ├── IndexIVF_c.h
         │   │       ├── IndexIVFFlat_c.h
         │   │       ├── IndexLSH_c.h
         │   │       ├── IndexPreTransform_c.h
         │   │       ├── IndexShards_c.h
         │   │       ├── macros_impl.h
         │   │       └── MetaIndexes_c.h
         │   ├── Index_c.h
         │   ├── index_factory_c.h
         │   ├── IndexFlat_c.h
         │   ├── index_io_c.h
         │   ├── IndexIVF_c.h
         │   ├── IndexIVFFlat_c.h
         │   ├── IndexLSH_c.h
         │   ├── IndexPreTransform_c.h
         │   ├── IndexShards_c.h
         │   ├── macros_impl.h
         │   └── MetaIndexes_c.h
         ├── clone_index.h
         ├── Clustering.h
         ├── impl
         │   ├── AuxIndexStructures.h
         │   ├── FaissAssert.h
         │   ├── FaissException.h
         │   ├── HNSW.h
         │   ├── io.h
         │   ├── io_macros.h
         │   ├── lattice_Zn.h
         │   ├── NNDescent.h
         │   ├── NSG.h
         │   ├── platform_macros.h
         │   ├── PolysemousTraining.h
         │   ├── pq4_fast_scan.h
         │   ├── ProductQuantizer.h
         │   ├── ProductQuantizer-inl.h
         │   ├── ResultHandler.h
         │   ├── ScalarQuantizer.h
         │   ├── simd_result_handlers.h
         │   ├── ThreadedIndex.h
         │   └── ThreadedIndex-inl.h
         ├── Index2Layer.h
         ├── IndexBinaryFlat.h
         ├── IndexBinaryFromFloat.h
         ├── IndexBinary.h
         ├── IndexBinaryHash.h
         ├── IndexBinaryHNSW.h
         ├── IndexBinaryIVF.h
         ├── index_factory.h
         ├── IndexFlat.h
         ├── Index.h
         ├── IndexHNSW.h
         ├── index_io.h
         ├── IndexIVFFlat.h
         ├── IndexIVF.h
         ├── IndexIVFPQFastScan.h
         ├── IndexIVFPQ.h
         ├── IndexIVFPQR.h
         ├── IndexIVFSpectralHash.h
         ├── IndexLattice.h
         ├── IndexLSH.h
         ├── IndexNNDescent.h
         ├── IndexNSG.h
         ├── IndexPQFastScan.h
         ├── IndexPQ.h
         ├── IndexPreTransform.h
         ├── IndexRefine.h
         ├── IndexReplicas.h
         ├── IndexScalarQuantizer.h
         ├── IndexShards.h
         ├── invlists
         │   ├── BlockInvertedLists.h
         │   ├── DirectMap.h
         │   ├── InvertedLists.h
         │   ├── InvertedListsIOHook.h
         │   └── OnDiskInvertedLists.h
         ├── IVFlib.h
         ├── MatrixStats.h
         ├── MetaIndexes.h
         ├── MetricType.h
         ├── utils
         │   ├── AlignedTable.h
         │   ├── distances.h
         │   ├── extra_distances.h
         │   ├── hamming.h
         │   ├── hamming-inl.h
         │   ├── Heap.h
         │   ├── ordered_key_value.h
         │   ├── partitioning.h
         │   ├── quantize_lut.h
         │   ├── random.h
         │   ├── simdlib_avx2.h
         │   ├── simdlib_emulated.h
         │   ├── simdlib.h
         │   ├── utils.h
         │   └── WorkerThread.h
         └── VectorTransform.h
    
  3. 重新运行example文件,发现已经可以成功运行!

总结

这个问题并不难,但是网上的教程实在是太少了,且我最近才学习的Go语言,所以作个学习记录吧。如果对你有帮助,可以帮忙点个赞,谢谢!

https://github.com/facebookresearch/faiss
https://github.com/DataIntelligenceCrew/go-faiss

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值