è¿ä¼¼æè¿åæ¢ç´¢ã«ãããæ°ãããããéååææ³ãRaBitQã¨BBQ
Elasticsearch 8.16 㧠Better Binary Quantization (BBQ) ã¨ãããæ°ããå¯ãã¯ãã«ã®ãã£ã¼ã«ãã¿ã¤ãã追å ããã¾ããã
- Dense vector field type | Elasticsearch Guide | Elastic
- Elasticsearch version 8.16.0 New features | Elasticsearch Guide | Elastic
- Adding new experimental bbq index types by benwtrent · Pull Request #114439 · elastic/elasticsearch · GitHub
Elasticsearch ã§ã¯ãã¯ãã«ã®å次å
ã® int8
ã int4
ã¸ã®éååããµãã¼ããã¦ãã¾ãããBBQ ã§ã¯ãããã«ã¾ã§éååãããã¨ã§ããããªãã¤ã³ããã¯ã¹ãµã¤ãºã®åæ¸ã¨è¿ä¼¼è¿åæ¢ç´¢ã®é«éåãå³ã£ã¦ãã¾ãã
ãã®è¨äºã§ã¯ãã¾ã BBQ ã®å ã«ãªã£ã RaBitQ[1] ã¨ãããã¯ãã«éååææ³ã解説ãã¾ãããã®ãã¨ãElasticsearch ã«ããã BBQ ã®å®è£ ã«ã¤ãã¦èª¬æããRaBitQ 㨠BBQ ã®éãã«ã¤ãã¦è§¦ãã¾ãã
ãã®è¨äºã¯æ å ±æ¤ç´¢ã»æ¤ç´¢æè¡ Advent Calendar 2024 ã® 25 æ¥ç®ã®è¨äºã§ãã
- è¿ä¼¼æè¿åæ¢ç´¢ (ANN)
- RaBitQ
- RaBitQ ã®æ¦è¦
- ãã¯ãã«ã®æ£è¦å
- å¤æ¬¡å ã³ã¼ãããã¯
- ã©ã³ãã ã³ã¼ãããã¯ã®è¨ç®
- ãã¼ã¿ãã¯ãã«ã®éåå
- ãã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®è·é¢
- ãã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®å ç©ã®æ¨å®
- RabitQ ã®ã¤ã³ããã¯ã¹ãã§ã¤ãº
- ãã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®å ç©ã®è¿ä¼¼è¨ç®
- ã¯ã¨ãªãã¯ãã«ã®éåå
- éååãããã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®å ç©è¨ç®
- SIMD ã«ããå ç©è¨ç®ã®é«éå
- å ç©è¨ç®ã®æé©åã®å ·ä½ä¾
- RaBitQ ã®ã¯ã¨ãªãã§ã¤ãº
- RaBitQ 㨠ANN
- RaBitQ ã®æ¡å¼µ
- BBQ
- ã¾ã¨ã
è¿ä¼¼æè¿åæ¢ç´¢ (ANN)
RaBitQ ã®åã«ããã®èæ¯ã¨ãªã£ã¦ããè¿ä¼¼æè¿åæ¢ç´¢ã«ã¤ãã¦ç°¡åã«èª¬æãã¾ãã
ANN ã®åé¡è¨å®
ãããã¯ãã«ãä¸ããããã¨ãã«ãããããè¿ããã¯ãã«ãæ¢ãã¿ã¹ã¯ãæè¿åæ¢ç´¢ (NN query; nearest neighbor query) ã¨ããã¾ããè¿ä¼¼æè¿åæ¢ç´¢ã¨ã¯ãNN ã®ããã« exact ã«è¿ããã¯ãã«ãæ¢ãã®ã§ã¯ãªããããç¨åº¦ã®èª¤å·®ã許容ãããã®ã§ãã
D 次å ã®ã¦ã¼ã¯ãªãã空éãèãã¾ããè¿ä¼¼æè¿åæ¢ç´¢ (ANN query; approximate nearest neighbor query) ã¨ã¯ã
- ã¯ã¨ãªãã¯ãã« $q$ ã«å¯¾ãã¦
- $N$ åã®ãã¼ã¿ãã¯ãã«ã®éåãã
- $K$ åã®è¿ä¼¼æè¿åãã¯ãã«ãåå¾ (retrieve) ãã
ã¨ããåé¡è¨å®ã§ããANN query ã¯åã« ANN ã¨å¼ã°ãããã¨ãããããã¾ãããã®ããã以ä¸ã§ã¯ ANN ã¨è¡¨è¨ãã¾ãã
è¨èªã¢ãã«ã¨ãã¯ãã«åãè¾¼ã¿
åèªãæãæç« ãªã©ãããããããã¹ããã¼ã¿ã¯è¨èªã¢ãã« (LM; language model) ã«ããããã¯ãã«ã«å¤æã§ãã¾ããããããã¯ãã«åã込㿠(vector embeddings) ã¨å¼ã³ã¾ããèªç¶è¨èªå¦ç (NLP; natural language processing) ã§ã¯é常ã100 ãã 1000 次å ç¨åº¦ã®ãã¯ãã«ã«å¤æãã¾ãããã®ããã«é«æ¬¡å ã®ãã¯ãã«ç©ºéã«åãè¾¼ã¾ãããã¯ãã«ã®ãã¨ããåã«åã込㿠(embeddings) ã¨å¼ã¶ãã¨ãããã¾ãã
è¿å¹´ã®LM ã®æ¥éãªçºå±ã«ãããã質ã®ããããã¯ãã«åãè¾¼ã¿ãç°¡åã«è¨ç®ã§ããããã«ãªãã¾ãããã¤ã¾ããåãè¾¼ã¾ãããã¯ãã«ç©ºéä¸ã§è¿ããã¯ãã«å士ã¯æå³ãè¿ãã¨ã¿ãªãããã¨ãããã¨ã§ãããã®æ§è³ªã¯æ å ±æ¤ç´¢ (information retrieval) ãªã©ã®ã¿ã¹ã¯ã«ããã¦éè¦ãªæå³ãæããã¾ãã
ANN ã®éè¦æ§
ãã¼ã¿ã1次å ã§ããã°ã B-tree ãªã©ã®ãã¼ã¿æ§é ã§å¹ççã«ã¤ã³ããã¯ã¹åã»æ¤ç´¢ã§ãã¾ãããå¤æ¬¡å ã«ãªãã¨é£ãããªãã¾ããããã«é«æ¬¡å ããã¨ãã°èªç¶è¨èªå¦çã§ä½¿ç¨ããããã㪠1000 次å ã¯ã©ã¹ã«ãªãã¨ãkd-tree ã®ãããªå¤æ¬¡å ã¤ã³ããã¯ã¹ãå½¹ã«ç«ã¡ã¾ããã
ããã§ä¸å®ã®èª¤å·®ãçãããã¨ãèªããå®éã¯ãã£ã¨è¿ããã¯ãã«ãããããã©ãã ãããè¿ã (approximate nearest neighbor) ãã¯ãã«ãè¿ãã° OK ã¨ãããã¨ã«ãã¾ããããã¨ããåé¡è¨å®ã ANN ã§ãã
NN query ãã ANN query ã«åé¡ãç·©å (relax) ãããã¨ã§ãé«æ¬¡å ã®ãã¯ãã«æ¤ç´¢ãé«éã«å®è¡ãããã¨ãã§ãã¾ããä¾ãã°ãFAISSãAnnoyãFLANNãScaNNãNGTãDiskANN ã¨ãã£ãææ³ï¼å®è£ ï¼ãæåã§ãããããã®ææ³ã¯ã精度 (recall) ãããç¨åº¦ä¿ã¡ãªããé«éã« ANN ã® K åã®ãã¯ãã«ãæ¤ç´¢ãããã¨ãã§ãã¾ããä»ã«ãã ann-benchmarks[2] ã¨ãããªãã¸ããªã«ã¯ãANN ã®ã¡ã¸ã£ã¼ãªææ³ã¨ãã®ãã³ããã¼ã¯çµæãã¾ã¨ã¾ã£ã¦ãã¾ãã
ANN ã¯ç¾å¨ãæ´»çºã«ç 究éçºãããæ¥é²ææ©ã§ãã®ç²¾åº¦ã¨é度ãåä¸ãã¦ãã¾ããANN ã«èå³ããã£ãæ¹ã¯ã以ä¸ã®ã¹ã©ã¤ã[3]ãããã¾ã¨ã¾ã£ã¦ããã®ã§ãåèã«ããã¨ããã§ãããã
ANN ã¨ãã¯ãã«ã®éåå
è¿ä¼¼æè¿åæ¢ç´¢ (ANN) ã®ã¤ã³ããã¯ã¹ã«ã¯ããã¹ã¦ã®ãã¼ã¿ãã¯ãã«ãä¿æããå¿
è¦ãããã¾ããåãã¼ã¿ãã¨ã«ã次å
æ° x ã¹ã«ã©ã¼ã®ãã¼ã¿ãµã¤ãº (e.g., float32
)ãã®å®¹éãå¿
è¦ã«ãªããå¹ççã¨ã¯è¨ãã¾ããã
ãã¯ãã«ã®éåå (quantization) ã¯ãä¸è¬ã«ã¯ float32
ã float64
ã®é
åã§è¡¨ç¾ããããã¯ãã«ãã int8
ã int4
ãªã©ã®ã³ã³ãã¯ããªæ´æ°è¡¨ç¾çã«å¤æããææ³ã§ãããã¯ãã«ãéååãããã¨ã§ã¡ã¢ãªããã£ã¹ã¯ã®ä½¿ç¨éãæããã¾ã SIMD ã«ãã£ã¦æ¤ç´¢å¦çã®é«éåãçãã¾ãã
éååã«é¢é£ãã代表ç㪠ANN ã®é«éåææ³ã¨ãã¦ãç´ç©éåå (PQ) ã¨è»¢ç½®ãã¡ã¤ã« (IVF) ãããç¥ããã¦ãã¾ããã¾ããéååã¨ã¯ç´æ¥é¢ä¿ã¯ãªãã§ãããå¥ã® ANN é«éåæ段ã¨ã㦠HNSW ã¨ããã°ã©ããã¼ã¹ã®ã¤ã³ããã¯ã¹ææ³ãããã¾ãã
ãããã«ã¤ãã¦ã以ä¸ã®è³æ[3:1]ã«è©³ããã¾ã¨ã¾ã£ã¦ãã¾ãã
ç´ç©éåå (PQ)
代表çãªãã¯ãã«éååææ³ã®ä¸ã¤ã«ãç´ç©éåå (PQ) ãããã¾ãã
ãã¯ãã«éåå (VQ; vector quantization) ã¯ããã¯ãã«ã®éåãäºåè¨ç®ãã K åã®ã»ã³ããã¤ãã§ä»£è¡¨ããå¤å ¸çãªææ³ã§ããVQ ã§ã¯ããã¯ãã«ãæãè¿ãã»ã³ããã¤ãã® ID ã§è¡¨ç¾ãã¾ãã
ç´ç©éåå (PQ; product quantization)[4] ã¯ããã¯ãã«ã®æ¬¡å ã M åã«åå²ãã¦ããããã®ã¹ã©ã¤ã¹ããããã VQ ããæ¹æ³ã§ãããã® M åã®ä»£è¡¨ãã¯ãã«ï¼ã® IDï¼ã®éåãã³ã¼ãããã¯ã¨å¼ã³ã¾ããPQ ã§ã¯ãåå²ãã M åãã¨ã«è¿ãã»ã³ããã¤ããæ¢ããããã M åã® ID ã§è¡¨ç¾ãã¾ãã
転置ãã¡ã¤ã« (IVF)
ã¾ããç´ç©éåå (PQ) ã¨çµã¿åããã¦æ¤ç´¢ãå¹çåãããã¼ã¿æ§é ã¨ãã¦ã転置ãã¡ã¤ã« (IVF) ãããã¾ãã
転置ãã¡ã¤ã« (IVF; inverted file) ããã㯠IVFADC (Inverted File with Asymmetric Distance Computation)[4:1] ã¨ã¯ã転置ã¤ã³ããã¯ã¹çãªè£å©ãã¼ã¿æ§é ãããã³ãããå©ç¨ããANN ã®é«éåææ³ã§ããIVF ã§ã¯ã¾ãã空éãããã¤ãã«åå²ããããããã®é¨å空éã代表ããã»ã³ããã¤ããç¨æãã¾ãããã¯ãã«ãä¸ããããã¨ãã«ãã©ã®é¨å空éã«å ¥ããï¼ï¼ã©ã®ã»ã³ããã¤ããè¿ããï¼ãè¨ç®ããç²éååå¨ (coarse quantizer) ãäºåã«æºåãã¦ããã¾ã [5]ã
IVF ã¯ã以ä¸ã®ããã«ãè¿ããã¯ãã«ã代表ãã¯ãã«ï¼ã»ã³ããã¤ãï¼ããã¼ã¨ãã転置ãªã¹ãã«ã¾ã¨ãã¾ã[4:2]ãIVF ã§ãã¯ãã«ãæ¤ç´¢ããã¨ãã«ã¯ãã¾ãéååãããã¯ãã«ãè¨ç®ãããã®è»¢ç½®ãªã¹ããåå¾ãã¾ãããã®ãã¨å¾ããã転置ãªã¹ããèµ°æ»ããæçµçãªæè¿åã®ãã¯ãã«ãè¨ç®ãã¾ãã
RaBitQ
RaBitQ[1:1] ã¯ãJianyang Gao & Cheng Long ã«ãã£ã¦ææ¡ããããæ°ãã ANN ã¤ã³ããã¯ã¹ã®ãã¯ãã«éååææ³ã§ãããã®æ¹æ³ã¯ããã¯ãã«ã®å次å ã1ãããã«éååãããã¨ã§ãã¤ã³ããã¯ã¹ãµã¤ãºãå°ããããã¾ããããæ¼ç®ã SIMD ãæ´»ç¨ãããã¨ã§æ¤ç´¢å¦çãé«éåãã¦ãã¾ããRaBitQ ã®è«æã§ã¯ãPQ ã¨æ¯è¼ããã¨ãã®åªä½æ§ã«ã¤ãã¦ã説æããã¦ãã¾ãã
RaBitQ ã®æ¦è¦
RaBitQ ã®ã¢ã«ã´ãªãºã ããã¤ã³ããã¯ã¹ãã§ã¤ãºï¼ã¤ã³ããã¯ã¹ã®æ§ç¯ï¼ã¨ã¯ã¨ãªããã§ã¤ãºï¼ã¤ã³ããã¯ã¹ããã®æ¤ç´¢ï¼ã«åãã¦èª¬æãã¾ããè«æ[1:2]ã«åããã¦ä»¥ä¸ã®ããã«è¡¨è¨ãã¾ãã
è¡¨è¨ | 説æ |
---|---|
$\bm{o_r}$ | å ã®ãã¼ã¿ãã¯ãã«ï¼æ£è¦åã»éåååï¼ |
$\bm{q_r}$ | å ã®ã¯ã¨ãªãã¯ãã«ï¼æ£è¦åã»éåååï¼ |
$\bm{o}$ | æ£è¦åãããã¼ã¿ãã¯ãã« |
$\bm{q}$ | æ£è¦åããã¯ã¨ãªãã¯ãã« |
$\bm{c}$ | ã»ã³ããã¤ãï¼ä¸å¿ãã¯ãã«ï¼ |
$C$ | éååãã¯ãã«ã®ã³ã¼ãããã¯ï¼éåï¼ |
$C_{rand}$ | ã³ã¼ããã㯠$C$ ãã©ã³ãã åãããã® |
$\overline{\bm{x}}$ | éååãããã¼ã¿ãã¯ãã«ï¼ã³ã¼ããã㯠$C$ ã®ä¸ããé¸ã¶ï¼ |
$\overline{\bm{o}}$ | éååãããã¼ã¿ãã¯ãã«ï¼ã³ã¼ããã㯠$C_{rand}$ ã®ä¸ããé¸ã¶ï¼ãã¤ã¾ã $\overline{\bm{o}} = P \overline{\bm{x}}$ |
$\overline{\bm{x}}_b$ | æ£è¦åãããã¼ã¿ãã¯ãã« $\bm{o}$ ãéååããããã表ç¾ã«ãããã® |
$\bm{q}\rq$ | ã¯ã¨ãªãã¯ãã«ãã©ã³ãã å°å½±ã®éè¡å $P^{-1}$ ã§å¤æãããã®ï¼ $\bm{q}\rq = P^{-1} \bm{q}$ ï¼ |
$\overline{\bm{q}}$ | å¤æå¾ã®ã¯ã¨ãªãã¯ãã« $\bm{q}\rq$ ãéååãããã® |
$\overline{\bm{q}}_u$ | $\overline{\bm{q}}$ ã®ç¬¦å·ãªãæ´æ°è¡¨ç¾ |
RaBitQ ã§ã¯ããã¼ã¿ãã¯ãã«ï¼$\bm{o_r}$ ã®éåï¼ã以ä¸ã®ããã«éååã»ã¤ã³ããã·ã³ã°ãã¾ãï¼ã¤ã³ããã¯ã¹ãã§ã¤ãºï¼ã
- ã»ã³ããã¤ã $\bm{c}$ ãè¨ç®ãããã¹ã¦ã®ãã¼ã¿ãã¯ãã«ãæ£è¦åï¼$\bm{o_r}$ ã $\bm{o}$ ã«ããï¼
- ã©ã³ãã ãªç´äº¤è¡å $P$ ããµã³ããªã³ã°ããã³ã¼ããã㯠$C_{rand}$ ãæ§ç¯
- éååããããã¼ã¿ãã¯ãã« $\overline{\bm{x}}_b$ ãè¨ç®ï¼ã³ã¼ãããã¯ã®ä¸ããé¸ã¶ï¼
- 以ä¸ãäºåè¨ç®
- ãã¼ã¿ãã¯ãã«ã¨ã»ã³ããã¤ãã¨ã®è·é¢ $\Vert \bm{o}_r - \bm{c} \Vert$
- éååããããã¼ã¿ãã¯ãã«ã¨æ£è¦åãããã¼ã¿ãã¯ãã«ã®å ç© $\langle \overline{\bm{o}}, \bm{o}\rangle$
æ§ç¯ãããã¤ã³ããã¯ã¹ã«å¯¾ãã¦ãæ¤ç´¢ã¯ä»¥ä¸ã®ã¢ã«ã´ãªãºã ã§è¡ãã¾ãï¼ã¯ã¨ãªãã§ã¤ãºï¼ã
- ã¯ã¨ãªãã¯ãã«ãæ£è¦åã»å¤æ
- 1.ã®ã¯ã¨ãªãã¯ãã«ãéåå
- åãã¼ã¿ãã¯ãã«ã«å¯¾ãã¦ä»¥ä¸ãè¨ç®
- $\frac{\langle \bm{\overline{o}}, \bm{q}\rangle}{\langle \bm{\overline{o}}, \bm{o}\rangle}$ ãè¨ç®ï¼$\langle \bm{o}, \bm{q}\rangle$ ã®è¿ä¼¼å¤ã¨ãã¦ä½¿ç¨ãããå¾è¿°ï¼
- å ã®ã¯ã¨ãªãã¯ãã«ã¨ãã¼ã¿ãã¯ãã«ã®è·é¢ã®æ¨å®å¤ãè¨ç®
ããã§ã¯ãRaBitQ ã®åã¹ãããã詳ããè¦ã¦ããã¾ããããã¾ããã¤ã³ããã¯ã¹ãã§ã¤ãºã§ãã¯ã¨ãªãã§ã¤ãºã§ãå ±éã§ä½¿ç¨ããããã¨ã«ãªãããã¯ãã«ã®æ£è¦åã¨ã³ã¼ãããã¯ã«ããéååã«ã¤ãã¦èª¬æãã¾ãã
ãã¯ãã«ã®æ£è¦å
ãã¯ãã« $\bm{x}_1, \cdots, \bm{x}_k$ ã®ã»ã³ããã¤ã $\bm{c}$ ã¯ä»¥ä¸ã§è¨ç®ããã¾ãã
\[ \bm{c} = \frac{1}{k} (\bm{x}_1 + \cdots + \bm{x}_k) \]
RaBitQ ã§ã¯ã¾ããä¸ãããããã¼ã¿ãã¯ãã«å ¨ä½ãããã»ã³ããã¤ã $\bm{c}$ ãäºåã«è¨ç®ãã¾ãã
ãã®å¾ãåãã¼ã¿ãã¯ãã« $\bm{o}_r$ ã«å¯¾ãã¦ã以ä¸ã®ããã«æ£è¦åããããã¯ãã« $\bm{o}$ ãå¾ã¾ãï¼
\[ \bm{o} := \frac{\bm{o}_r - \bm{c}}{\|\bm{o}_r - \bm{c}\|} \]
ãã®æ§åãå¯è¦åãããã®ã以ä¸ã§ã[6]ã
å¤æ¬¡å ã³ã¼ãããã¯
次ã«ãæ£è¦åãããã¯ãã«ãéååãããã¨ãèãã¾ãã代表ç¹ï¼ã³ã¼ãï¼ã®éåï¼ã³ã¼ãããã¯ãèãããã¯ãã«ãããã«æãè¿ã代表ç¹ã§è¡¨ç¾ï¼è¿ä¼¼ï¼ãããã¨ã«ãã£ã¦éååã§ãã¾ãã
æ£è¦åãããã¼ã¿ãã¯ãã«ã¯ãåä½çé¢ä¸ã«åºãã£ã¦åå¸ãããã¨ãæå¾ ããã¾ã[7]ããã£ã¦ã³ã¼ãããã¯ããåä½çé¢ä¸ã«ä¸æ§ã«åå¸ããããã«æ§æãã¾ããã³ã¼ãããã¯ã®è¦ç´ ï¼ã³ã¼ãï¼ã¯åä½çé¢ä¸ã®ç¹ãªã®ã§ãåä½ãã¯ãã«ã§ãããã¨ã«æ³¨æãã¾ãã
ãã¯ãã«ç©ºéã®æ¬¡å ã $D$ ã¨ããã¨ããèªç¶ãªæ§æã¨ãã¦ãã³ã¼ãããã¯ã以ä¸ã®ããã«ã¤ãããã¨ãèãããã¾ãã
\[ C := \lbrace +\frac{1}{\sqrt{D}}, -\frac{1}{\sqrt{D}} \rbrace ^D \]
ãã®ããã«æ§æããã³ã¼ãããã¯ã¯ãå ·ä½çã«ã¯ä»¥ä¸ã®ããã«ãªãã¾ãï¼ã³ã¼ãããã¯ã¯ $2^D$ åã®è¦ç´ ããã¡ã¾ãï¼ã
- 1次å : $\lbrace +1, -1 \rbrace$
- 2次å : $\lbrace \lparen +\frac{1}{\sqrt{2}}, +\frac{1}{\sqrt{2}} \rparen, \lparen +\frac{1}{\sqrt{2}}, -\frac{1}{\sqrt{2}} \rparen, \lparen -\frac{1}{\sqrt{2}}, +\frac{1}{\sqrt{2}} \rparen, \lparen -\frac{1}{\sqrt{2}}, -\frac{1}{\sqrt{2}} \rparen, \rbrace$
- 3次å : $\lbrace \lparen +\frac{1}{\sqrt{3}}, +\frac{1}{\sqrt{3}}, +\frac{1}{\sqrt{3}} \rparen, \dots, \lparen -\frac{1}{\sqrt{3}}, -\frac{1}{\sqrt{3}}, -\frac{1}{\sqrt{3}} \rparen \rbrace$
2次å ã®ã¨ãã®ä¾ãèãã¾ãããã2次å ã®å ´åãã³ã¼ããã㯠$\lbrace \lparen +\frac{1}{\sqrt{2}}, +\frac{1}{\sqrt{2}} \rparen, \lparen +\frac{1}{\sqrt{2}}, -\frac{1}{\sqrt{2}} \rparen, \lparen -\frac{1}{\sqrt{2}}, +\frac{1}{\sqrt{2}} \rparen, \lparen -\frac{1}{\sqrt{2}}, -\frac{1}{\sqrt{2}} \rparen, \rbrace$ ã®ä¸ããããã£ã¨ãè¿ã代表ç¹ãé¸ã¶ãã¨ã«ãªãã¾ããå¹¾ä½å¦çã«èããã¨ã以ä¸ã®ããã«ã4象éï¼é åï¼ã®ããããã«ã³ã¼ãããã¯ã®ä»£è¡¨ç¹ã対å¿ãã¦ããã¨æãããã¾ã[8]ã
3次å ã®å ´åã¯é åã8åã«å¢ããã ãã§ãåæ§ã«åé åã®ãä¸å¿ãã«ä»£è¡¨ç¹ãä½ç½®ãããã¨ã«ãªãã¾ãã4次å 以ä¸ã«ãªãã¨æ³åããã®ãé£ããã¯ãªãã¾ããåæ§ã§ãã
ãã¦ãã³ã¼ããã㯠$C$ ãæ§æããã¨ããæ£è¦åãããã¼ã¿ãã¯ãã«ãåä½çé¢ä¸ã«åºãã£ã¦åå¸ãããã¨ãä»®å®ãã¦ãã¾ãããããããæ£æçã«ä½æãã人工ãã¼ã¿ã§ããªãéããå®éã«ã¯åãããããã¨ãæ³å®ããã¾ãããã®åããæ±ãããã«ãRaBitQ ã§ã¯ãä¸è¨ã®ã³ã¼ãããã¯ã®ã©ã³ãã ç´äº¤å°å½±ãèãããããã³ã¼ãããã¯ã¨ãã¾ãã
ã©ã³ãã ã³ã¼ãããã¯ã®è¨ç®
RaBitQ ã§ã¯ãã³ã¼ããã㯠$C$ ã®åãã¯ãã«ãã©ã³ãã ãªç´äº¤è¡å (orthogonal matrix) $P$ ã§å¤æãããã®ãæçµçãªã³ã¼ããã㯠$C_{rand}$ ã¨ãã¾ãï¼
\[ C_{rand} := \lbrace P \bm{x} | \bm{x} \in C \rbrace \]
ç´äº¤è¡åã¨ã¯ã以ä¸ãæºãããããªæ£æ¹è¡å R ã®ãã¨ã§ããã
\[ R^T R = R R^T = I \]
ç´äº¤è¡åã®æ§è³ªã¨ãã¦ã以ä¸ã®ãããªãã®ãããã¾ãã
- ç´äº¤è¡åã®éè¡åã¯è»¢ç½®è¡åã§ãã: $R^{-1} = R^T$
- è¡å $A$ ã®éè¡åã¨ã¯ $AB = BA = I$ ãæºãããããªè¡å B ã®ãã¨ã
- ç´äº¤è¡åã®å®ç¾©ãã $R^T = R^{-1}$ ã§ããã
- ç´äº¤è¡åã¯ãã«ã ãä¸å¤ã«ä¿ã¤å¤æã§ãã: $\Vert R \bm{u} \Vert = \Vert \bm{u} \Vert$
- R ãç´äº¤è¡åã u ãä»»æã®ãã¯ãã«ã¨ããã¨ãã $\Vert R\bm{u} \Vert^2 = \langle R\bm{u}, R\bm{u} \rangle = \langle \bm{u}, R^T R\bm{u} \rangle = \langle \bm{u},\bm{u} \rangle = \Vert\bm{u}\Vert^2$ã
- ãã£ã¦ $\Vert Ru\Vert = \Vert u \Vert$ã
- ç´äº¤è¡åã«ããå¤æã¯å
ç©ãä¸å¤ã«ä¿ã¤: $\langle R\bm{u}, R\bm{v} \rangle = \langle \bm{u}, \bm{v} \rangle$
- R ãç´äº¤è¡åã u, v ãä»»æã®ãã¯ãã«ã¨ããã¨ãã $\langle R\bm{u}, R\bm{v} \rangle = \langle \bm{u}, R^T R\bm{v} \rangle = \langle \bm{u},\bm{v} \rangle$
$P$ ã¯ç´äº¤è¡åãªã®ã§ãåä½ãã¯ãã« $\bm{x} \in C$ ãå¤æãã $P\bm{x} \in C_{rand}$ ãã¾ãåä½ãã¯ãã«ã¨ãªãã¾ãï¼ä¸è¨ã®æ§è³ªãç´äº¤è¡åã¯ãã«ã ãä¸å¤ã«ä¿ã¤å¤æã§ãããããï¼ãã¤ã¾ãã $C_{rand}$ ä¸ã®ãã¯ãã«ï¼ã³ã¼ãï¼ã¯åä½è¶ çé¢ä¸ã«åå¸ãã¾ãã
ã¾ããæ§è³ªãç´äº¤è¡åã«ããå¤æã¯å ç©ãä¸å¤ã«ä¿ã¤ãã«ããããã®ç´äº¤è¡å $P$ ã«ããå°å½±ã§ã¯ä»»æã®ãã¯ãã«éã®å ç©ï¼è·é¢ï¼ãä¿åããã¾ãããã®ã©ã³ãã ç´äº¤å°å½±ã«ãããã¯ãã«ã®å¤æã¯ã1種㮠Johnson-Lindenstrauss Transformation[9][10] ã«ãªã£ã¦ãã¾ã[11]ã
ãã®ã©ã³ãã ç´äº¤è¡å $P$ ã¯ãåè¦ç´ ãä¹±æ°ã§åæåããè¡åã QR å解ãããã¨ã§è¨ç®ã§ãã¾ããRabitQ ã§ã¯ä»¥ä¸ã®ããã«å®è£ ããã¦ãã¾ãã[12]ã
G = np.random.randn(D, D).astype('float32')
Q, _ = np.linalg.qr(G)
return Q
ã³ã¼ããã㯠$C$ ã¯ã $\lbrace +\frac{1}{\sqrt{D}}, -\frac{1}{\sqrt{D}} \rbrace ^D$ ã®ããã«ããæå³æ£æçã«æ§æãããã®ã§ããããã® $P$ ã®ã©ã³ãã æ§ã«ããã決å®æ§ã®ã³ã¼ããã㯠$C$ ã® preference ãæé¤ãããã¨ãã§ãã¾ãã
$P$ ã¯ãããããå¤æã®ä¸ããã©ã³ãã ã«ãµã³ããªã³ã°ãããã®ã§ããã¤ã¾ãã $P$ ã«ããå¤æãããã³ã¼ããã㯠$C_{rand}$ ã¯ãåä½è¶ çé¢ä¸ã«ä¸æ§ã«ï¼ç確çã§ï¼åå¸ãããã¨ã«ãªãã¾ãã
ãã£ã¦ããã¼ã¿ãã¯ãã«ã«åãããã£ãã¨ãã¦ããéååï¼ã³ã¼ãåï¼ããéãããå¤æ§ãªã³ã¼ãã¸ã¨åæ£ãããã¨ãæå¾ ã§ãã¾ãã詳細ã¯å è«æ[1:3]ã® Section 3.1 ãåç §ãã¦ãã ããã
ãã¼ã¿ãã¯ãã«ã®éåå
ã³ã¼ããã㯠$C_{rand}$ ã®è¨ç®ãçµãã£ãã®ã§ããã®ä¸ããï¼æ£è¦åããï¼ãã¼ã¿ãã¯ãã« $\bm{o}$ ã«æãè¿ããã®ãæ¢ããããããã¼ã¿ãã¯ãã«ã®éååããã表ç¾ï¼ã³ã¼ãï¼ã¨ãã¾ãï¼ã¤ã³ããã¯ã¹ãã§ã¤ãºã®3çªç®ã®ã¹ãããã«ç¸å½ï¼ã
ã¦ã¼ã¯ãªããè·é¢ãæãè¿ããã¯ãã«ãæ¢ããã¨ã¯ãå ç©ãæã大ãããªããã¯ãã«ãæ¢ããã¨ã¨åå¤ã§ãããã®ãã¯ãã«ã $\overline{\bm{o}} = P \overline{\bm{x}} \in C_{rand}$ ã¨ãã¾ãããã®ãã¯ãã« $\overline{\bm{o}}$ ã® $P$ ã§ã®å°å½±åã®ãã¯ãã«ã $\overline{\bm{x}} \in C$ ã§ããããã¯ä»¥ä¸ã®ããã«æ¸ãã¾ãã
\[ \begin{align*} \overline{\bm{x}} &= \argmin_{\bm{x} \in C} \Vert \bm{o} - P \bm{x} \Vert^2 \\ &= \argmin_{\bm{x} \in C} (\Vert \bm{o} \Vert^2 + \Vert P \bm{x} \Vert^2 - 2 \langle \bm{o}, P\bm{x} \rangle) \\ &= \argmin_{\bm{x} \in C} (2 - 2 \langle \bm{o}, P \bm{x} \rangle) \\ &= \argmax_{\bm{x} \in C} \langle \bm{o}, P \bm{x} \rangle \end{align*} \]
ã¤ã¾ãã $\langle \bm{o}, P \bm{x} \rangle$ ãæ大ã«ãªããã㪠$\bm{x}$ ãæ±ãããããã§ããããã¯ããã«ä»¥ä¸ã®ããã«å¤å½¢ã§ãã¾ãã
\[ \langle \bm{o}, P \bm{x} \rangle = \langle P^{-1} \bm{o}, P^{-1} P \bm{x} \rangle = \langle P^{-1}\bm{o}, \bm{x} \rangle \]
人工çã«æ§æããã³ã¼ãããã¯ã®è¦ç´ $\bm{x} \in C$ ã®å次å ã®å¤ã¯ $\pm 1 / \sqrt{D}$ ã§ããããã¯ãã« $P^{-1} \bm{o}$ ã¨ã®å ç©ãæ大ã«ãªããã㪠$\bm{x}$ ã決ããã«ã¯ããã ãã¯ãã« $P^{-1} \bm{o}$ ã®å次å ã®å¤ã®ç¬¦å·ã ããè¦ãã°ãããã¨ããããã¾ã[13]ããããã®ç¬¦å·ãããããã°ã $\overline{\bm{x}}$ ããã 1ã¤ã«æ±ºå®ãããã¨ãã§ãã¾ãããã£ã¦ããããã®ç¬¦å·ã®åï¼é·ã $D$ ï¼ã $\overline{\bm{x}}_{b} \in \{ 0, 1 \}^D$ ã¨è¡¨ãããããã¤ã³ããã¯ã¹ã«ä¿åãã¾ãã
RaBitQ ã§ã¯ããã¼ã¿ãã¯ãã«ã¯ãã®ããã«éååãã¾ãããã®ããã«è¡¨ç¾ãããã¨ã§ãåãã¼ã¿ãã¯ãã«ã¯ $D$ ãããã¾ã§å°ãããªãã¾ããã¾ãã $\overline{\bm{x}} = ( 2 \overline{\bm{x}}_b - \bm{1}_D ) / \sqrt{D}$ ã«ãã£ã¦ãã¤ããªè¡¨ç¾ $\overline{\bm{x}}_b$ ããéååãããã¼ã¿ãã¯ãã« $\overline{\bm{x}}$ ã復å ãã¾ãã
ãã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®è·é¢
ãã¦ãè¿ä¼¼æè¿åæ¢ç´¢ã®åé¡ã¯ãã¯ã¨ãªãã¯ãã« $\bm{o_r}$ ã¨ãã¼ã¿ãã¯ãã« $\bm{q_r}$ ã®ã¦ã¼ã¯ãªããè·é¢ $\Vert \bm{o_r} - \bm{q_r} \Vert^2$ ãå°ãããã¼ã¿ãã¯ãã«ãæ¢ããã¨ã§ãããããã¯ãã¯ãã«ã®ãã«ã ã®æ§è³ª $\Vert \bm{x} - \bm{y}\Vert^2 = \Vert \bm{x} |^2 + \Vert \bm{y} \Vert^2 - 2 \cdot \langle \bm{x}, \bm{y} \rangle$ ã使ãã¨ãã»ã³ããã¤ã $\bm{c}$ ã使ã£ã¦ä»¥ä¸ã®ããã«å±éã§ãã¾ãã
\[ \begin{align} \Vert \bm{o_r} - \bm{q_r} \Vert^2 &= \Vert (\bm{o_r} - \bm{c}) - (\bm{q_r} - \bm{c}) \Vert^2 \\ &= \Vert \bm{o_r} - \bm{c} \Vert^2 + \Vert \bm{q_r} - \bm{c}\Vert^2 - 2 \cdot \langle \bm{o_r} - \bm{c}, \bm{q_r} - \bm{c} \rangle \end{align} \]
ãã¯ãã«ã®æ£è¦åã®ã¨ããã§è¿°ã¹ã¾ããããæ£è¦åãããã¼ã¿ãã¯ãã«ã¯ $\bm{o} := \frac{\bm{o_r} - \bm{c}}{\Vert\bm{o_r} - \bm{c}\Vert}$ ã§ãããã¾ããæ£è¦åããã¯ã¨ãªãã¯ãã«ã¯åæ§ã« $\bm{q} := \frac{\bm{q_r} - \bm{c}}{\Vert\bm{q_r} - \bm{c}\Vert}$ ã¨æ¸ãã¾ãããããã®å ç©ã¯ä»¥ä¸ã®ããã«æ¸ãã¾ãã
\[ \begin{align} \langle \bm{o}, \bm{q} \rangle &= \langle \frac{\bm{o_r} - \bm{c}}{\Vert \bm{o_r} - \bm{c} \Vert}, \frac{\bm{q_r} - \bm{c}}{\Vert \bm{q_r} - \bm{c} \Vert} \rangle \\ &= \frac{\langle \bm{o_r} - \bm{c}, \bm{q_r} - \bm{c} \rangle}{\Vert \bm{o_r} - \bm{c} \Vert \cdot \Vert \bm{q_r} - \bm{c} \Vert} \end{align} \]
(3) å¼ãã (4) å¼ã¸ã®å±éã«ã¯ãå ç©ã®æ§è³ª $\langle a \bm{x}, \bm{y} \rangle = a \langle \bm{x}, \bm{y} \rangle$ ã使ç¨ãã¾ããããã®é¢ä¿æ§ï¼ (4) å¼ï¼ã使ãã¨ã (2) å¼ã¯ä»¥ä¸ã®ããã«å¤å½¢ã§ãã¾ãã
\[ \begin{equation} \Vert \bm{o_r} - \bm{q_r} \Vert^2 = \Vert \bm{o_r} - \bm{c} \Vert^2 + \Vert \bm{q_r} - \bm{c} \Vert^2 - 2 \cdot \Vert \bm{o_r} - \bm{c} \Vert \cdot \Vert \bm{q_r} - \bm{c} \Vert \cdot \langle \bm{o}, \bm{q} \rangle \end{equation} \]
ãã®ããã«ãã¯ã¨ãªãã¯ãã« $\bm{o_r}$ ã¨ãã¼ã¿ãã¯ãã« $\bm{q_r}$ ã®ã¦ã¼ã¯ãªããè·é¢ $\Vert \bm{o_r} - \bm{q_r}\Vert^2$ ã¯ãããã¤ãã®ã³ã³ãã¼ãã³ãã«åé¢ã§ãã¾ãã
(5) å¼ã®æåã¨æå¾ã®é ã«ããããã $\Vert \bm{o_r} - \bm{c}\Vert$ ã¯ããã¼ã¿ãã¯ãã«ã¨ã»ã³ããã¤ãã®è·é¢ã§ããã»ã³ããã¤ãã¯ã¤ã³ããã¯ã¹æ§ç¯æã«è¨ç®æ¸ã¿ã®ãããããã¯äºåã«è¨ç®ã§ãã¾ããäºåè¨ç®ãã $\Vert \bm{o_r} - \bm{c} \Vert$ ã¯ã¤ã³ããã¯ã¹ã¨ä¸ç·ã«ä¿åãã¦ããã¾ãï¼ã¤ã³ããã¯ã¹ãã§ã¤ãºã®4çªç®ï¼ãã¾ããã¯ã¨ãªãã¯ãã«ã¨ã»ã³ããã¤ãã®è·é¢ $\Vert \bm{q_r} - \bm{c} \Vert$ ã¯æ¤ç´¢æã«1åã ãè¨ç®ããã°ãããããåé¡ã«ã¯ãªãã¾ããã
ã§ã¯ãæå¾ã®ã³ã³ãã¼ãã³ãã§ããå ç© $\langle \bm{o}, \bm{q} \rangle$ ã RaBitQ ãã©ãè¨ç®ããããè¦ã¦ããã¾ãã
ãã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®å ç©ã®æ¨å®
RabitQ ã§ã¯ãå ç© $\langle \bm{o}, \bm{q} \rangle$ ã®æ¨å®å¤ã¨ã㦠$\frac{\langle \overline{\bm{o}}, \bm{q} \rangle}{\langle \overline{\bm{o}}, \bm{o} \rangle}$ ã使ç¨ãã¾ãã
ãã¼ã¿ãã¯ãã« $\bm{o}$ ã¨ã¯ã¨ãªãã¯ãã« $\bm{q}$ ãå ±ç· (colinear) ã§ãããã¤ã¾ã $\bm{o} = \bm{q}$ ããã㯠$\bm{o} = - \bm{q}$ ã§ããã¨ãã $\langle \overline{\bm{o}}, \bm{q} \rangle = \langle \overline{\bm{o}}, \bm{o} \rangle \cdot \langle \bm{o}, \bm{q} \rangle$ ãæãç«ã¡ã¾ãï¼å ±ç·ã§ããã°ä»»æã®ãã¯ãã«ã«å¯¾ãã¦æãç«ã¤ï¼ããã®å ´åãå ç© $\langle \bm{o}, \bm{q} \rangle$ ã«ã¤ãã¦ã¯ç°¡åã«è§£ãã¦ã
\[ \begin{equation} \langle \bm{o}, \bm{q} \rangle = \frac{\langle \overline{\bm{o}}, \bm{q} \rangle}{\langle \overline{\bm{o}}, \bm{o} \rangle} \end{equation} \]
ã¨ãªãã¾ãããããæ¨å®å¤ã¨ãã¦ä½¿ãã¾ããå ±ç·ã§ãªãã¨ãã«ã¯ãã¡ãã誤差ãåºã¾ããããã®èª¤å·®ã¯ $O(1 / \sqrt{D})$ 以ä¸ï¼ $D$ ã¯ãã¼ã¿ãã¯ãã«ã»ã¯ã¨ãªãã¯ãã«ã®æ¬¡å æ°ï¼ã§ãããã㤠unbiased[14] ã«ãªããã¨ãè«æä¸[1:4]ã® Section 3.2 ã§è¨¼æããã¦ãã¾ãã
$\langle \overline{\bm{o}}, \bm{o} \rangle$ ã¯ãã¼ã¿ãã¯ãã«ã ãããäºåã«è¨ç®ã§ããããããããã¤ã³ããã¯ã¹ã«ä¿åãã¦ããã¾ãï¼ã¤ã³ããã¯ã¹ãã§ã¤ãºã®4çªç®ã®ã¹ãããï¼[15]ã $\langle \overline{\bm{o}}, \bm{q} \rangle$ ã®è¨ç®ã«ã¤ãã¦ã¯å¾è¿°ãã¾ãã
RabitQ ã®ã¤ã³ããã¯ã¹ãã§ã¤ãº
ããã§ãRabitQ ã§ã®ãã¼ã¿ãã¯ãã«ã®éååã»ã¤ã³ããã·ã³ã°ãã¾ã¨ãã¦ããã¾ãããï¼åæ²ï¼ã
- ã»ã³ããã¤ã $\bm{c}$ ãè¨ç®ãããã¹ã¦ã®ãã¼ã¿ãã¯ãã«ãæ£è¦åï¼$\bm{o_r}$ ã $\bm{o}$ ã«ããï¼
- ã©ã³ãã ãªç´äº¤è¡å $P$ ããµã³ããªã³ã°ããã³ã¼ããã㯠$C_{rand}$ ãæ§ç¯
- éååããããã¼ã¿ãã¯ãã« $\overline{\bm{x}}_b$ ãè¨ç®ï¼ã³ã¼ãããã¯ã®ä¸ããé¸ã¶ï¼
- 以ä¸ãäºåè¨ç®
- ãã¼ã¿ãã¯ãã«ã¨ã»ã³ããã¤ãã¨ã®è·é¢ $\Vert \bm{o}_r - \bm{c} \Vert$
- éååããããã¼ã¿ãã¯ãã«ã¨æ£è¦åãããã¼ã¿ãã¯ãã«ã®å ç© $\langle \overline{\bm{o}}, \bm{o}\rangle$ ï¼ãªãã·ã§ã³ï¼
ã¤ã³ããã¯ã¹ã«ã¯ä»¥ä¸ã®æ å ±ãä¿åãã¾ãã
- ã»ã³ããã¤ã $\bm{c}$
- éååããããã¼ã¿ãã¯ãã« $\overline{\bm{x}}_b$ ï¼ãã¼ã¿ãã¯ãã«ãã¨ã« $D$ ãããï¼
- åãã¼ã¿ãã¯ãã«ã¨ã»ã³ããã¤ãã¨ã®è·é¢ $\Vert \bm{o}_r - \bm{c}\Vert$
- éååããããã¼ã¿ãã¯ãã«ã¨æ£è¦åãããã¼ã¿ãã¯ãã«ã®å ç© $\langle \overline{\bm{o}}, \bm{o}\rangle$ ï¼ãªãã·ã§ã³ï¼
ãã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®å ç©ã®è¿ä¼¼è¨ç®
ãã¦ããã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®å ç©ï¼(6) å¼ï¼ãè¨ç®ããããã«ã¯ãæ®ã $\langle \overline{\bm{o}}, \bm{q} \rangle$ ãè¨ç®ããã°ãããªãã¾ãããããã¯ã©ã³ãã å°å½± $P$ ã使ãã¨ã以ä¸ã®ããã«å¤å½¢ã§ãã¾ãã
\[ \begin{equation} \langle \overline{\bm{o}}, \bm{q} \rangle = \langle P \overline{\bm{x}}, \bm{q} \rangle = \langle P^{-1} P \overline{\bm{x}}, P^{-1} \bm{q} \rangle = \langle \overline{\bm{x}}, \bm{q}\rq \rangle \end{equation} \]
ããã§ã $\overline{\bm{x}}$ ã¯éååå¾ã®ãã¼ã¿ãã¯ãã«ã§ããã¾ãã便å©ã®ããã« $\bm{q}\rq = P^{-1} \bm{q}$ ã¨ããã¾ããã
ã¯ã¨ãªãã¯ãã«ã®éåå
ãã¨ã㨠(6) å¼ã¯è¿ä¼¼ã§ãããã (7) å¼ãæ£ç¢ºãªå¤ãè¨ç®ããå¿ è¦ã¯ãªããä¸å®ã®èª¤å·®ã許容ããè¿ä¼¼å¤ã§ä»£ç¨ã§ãã¾ããRaBitQ ã§ã¯ $\bm{q}\rq$ ã®ä»£ããã«ããããéååãããã®ã使ã£ã¦è¨ç®ãå¹çåãã¦ãã¾ãããã ã 1 ãããã§ã¯ãªãã誤差ãæããããã« $B_q$ ãããã§éååãã¾ãï¼é対称ãªéååï¼ã
$\bm{q}\rq$ ãéååãããã®ã $\overline{\bm{q}}$ ã¨ãã¾ããããåã®ã»ã¯ã·ã§ã³ã§ $\langle \overline{\bm{x}}, \bm{q}\rq \rangle$ ãè¨ç®ãããã¨ãã話ããã¾ãããã $\langle \overline{\bm{x}}, \overline{\bm{q}} \rangle$ ããã®è¿ä¼¼ã¨ãã¦ä½¿ãã¾ãã
- $v_l \coloneqq \min_{1 \leq i \leq D} \bm{q}\rq[i]$ ï¼ $\bm{q}\rq$ ã®æå°å¤ï¼
- $v_r \coloneqq \max_{1 \leq i \leq D} \bm{q}\rq[i]$ï¼ $\bm{q}\rq$ ã®æ大å¤ï¼
- $\Delta \coloneqq (v_r - v_l) / (2^{B_q} - 1)$ ï¼éååã®å»ã¿å¹ ï¼
- $u_i$ ã $[0, 1]$ ã®ä¸æ§åå¸ãããµã³ããªã³ã°ããå¤
ã¨ããã¨ããRaBitQ ã§ã¯ $\overline{\bm{q}}$ ã®ãã¤ããªè¡¨ç¾ $\overline{\bm{q}}_u$ ï¼ã® $i$ çªç®ã®è¦ç´ ï¼ã以ä¸ã®å¼ã§è¨ç®ãã¾ãã
\[ \begin{equation} \overline{\bm{q}}_u [i] \coloneqq \lfloor \frac{\bm{q}\rq[i] - v_l}{\Delta} + u_i \rfloor \end{equation} \]
ãã®è¨ç®ã¯ç´æçã«ã¯ãé¢æ£åããã¨ãã«ãå·¦ãã®é¢æ£å¤ã«ããããå³ãã®é¢æ£å¤ã«ãããã 1/2 ã®ç¢ºçã§é¸ãã§ãããã¨ã«ãªãã¾ãããããããã¨ã«ãããå¤ã®åå¸ã«ä¾åããã« unbiased ã«ãããã¨ãã§ãã¾ã[16]ã
ãã¤ããªè¡¨ç¾ $\overline{\bm{q}}_u$ ãã $\overline{\bm{q}}$ ã復å ããã«ã¯ã $\overline{\bm{q}} = \Delta \cdot \overline{\bm{q}}_u + v_l \cdot \bm{1}_D$ ï¼ $\bm{1}_D$ ã¯ãã¹ã¦ 1 ãç«ã£ã¦ããããããã¯ãã«ï¼ã¨ããã°OKã§ãã
ã¯ã¨ãªãã¯ãã«ã®ãããæ° $B_q$ ã $\Theta (\log \log D)$ ã¨ããã¨ããé«ã確çã§è¿ä¼¼ã«ããéåå誤差 $| \langle \overline{\bm{x}}, \bm{q}\rq \rangle - \langle \overline{\bm{x}}, \overline{\bm{q}} \rangle |$ ã $O(1/ \sqrt{D})$ ã«åã¾ããã¨ãè«æä¸ã§è¨¼æããã¦ãã¾ãï¼Theorem 3.3[1:5]ï¼ãã¾ãå®é¨çã«ãã $D = 128$ ï¼SIFTãã¼ã¿ã»ããï¼ã $D = 960$ ï¼GISTãã¼ã¿ã»ããï¼ã®å ´åã«ã $B_q = 4$ ã¾ã§å¢ããã¨èª¤å·®ãååã«å°ããåæãããã¨ã示ããã¦ãã¾ãï¼Fig. 6[1:6]ï¼ã
éååãããã¼ã¿ãã¯ãã«ã¨ã¯ã¨ãªãã¯ãã«ã®å ç©è¨ç®
ãã¦ããã¼ã¿ãã¯ãã«ã®ãã¤ããªè¡¨ç¾ $\overline{\bm{x}}_b$ ã¨ã¯ã¨ãªãã¯ãã«ã®ãã¤ããªè¡¨ç¾ $\overline{\bm{q}}_u$ ãå¾ãã¨ããã§ãããã使ã£ã¦åè¿°ãã $\langle \overline{\bm{x}}, \overline{\bm{q}} \rangle$ ãè¨ç®ããã®ã次ã®é¢å¿äºã«ãªãã¾ãããããå¹ççã«è¨ç®ããããã«ããããæ¼ç®ãå©ç¨ã§ããå½¢ã«å¤å½¢ãã¦ããã¾ãã
$\overline{\bm{x}} = ( 2 \overline{\bm{x}}_b - \bm{1}_D ) / \sqrt{D}$ ã $\overline{\bm{q}} = \Delta \cdot \overline{\bm{q}}_u + v_l \cdot \bm{1}_D$ ã§ããããã $\langle \overline{\bm{x}}, \overline{\bm{q}} \rangle = \left\langle \frac{2 \overline{\bm{x}}_b - \bm{1}_D}{\sqrt{D}}, \Delta \cdot \overline{\bm{q}}_u + v_l \cdot \bm{1}_D \right\rangle$ ã§ããããã¯ããã«ã
\[ \begin{equation} \langle \overline{\bm{x}}, \overline{\bm{q}} \rangle = \frac{2 \Delta}{\sqrt{D}} \langle \overline{\bm{x}}_b, \overline{\bm{q}}_u \rangle + \frac{2 v_l}{\sqrt{D}} \sum_i^D \overline{\bm{x}}_b [i] - \frac{\Delta}{\sqrt{D}} \sum_i^D \overline{\bm{q}}_u [i] - \sqrt{D} \cdot v_l \end{equation} \]
ã¨ããå½¢ã«å±éã§ãã¾ãããã®ç¬¬ 2 é ã«è¡¨ãã $\sum_i \overline{\bm{x}}_b \lbrack i \rbrack$ ã¯ããã®ããããã¯ãã«ã® 1 ã®ç«ã£ã¦ããæ°ã§ãããã¤ã³ããã¯ã¹ãã§ã¤ãºã«äºåè¨ç®ã§ãã¾ãã
ã¾ãã $D$ ã¯åºå®å¤ã§ããã $\Delta$ ã $v_l$ ã¯ã¯ã¨ãªãã¯ãã«ã®éååæã«ãã§ã«è¨ç®ããã¦ãã¾ããåæ§ã«ç¬¬3é ã® $\sum^D \overline{\bm{q}}_{u} [i]$ ãã¯ã¨ãªæã«ä¸åº¦ã ãè¨ç®ããã°ãããè¨ç®ã³ã¹ãã¯ã»ã¨ãã©ãããã¾ãããã¤ã¾ãã第1é ã® $\langle \overline{\bm{x}}_b, \overline{\bm{q}}_u \rangle$ ãã©ãå¹ççã«è¨ç®ãããã主ãªé¢å¿ã«ãªãã¾ãã
SIMD ã«ããå ç©è¨ç®ã®é«éå
ããã§ã $D$ 次å ã®ã¯ã¨ãªãã¯ãã«ã®ãã¤ããªè¡¨ç¾ $\overline{\bm{q}}_u$ ã 4 ãããï¼ $B_q = 4$ ï¼ã¨ãã¦ããã¼ã¿ãã¯ãã«ã®ãã¤ããªè¡¨ç¾ $\overline{\bm{x}}_b$ ã¨ã®å ç©è¨ç®ãèãã¦ã¿ã¾ããããFig. 2 ã®å·¦å³ã®ç¹ç·ãã¯ã¨ãªã®1ã¤ã®æ¬¡å ã§ãï¼4 ããã表ç¾ï¼ãã¯ã¨ãªã¯ $4D$ ãããã§è¡¨ç¾ããããã¨ã«ãªããåã»ã«ã¯ 0/1 ã®ãã¤ããªã®å¤ã§ãã
å ç©ã®å¤ã¯1次å ãã¤è¨ç®ã§ã㦠$\langle \overline{\bm{x}}_b, \overline{\bm{q}}_u \rangle = ( {\overline{\bm{q}}_u}^{(0)} [1] \cdot 2^0 + {\overline{\bm{q}}_u}^{(1)} [1] \cdot 2^1 + {\overline{\bm{q}}_u}^{(2)} [1] \cdot 2^2 + {\overline{\bm{q}}_u}^{(3)} [1] \cdot 2^3 ) + \cdots$ ã¨ãªãã¾ããä¸æ¹ãå ç®ã¯äº¤æã§ããã®ã§ã0ãããç®ãã4ãããç®ã¾ã§ãå¥ã ã«è¨ç®ãããã¨ãã§ãã¾ããã¤ã¾ãã $\langle \overline{\bm{x}}_b, \overline{\bm{q}}_u \rangle = ( {\overline{\bm{q}}_u}^{(0)} [1] \cdot 2^0 + {\overline{\bm{q}}_u}^{(0)} [2] \cdot 2^0 + {\overline{\bm{q}}_u}^{(0)} [3] \cdot 2^0 + {\overline{\bm{q}}_u}^{(0)} [4] \cdot 2^0 + \cdots ) + \cdots$ ã§è¨ç®ãããã¨ãã§ãã¾ãï¼Fig. 2 å³å³ï¼ã
ãããããã¨ã§ãåããããã¯ãã« ${\overline{\bm{q}}_u}^{(0)}$ ã ${\overline{\bm{q}}_u}^{(1)}$ ã ${\overline{\bm{q}}_u}^{(2)}$ ã ${\overline{\bm{q}}_u}^{(3)}$ 㨠${\overline{\bm{x}}_b}$ ã®è«çç©ï¼ANDï¼ãã¨ã£ããã¨ã1ãç«ã£ã¦ããæ°ãã«ã¦ã³ãããç©åæ¼ç®ï¼ãããã 1, 2, 4, 8 ãæãã¦è¶³ãï¼ãããã¨ã§å ç©ãæ±ã¾ãã¾ãã
ãã㯠SIMD æ¼ç®ã§å¹ççã«è¨ç®ãããã¨ãã§ããã¨ãã«ããããæ°ããã¹ããã㯠popcount ã¨ãã¦ç¥ãããå°ç¨ã®å½ä»¤ã使ç¨ãããã¨ã§é«éã«è¨ç®ã§ãã¾ãããã¨ãã° SSE ã AVX ã§ã¯ POPCNT ã¨å¼ã°ããå½ä»¤ç¾¤ãç¨æããã¦ãã¾ãã
è«æ[1:7]ã® Section 3.3.2 ã§ã¯ããã«ãè¤æ°ã®ãã¼ã¿ãã¯ãã«ããããã§å¦çãããã¨ã§ã¯ã¨ãªãé«éåããæ¹æ³ã«ã¤ãã¦ãè¿°ã¹ããã¦ãã¾ãã
å ç©è¨ç®ã®æé©åã®å ·ä½ä¾
ãã®å
ç©è¨ç®ãããå°ãå
·ä½çã«è¦ã¦ã¿ã¾ãããã以ä¸ã¯ã¯ã¨ãªãã¯ãã«ã [8, 15, 10, 7, 4, 0, 9, 9]
ã®ã¨ãã®ä¾ã§ã[17]ã
è¦ç´ ã¯ãããã 4 ãããã§è¡¨ç¾ããã¦ãã¾ããã¯ã¨ãªãã¯ãã«ã¯ 8 次å
ãã¨ã«åå²ãã¾ãï¼8x4 = 32 ãããåä½ï¼ããã®ä¾ã§ã¯ 8 次å
ã¡ããã©ãªã®ã§ãã®ã¾ã¾ã§ãã次ã«ã8 åã® 4 ãããã®åä½ç½®ã®ãããï¼0 ãããç®ãã 4 ãããç®ã¾ã§ï¼ãåãåºãã4 ã¤ã® int8
ã«å¤æãã¾ãã
ãã¼ã¿ãã¯ãã«ã¯ 1 ããããã¯ã¨ãªãã¯ãã«ã¯ 4 ãããã§éååãããã®ã§ãããéååããããã¼ã¿ãã¯ãã«ã [0, 1, 1, 0, 0, 0, 0, 0]
ãã¯ã¨ãªãã¯ãã«ã [8, 15, 10, 7, 4, 0, 9, 9]
ã¨ãã¦ããã®å
ç©ãè¨ç®ãã¦ã¿ã¾ãããã
æ®éã«è¨ç®ããã¨ã 0 * 8 + 1 * 15 + 1 * 10 + 0 * 7 + 0 * 4 + 0 * 0 + 0 * 9 + 0 * 9 == 15 + 10 == 25
ã§ããããã®å
ç©è¨ç®ããããæ¼ç®ãå©ç¨ãã¦é«éåãã¾ãã
éååãããã¯ã¨ãªãã¯ãã« [8, 15, 10, 7, 4, 0, 9, 9]
ã®ãã¤ããªè¡¨ç¾ã¯ãå
é ãã
0b1000
(=8
)0b1111
(=15
)0b1010
(=10
)0b0111
(=7
)0b0100
(=4
)0b0000
(=0
)0b1001
(=9
)0b1001
(=9
)
ã§ããããã¼ã¿ãã¯ãã«ã 1
ã®æ¬¡å
ã ãè¨ç®ããã°ããã®ã§ã2çªç® (0b1111 = 15
) ã¨3çªç® (0b1010 = 10
) ã足ãã°çã (0b1111 + 0b1010 = 25
) ãæ±ã¾ãã¾ãããã®è¨ç®ããããæ¼ç®é¢¨ã«è¡¨ç¾ãã㨠(1 + 1) << 3 + (1 + 0) << 2 + (1 + 1) << 1 + (1 + 0) << 0 == 2 * (2**3) + 1 * (2**2) + 2 * (2**1) + 1 * (2**0) == 25
ã§ãã
ã¤ã¾ãããã¼ã¿ãã¯ãã« 0, 1, 1, 0, 0, 0, 0, 0]
ã§ãã¹ã¯ãããã¨ï¼2çªç®ã¨3çªç®ã ããæ®ãï¼ãåãããä½ç½®ãã¨ã«ãããæ°ãã«ã¦ã³ãããæçµçãªçµæãè¨ç®ããã°ããããã§ãããããã®è¨ç®ã¯ãè«çç© (AND)ããããã«ã¦ã³ãããããã·ãããããã¦å ç®ã®ã¿ã§è¨ç®ã§ãã¾ãã
ãã®ããã«ãç°ãªããããæ°ã®ãã¯ãã«å士ã®å ç©è¨ç®ããç°¡åãªãããæ¼ç®ã«å¸°çããããã¨ãã§ãã¾ãã
RaBitQ ã®ã¯ã¨ãªãã§ã¤ãº
ããã¾ã§ããããããã¾ããã¤ã³ããã¯ã¹ã«ã¯ä»¥ä¸ã®æ å ±ãä¿åããã¦ãã¾ãï¼
- ã»ã³ããã¤ã $\bm{c}$
- éååããããã¼ã¿ãã¯ãã« $\overline{\bm{x}}_b$ ï¼ãã¼ã¿ãã¯ãã«ãã¨ã« $D$ ãããï¼
- åãã¼ã¿ãã¯ãã«ã¨ã»ã³ããã¤ãã¨ã®è·é¢ $\Vert \bm{o}_r - \bm{c}\Vert$
- éååããããã¼ã¿ãã¯ãã«ã¨æ£è¦åãããã¼ã¿ãã¯ãã«ã®å ç© $\langle \overline{\bm{o}}, \bm{o}\rangle$ ï¼ãªãã·ã§ã³ï¼
è¨ç®ãããã®ã¯çã®ãã¼ã¿ãã¯ãã« $\bm{o_r}$ ã¨ã¯ã¨ãªãã¯ãã« $\bm{q_r}$ ã®è·é¢ã§ããã (5) å¼ãæãåºãã¦ãã ããã
\[ \begin{equation*} \Vert \bm{o_r} - \bm{q_r} \Vert^2 = \Vert \bm{o_r} - \bm{c} \Vert^2 + \Vert \bm{q_r} - \bm{c} \Vert^2 - 2 \cdot \Vert \bm{o_r} - \bm{c} \Vert \cdot \Vert \bm{q_r} - \bm{c} \Vert \cdot \langle \bm{o}, \bm{q} \rangle \end{equation*} \]
$\Vert \bm{o}_r - \bm{c}\Vert$ ã¯ã¤ã³ããã¯ã¹ã«ä¿åããã¦ãã¾ããã $\bm{c}$ ãä¿åããã¦ãããã $\Vert \bm{q_r} - \bm{c}\Vert$ ãã¯ã¨ãªæã«ç´ã¡ã«è¨ç®ã§ãã¾ããæ®ã $\langle \bm{o}, \bm{q} \rangle$ 㯠(6) å¼ã§è¿ä¼¼ããã®ã§ããï¼
\[ \begin{equation*} \langle \bm{o}, \bm{q} \rangle = \frac{\langle \overline{\bm{o}}, \bm{q} \rangle}{\langle \overline{\bm{o}}, \bm{o} \rangle} \end{equation*} \]
å ç© $\langle \overline{\bm{o}}, \bm{o}\rangle$ ã¯ã¤ã³ããã¯ã¹ã«ä¿åããã¦ããããããã使ãã¾ã[18]ãå ç© $\langle \overline{\bm{o}}, \bm{q}\rangle$ 㯠$\langle \overline{\bm{x}}, \overline{\bm{q}} \rangle$ ã§è¿ä¼¼ããã®ã§ããã(9) å¼ãæãåºãã¾ãã
\[ \begin{equation*} \langle \overline{\bm{x}}, \overline{\bm{q}} \rangle = \frac{2 \Delta}{\sqrt{D}} \langle \overline{\bm{x}}_b, \overline{\bm{q}}_u \rangle + \frac{2 v_l}{\sqrt{D}} \sum_i^D \overline{\bm{x}}_b [i] - \frac{\Delta}{\sqrt{D}} \sum_i^D \overline{\bm{q}}_u [i] - \sqrt{D} \cdot v_l \end{equation*} \]
åè¿°ããéãã第2é 以éã¯ç´ ç´ã«è¨ç®ãã¦ãããã»ã©ã³ã¹ãã¯ãããã¾ããã第1é ã®å ç© $\langle \overline{\bm{x}}_b, \overline{\bm{q}}_u \rangle$ ã¯ããã¼ã¿ãã¯ãã«ãã¨ã«ãããæ¼ç®ã¨ SIMD ã§è¨ç®ãã¾ãã
以ä¸ãã¾ã¨ããã¨ãRaBitQ ã®ã¯ã¨ãªãã§ã¤ãºã¯ä»¥ä¸ã®éãã§ãï¼åæ²ï¼ã
- ã¯ã¨ãªãã¯ãã«ãæ£è¦åã»å¤æ
- 1.ã®ã¯ã¨ãªãã¯ãã«ãéåå
- åãã¼ã¿ãã¯ãã«ã«å¯¾ãã¦ä»¥ä¸ãè¨ç®
- $\frac{\langle \bm{\overline{o}}, \bm{q}\rangle}{\langle \bm{\overline{o}}, \bm{o}\rangle}$ ãè¨ç®ï¼$\langle \bm{o}, \bm{q}\rangle$ ã®è¿ä¼¼å¤ã¨ãã¦ä½¿ç¨ããï¼
- å ã®ã¯ã¨ãªãã¯ãã«ã¨ãã¼ã¿ãã¯ãã«ã®è·é¢ã®æ¨å®å¤ãè¨ç®ï¼(5) å¼ããï¼
RaBitQ 㨠ANN
ã¯ã¨ãªãã§ã¤ãºã®ãã¼ã¿ãã¯ãã«ãã¨ã«è¨ç®ããé¨åï¼æ¬ä¼¼ã³ã¼ãã®3è¡ç®ãã5è¡ç®ï¼ã¯ãåè¿°ãã IVF ã¨ãã£ã ANN ã®ææ³ãä½µç¨ãã¦é«éåã§ãã¾ãï¼Section 4 ãåç §ï¼ãRaBitQ ã§ã¯ããããã§ã®ã¯ã¨ãªãã§ã¤ãºã®è¨ç®ãå°é£ã¨ããçç±ã§ãHNSW ã®ãããªã°ã©ããã¼ã¹ã®ææ³ã§ã¯ãªãã IVF ã使ã£ã¦ ANN ã«ããé«éåãè¡ã£ã¦ãã¾ãã
RaBitQ ã§ã¯ IVF ã®ã¤ã³ããã¯ã¹ãããã¼ã¿ãã¯ãã«ãå¤ãã«åå¾ãããªã©ã³ãã³ã°ãã¾ããRaBitQ ã§ã¯èª¤å·®ã®ä¸éãè¨ç®ã§ããããããããå©ç¨ãã¦ãªã©ã³ã¯å¯¾è±¡ã®ãã¼ã¿ãã¯ãã«ã®æ°ã調æ´ãã¾ãã
RaBitQ ã®æ¡å¼µ
RaBitQ ã¯ãã¼ã¿ãã¯ãã«ã 1 ãããã§è¡¨ç¾ããææ³ã§ããããããè¤æ°ãããã«æ¡å¼µãããã¨ã§ããã«èª¤å·®ãä¸ããææ³ Extended RaBitQ[19] ãææ¡ããã¦ãã¾ãããã®ææ³ã«ã¤ãã¦ã¯ä»¥ä¸ã®ããã°ãã¹ããåèã«ãªãã§ãããã
Extended RaBitQ: an Optimized Scalar Quantization Method
BBQ
BBQ (Better Binary Quantization) ã¯ãElastic ã§éçºããããããéååææ³ã§ããRaBitQ ããçæ³ãå¾ã¦éçºãããã¨ã®ãã¨ã§ãã
- RaBitQ binary quantization 101 - Elasticsearch Labs
- Better Binary Quantization (BBQ) in Lucene and Elasticsearch - Elasticsearch Labs
- Smokin' fast BBQ with hardware accelerated SIMD instructions - Elasticsearch Labs
- Better Binary Quantization vs. Product Quantization - Elasticsearch Labs
Elasticsearch ã§ã®å©ç¨æ¹æ³
Elasticsearch 8.16 以éãBBQ ã dense_vector
ãã£ã¼ã«ãã¨ãã¦ä½¿ç¨ã§ããããã« Elasticsearch ã«çµã¿è¾¼ã¾ãã¦ãã¾ãã dense_vector
ãã£ã¼ã«ãã® mapping å®ç¾©ã§ã index_options.type
ã«ä»¥ä¸ã®ãããããè¨å®ãããã¨ãã§ãã¾ãï¼
bbq_hnsw
ï¼ã°ã©ããã¼ã¹ã® HNSW 㧠ANN ã®ãã¼ã¿ãã¯ãã«ãåå¾ï¼bbq_flat
ï¼ãã«ã¼ããã©ã¼ã¹ã§ kNN ã®ãã¼ã¿ãã¯ãã«ãåå¾ï¼
{
"mappings": {
"properties": {
"my_vector": {
"type": "dense_vector",
"dims": 64,
"index": true,
"index_options": {
"type": "bbq_hnsw"
}
}
}
}
}
詳細ã¯å ¬å¼ããã¥ã¡ã³ããåç §ãã¦ãã ããã
BBQ ã«ãããã¼ã¿ãã¯ãã«ã®éåå
BBQ ã§ã¯ RaBitQ ã¨åæ§ã«ããã¼ã¿ãã¯ãã«ã®å次å ã1ãããã«éååãã¾ãã
ãã¼ã¿ãã¯ãã«ã®ã»ã³ããã¤ãã¯äºåã«è¨ç®ãã¦ããç¹ãåæ§ã§ããã»ã³ããã¤ãã®è¨ç®ã¯ããã¼ã¿ãã¯ãã«ãå ¥ã£ã¦ãããã³ã«ã¤ã³ã¡ã¢ãªã§ã¤ã³ã¯ãªã¡ã³ã¿ã«ã«å®è¡ã§ããã®ã§ãã¤ã³ããã¯ã¹æ§ç¯æã«ã¯ãã§ã«è¨ç®ãçµãã£ã¦ãã¾ãã
ãã¼ã¿ãã¯ãã«ã¯ä»¥ä¸ã®ããã« 8 次å åä½ã§éååãã¾ã[17:1]ã
- ãã¼ã¿ãã¯ãã«ããã»ã³ããã¤ããå¼ãï¼æ£è¦åï¼
- 1ã®ãã¯ãã«ã®å次å
ã®å¤ã 0 ãã大ãããã°
1
ãããã§ãªããã°0
ã«éåå - corrections ãäºåè¨ç®
- ãã¼ã¿ãã¯ãã«ããã»ã³ããã¤ãã®è·é¢ï¼1 ã§è¨ç®æ¸ã¿ï¼
- å ã®ãã¼ã¿ãã¯ãã«ã¨ãéååå¾ã®ãã¯ãã«ã®å ç©ï¼ã©ã®ãããé¢ãã¦ãããï¼
BBQ ã§ã®è·é¢æ¨å®
corrections ã¯æ¤ç´¢æã«éååã«ãã£ã¦å¤±ãããæ å ±ãã復å ãããã¯ã¨ãªãã¯ãã«ã¨ãã¼ã¿ãã¯ãã«ã®è·é¢ãããæ£ç¢ºã«æ¨å®ããããã«ä½¿ãã¾ãããã®ããã㯠RaBitQ ã¨åæ§ã®è¨ç®ãã¦ããããã§ããããã«è©³ãã解説ã¯ä»¥ä¸ã®ããã°ãåç §ãã¦ãã ããã
BBQ ã®ãã¤ããªãã©ã¼ããã
BBQ ã Lucene ã¤ã³ããã¯ã¹ã«ä¿åãããã¨ãã®ãã¤ããªãã©ã¼ãããã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ã[17:2]ã
éååããããã¼ã¿ãã¯ãã«ã¯ 8 次å
ã㤠pack ããã¾ãã8次å
ãã¨ã«éååãããããããã¾ã¨ã㦠byte ã¨ãã¦ä¿åãã¾ãããã®ç´å¾ã« corrections ï¼é·ã 2 ãã 3 ã® float
ã®é
åï¼ãç½®ãå½¢ã«ãªã£ã¦ãã¾ãã
BBQ ã®ã¤ã³ããã¯ã¹æ§ç¯ã®å®è£
ã¤ã³ããã¯ã¹ã¸ã®æ¸ãè¾¼ã¿ã®å®è£ ã¯ãã®ãããã§ãï¼
- https://github.com/elastic/elasticsearch/blob/6c2f6071b20633fafc383212331f79146613011b/server/src/main/java/org/elasticsearch/index/codec/vectors/es816/ES816BinaryQuantizedVectorsWriter.java#L147-L216
- quantizeForIndex https://github.com/elastic/elasticsearch/blob/6c2f6071b20633fafc383212331f79146613011b/server/src/main/java/org/elasticsearch/index/codec/vectors/es816/BinaryQuantizer.java#L245-L300
- generateSubSpace https://github.com/elastic/elasticsearch/blob/6c2f6071b20633fafc383212331f79146613011b/server/src/main/java/org/elasticsearch/index/codec/vectors/es816/BinaryQuantizer.java#L98-L114
è·é¢ (similarity) ãã¦ã¼ã¯ãªãããã«ã ã®å ´åã®æµããã¾ã¨ãã¦ã¿ãã¨ã以ä¸ã®ããã«ãªãã¾ãã
- ãã¼ã¿ãã¯ãã«ã¨ã»ã³ããã¤ãã®è·é¢ãè¨ç®
- ãã¼ã¿ãã¯ãã«ããã»ã³ããã¤ããå¼ãï¼ãæ£è¦åãï¼
- ï¼éåååå¾ã®ãã¼ã¿ãã¯ãã«ã®ãã«ã ï¼å ç©ï¼ãè¨ç®ï¼
- ãã¼ã¿ãã¯ãã«ãéååãã¦æ¸ãè¾¼ã¿ï¼0ãã大ãããã°
1
ï¼ - ï¼3ã§è¨ç®ãããã«ã ã¨ãã¼ã¿ãã¯ãã«ããprojection? ãè¨ç®ï¼
- ä¸è¨1ã¨5ã§è¨ç®ãããã®ã correctionsï¼2ã¤ã® float ã®å¤ï¼ã¨ãã¦ä¿å
BBQ ã®ã¯ã¨ãªå¦ç
BBQ ã§ã¯ RaBitQ ã¨åæ§ããã¼ã¿ãã¯ãã«ã®å次å
ã 1 ãããã«ãã¯ã¨ãªãã¯ãã«ã¯å次å
ã 4 ãããã® int4
ï¼0 ãã 15 ã®ç¯å²ï¼ã«ã¹ã«ã©éååãã精度ã®åä¸ãçã£ã¦ãã¾ããBBQ ã§ã¯ã¯ã¨ãªãã¯ãã«ã¨ãã¼ã¿ãã¯ãã«ã®å
ç©ãæé©åãããããã¯ã¨ãªãã¯ãã«ã 8 次å
ãã¨ã«ãããã並ã¹æ¿ãã¾ãã
ãã³ããã¼ã¯
PQ 㨠BBQ ãæ¯è¼ããçµæã以ä¸ã®ããã°ã§å ¬éããã¦ãã¾ãã
PQ ã¨æ¯è¼ããã¨ãBBQ ã¯ã¤ã³ããã¯ã¹æ§ç¯æéãã¬ã¤ãã³ã·ãããªãçãã精度 (recall) ãå ãã§ããè¯ãããã§ãã
ã¾ã¨ã
ãã®è¨äºã§ã¯ãANN ã§ã®ãã¯ãã«éååææ³ã§ãã RaBitQ ã¨ãElasticsearch ã® BBQ (Better Binary Quantization) ãç´¹ä»ãã¾ããã
RaBitQ 㨠BBQ ã®ä¸»ãªéãã¯ãBBQ ã§ã¯ã©ã³ãã å°å½± $P$ ã使ã£ã¦ããªãã¨ããç¹ã§ã[20]ãããã¯ãã¼ã¿ãã¯ãã«ã®åå¸ã«ãã£ã¦ã¯éåå誤差ã大ãããªã£ã¦ãã¾ããã¨ãæå³ãã誤差ã®ä¸éãä¿è¨¼ãããã¨ãã§ãã¾ãããè«æã®çé èè ã§ãã Gao ã«ãã以ä¸ã®è¨äºã¯ãRaBitQ ãé«ç²¾åº¦ãéæã§ããç´æçãªçç±ã解説ããã¦ãã¾ãã
ã¾ããANN ãä½µç¨ãã BBQ ï¼ bbq_hnsw
ï¼ã§ã¯ã°ã©ããã¼ã¹ã¢ã«ã´ãªãºã ã® HNSW ãå©ç¨ããããã誤差ä¸éãå©ç¨ãããªã©ã³ãã³ã°ãå©ç¨ãããã¨ãã§ãã¾ããï¼ãããã誤差ä¸éã®ä¿è¨¼ãããã¾ãããï¼ã
Elasticsearch ã® BBQ ã¯ãRaBitQ ã®ã©ã³ãã å°å½±ã¨ãªã©ã³ãã³ã°ãåãå ¥ãããã¨ã§ãããã«ç²¾åº¦ã»é度ã®åä¸ã®ä½å°ãããããã§ãã
ãã®è¨äºã¯äººåã§æ¸ããã¾ãããBBQ ãå©ç¨ããæ¹ã®åèã«ãªãã°å¹¸ãã§ãã
Jianyang Gao and Cheng Long. 2024. RaBitQ: Quantizing High-Dimensional Vectors with a Theoretical Error Bound for Approximate Nearest Neighbor Search. Proc. ACM Manag. Data 2, 3, Article 167 (June 2024), 27 pages. https://doi.org/10.1145/3654970 â©ï¸ â©ï¸ â©ï¸ â©ï¸ â©ï¸ â©ï¸ â©ï¸ â©ï¸
æ¾äº åä½. 2019. è¿ä¼¼æè¿åæ¢ç´¢ã®æåç·. MIRU 2019 ãã¥ã¼ããªã¢ã«. https://speakerdeck.com/matsui_528/jin-si-zui-jin-bang-tan-suo-falsezui-qian-xian â©ï¸ â©ï¸
Herve Jegou, Matthijs Douze, and Cordelia Schmid. 2011. Product Quantization for Nearest Neighbor Search. IEEE Trans. Pattern Anal. Mach. Intell. 33, 1 (January 2011), 117â128. https://doi.org/10.1109/TPAMI.2010.57 â©ï¸ â©ï¸ â©ï¸
ä½è«ã§ãããIVF ã§ã®ç²éååå¨ã HNSW ã«ããææ³ãããã¾ãã â©ï¸
https://www.elastic.co/search-labs/blog/rabitq-explainer-101 â©ï¸
å®éã«ã¯åããããã¾ããããããã©ã®ããã«è§£æ¶ããããå¾ã§èª¬æãã¾ãã â©ï¸
https://www.elastic.co/search-labs/blog/rabitq-explainer-101 â©ï¸
William B Johnson and Joram Lindenstrauss. 1984. Extensions of Lipschitz mappings into a Hilbert space. In: Proceedings of the 1982 Conference in Modern Analysis and Probability. Vol. 26. Contemporary Mathematics. AMS, 1984, pp. 189â206. https://doi.org/10.1090/conm/026/737400 â©ï¸
Casper Benjamin Freksen. 2021. An introduction to Johnson-Lindenstrauss Transforms. arXiv [cs.DS]. Retrieved December 25, 2024 from http://arxiv.org/abs/2103.00564 â©ï¸
Johnson-Lindenstraussã®è£é¡ã«ãããå¤æããã¦ã2ã¤ã®ãã¯ãã«ã®è·é¢ãä¸å®ã®èª¤å·®å ã«æããããã¨ããæ§è³ªã証æããã¦ãã¾ãï¼ãã¨ãå°å½±å ãä½æ¬¡å ã§ãï¼ã â©ï¸
ã©ã³ãã å°å½±ã«ããç¹ç°å¤å解ï¼æ¬¡å åæ¸ï¼ã¯ãscikit-learn ã«ãå®è£ ããã¦ãã¾ãã https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.TruncatedSVD.html#sklearn.decomposition.TruncatedSVD â©ï¸
ãªãããã¼ã¿ãã¯ãã«ãæ£è¦åã㦠$\bm{o}$ ãè¨ç®ããããã« $\bm{o_r}$ ããã»ã³ããã¤ã $\bm{c}$ ãå¼ããå¾ããã«ã ã§å²ã£ã¦æ£è¦åãã¦ãã¾ãããå®ã¯éååããããã§ã¯ãã«ã ã§å²ããªãã¦ãåãçµæãå¾ããã¾ããRaBitQ ã§ã BBQ ã§ãããã«ã ã§ã®å²ãç®ã¯çç¥ãã¦ãã¾ãã â©ï¸
ã©ã³ãã å°å½±ã使ã£ãããã ã¨æããã â©ï¸
ãªãããã®å ç©ã®å¤ã®ä¿åã¯ãªãã·ã§ã³ã§ããä¿åããªãå ´åããã®å¤ã®çè«å¤ã§ãã 0.8 ã使ç¨ãããã¨ãã§ãã¾ãï¼Section 3.2.1ï¼ã â©ï¸
ããã«ã¤ãã¦ã¯ãå®ç¨ä¸ã¯ç¢ºççã«ãµã³ããªã³ã°ãããåæ¨äºå ¥ãªã©ã§æ±ºå®çã«ä¸¸ããã ãã§ãååããããã¾ããã â©ï¸
https://www.elastic.co/search-labs/blog/better-binary-quantization-lucene-elasticsearch â©ï¸ â©ï¸ â©ï¸
åã®è注ã§èª¬æããéããä¿åããªãå ´åã¯çè«å¤ã§ãã 0.8 ã使ç¨ãã¾ãã â©ï¸
Jianyang Gao, Yutong Gou, Yuexuan Xu, Yongyi Yang, Cheng Long, and Raymond Chi-Wing Wong. 2024. Practical and asymptotically optimal quantization of high-dimensional vectors in Euclidean space for approximate nearest neighbor search. arXiv [cs.DB] http://arxiv.org/abs/2409.09913 â©ï¸