usearch binary
1.0.0
該存儲庫包含用於構建二進制矢量搜索的示例,指示了wikipedia嵌入在Huggingface Portal上可用的嵌入:
要查看結果,請查看bench.ipynb 。要復制結果,首先下載數據:
$ pip install -r requirements.txt
$ python download.py
$ ls -alh mixedbread | head -n 1
> total 15G
$ ls -alh cohere | head -n 1
> total 15G在這兩種情況下,嵌入都有1024個維度,每個維度都用一個位表示,填充到128個字節矢量中。建議使用32 GB的RAM來運行腳本。
知道嵌入的長度非常方便地進行優化。如果嵌入僅長1024位,我們只需要2個ZMM寄存器即可存儲整個向量。我們不需要for環,那麼整個操作都可以展開和嵌入式。
inline uint64_t hamming_distance ( uint8_t const * first_vector , uint8_t const * second_vector ) {
__m512i const first_start = _mm512_loadu_si512 (( __m512i const * )( first_vector ));
__m512i const first_end = _mm512_loadu_si512 (( __m512i const * )( first_vector + 64 ));
__m512i const second_start = _mm512_loadu_si512 (( __m512i const * )( second_vector ));
__m512i const second_end = _mm512_loadu_si512 (( __m512i const * )( second_vector + 64 ));
__m512i const differences_start = _mm512_xor_epi64 ( first_start , second_start );
__m512i const differences_end = _mm512_xor_epi64 ( first_end , second_end );
__m512i const population_start = _mm512_popcnt_epi64 ( differences_start );
__m512i const population_end = _mm512_popcnt_epi64 ( differences_end );
__m512i const population = _mm512_add_epi64 ( population_start , population_end );
return _mm512_reduce_add_epi64 ( population );
}要運行內核基準,請使用以下命令:
$ python kernel.py通過實際數據運行基準:
$ python kernels.py --dir cohere --limit 1e6