ã¨ã ã¹ãªã¼ã¨ã³ã¸ãã¢ãªã³ã°ã°ã«ã¼ã AIã»æ©æ¢°å¦ç¿ãã¼ã ã§ã½ããã¦ã§ã¢ã¨ã³ã¸ãã¢ããã¦ããä¸æ(@po3rin) ã§ãã 好ããªè¨èªã¯Goãä»äºã§ã¯ä¸»ã«æ¤ç´¢å¨ããæ å½ãã¦ãã¾ãã
Overview
æè¿ã社å ã§æ å ±æ¤ç´¢è«æ輪èªä¼ãç«ã¡ä¸ãã¾ããã
ããã§NGT-ONNGã«ã¤ãã¦ã®è«æ*1ãç´¹ä»ããã¨ãã1æéã®äºå®ã®ã¨ãããçãä¸ããããã¦2æéè¶ ãã¦ãã¾ãã¾ããã
大çãä¸ããã®ã¤ãã§ã«ãä»åã¯æ å ±æ¤ç´¢è«æ輪èªä¼ã§ç´¹ä»ããè¿ä¼¼æè¿åæ¢ç´¢ã©ã¤ãã©ãªNGTãå é¨ã§å©ç¨ããValdã使ã£ã¦ãé¡ä¼¼ææ¸æ¤ç´¢ãã©ã®ããã«åºæ¥ãã®ããç¾ç¶ã®åé¡ã解決ã§ããã®ãã試ããã®ã§ãã®çµæãå ±åãã¾ãã
- Overview
- å¼ç¤¾ãæ±ããé¡ä¼¼ææ¸æ¤ç´¢ã®èª²é¡
- Sentence-BERT
- Valdã使ã£ãè¿ä¼¼æè¿åæ¢ç´¢
- ValdÃSententce-BERTã§é¡ä¼¼ææ¸æ¤ç´¢
- Vald Agentã®ãã©ã¡ã¼ã¿ãå¤ãã¦è©¦ãã
- ãã¾ã: Elasticsearchã®è¿ä¼¼æè¿åæ¢ç´¢ã®ç¾ç¶
- ã¾ã¨ã
å¼ç¤¾ãæ±ããé¡ä¼¼ææ¸æ¤ç´¢ã®èª²é¡
å»å¸«ã«è³ªåãã§ãããµã¼ãã¹ã§ããAskDoctorsã§ã¯ã¦ã¼ã¶ã¼ã質åãæ¤ç´¢ã§ããæ©è½ããããç¾ç¶ãä¼¼ã質åãåºãæ©è½ã¯Elaticsearchã®More Like Thisã®ãããªåèªé »åº¦ãã¼ã¹ã®é¡ä¼¼ææ¸æ¤ç´¢ãå©ç¨ãã¦ãã¾ããã¯ã¨ãªã¨ãã¦å ¥åãããããã¥ã¡ã³ãããé »åºåèªãæãåºããããã使ã£ã¦ææ¸æ¤ç´¢ãã¾ããããã¯ãä¼¼ãææ¸ã¯åãåèªããã¤å¯è½æ§ãé«ããã¨ããä»®å®ã«åºã¥ããææ³ã§ãã
ãããå»çè¨èªã¯è¡¨ç¾æºãã大ãããåèªé »åº¦ãã¼ã¹ã ã¨é¡ä¼¼ææ¸ãåºããªãå¯è½æ§ãããã¾ããä¾ãã°
ãè¸ãéåæãã¨è¡¨ç¾ãã人ãããã°ãè¸ãã ã«ã ã«ãã¨è¡¨ç¾ãã人ãããã®ã§é¢é£åº¦ãé«ãã®ã«åèªãã¼ã¹ã ã¨ã¹ã³ã¢ãä¸ãã£ã¦ãã¾ãé¡ä¼¼ææ¸ãåºã¦ãã
ãå¦å¨ 30æ¥ããçå¾12æ¥ãã39度ã®ç±ããªã©è¡¨ç¾ã§ã¯å¤ãã®æ°å¤è¡¨ç¾ãåºã¦ãããåèªé »åº¦ãã¼ã¹ã§ã¯æ°åã ãããã¼ã¯ã³ã¨ãã¦æ½åºããã¦ãã¾ãã®ã§ãä½ã¨ã²ãã¥ãæ°å¤ãªã®ããæèã§ç解ããå¿ è¦ããã
ãç±ã¯ãªãããé ãçãããªã©ãç±ãã¨ããªããã®é¢ä¿ãã¾ãã¯å¦å®å½¢ãå«ãã é¡ä¼¼ææ¸æ¤ç´¢ãããªãã¨ã¦ã¼ã¶ã¼ã®æå³ã¨éãææ¸ãåºãã¦ãã¾ã
ãã®ãããªå»çèªç¶è¨èªã«é¢ãã課é¡ã®è©±ã¯å»çè¨èªå¦çã¨ããæ¬ãé¢ç½ãã®ã§èå³ã®ãã人ã¯èªãã§ã¿ããã¨ããå§ããã¾ãã
ãããã®åé¡ã解決ããããã«ãæèãèæ ®ããææ¸ãã¯ãã«ãå©ç¨ããé¡ä¼¼åº¦è¨ç®ã1ã¤ã®è§£æ±ºçã¨ãã¦èãããã¾ããããã§ä»åã¯Sentence BERTã§è³ªåã®ã¿ã¤ãã«ããæç« ãã¯ãã«ãçæããValdã使ã£ã¦ãã¯ãã«æ¤ç´¢ããããã¨ã§ããã®åé¡ãçªç ´ã§ãããã試ãã¾ãã
ã¾ããä»å¹´ã®2æã«ç§ãæ¸ããè¨äºã§ã¯ãããã®åé¡ã®å¥è§£ã¨ãã¦GiNZAã¨æ£è 表ç¾è¾æ¸ã使ã£ãæå³æ§é æ¤ç´¢ã試ããè¨äºãããã®ã§èªãã§ã¿ã¦ãã ããã
Sentence-BERT
Sentence BERT*2ã¯æç« ã®çµã¿åããã«å¯¾ãã¦ãããããä¼¼ã¦ãããå¦ãã®ã©ãã«ãã¤ãã¦å ¥åã¨ããBERT層ãpooling層ãè·é¢å¦ç¿ã§fine-tuneããã¢ãã«ã§ãã
è«æã§ã¯è©ä¾¡é¢æ°ãpoolingææ³ã®2ã¤ãå¤ãã¦å®é¨ãã¦ãã¾ããè©ä¾¡é¢æ°ã¯SoftmaxãCosine Similarityã®2ã¤ã§å®é¨ãã¦ãã¾ããpooling層ã¯mean poolingãmax poolingãææ¡ããã¦ãã¾ããè«æããå¼ç¨ããå³ãããããããã§ãã
poolingææ³ã«ã¤ãã¦ã¯ãè«æã®å®é¨ã§ã¯åèªãã¯ãã«ã®å¹³åã使ã£ãææ³ãBERTã®CLSãã¯ãã«ãå©ç¨ããææ³ããã精度ãé«ãã£ãããã§ãã
ä»åã¯æ¤è¨¼ã®ãããå¦ç¿æ¸ã¿ã¢ãã«ã¯ä»¥ä¸ã®è¨äºã§å ¬éããã¦ãããã®ã使ç¨ãã¾ããã
è¨äºå ã§ã¯å¦ç¿æ¹æ³ã«ã¤ãã¦æè¨ãããã¦ããªããããåãè¾¼ã¿ç©ºéã®ç²¾åº¦ã¸ã®å½±é¿ã«ã¤ãã¦ã¯ä»åè¦ã¦ãã¾ããããæ¹åã®ä½å°ã¯ããããã§ãã
Valdã使ã£ãè¿ä¼¼æè¿åæ¢ç´¢
Sentence-BERTã§çæããææ¸ãã¯ãã«ã使ã£ã¦Cosine Similarityãè¨ç®ããé¡ä¼¼ææ¸ã決å®ããã®ã§ãããå ¨ã¦ã®ãã¯ãã«ã«å¯¾ãã¦ç·å½¢ã«æ¢ç´¢ããã¨ããã©ã¼ãã³ã¹çã«åé¡ãããã¾ãããã®ããããã¯ãã«æ¤ç´¢ãå®è·µæå ¥ããããã«ã¯è¿ä¼¼æè¿åæ¢ç´¢ãé¸æè¢ã«ä¸ããã¾ãã
ããã§ä»åã¯åã ããæ°ã«ãªã£ã¦ããNGTã¨ãããã¹ã±ã¼ã©ãã«ãªåæ£ãã¯ãã«æ¤ç´¢ã¨ã³ã¸ã³ã¨ãã¦ä½¿ããããã«å®è£ ãããValdã試ãã¦ã¿ã¾ããã
NGT
Valdã®ä¸ã§å©ç¨ããã¦ããNGTã¨ããè¿ä¼¼æè¿åæ¢ç´¢ã©ã¤ãã©ãªããç´¹ä»ãã¾ããNGTã©ã¤ãã©ãªã§ã¯å©ç¨ã§ããã¢ã«ã´ãªãºã ã«ç¨®é¡ããããç¹ã«ããªã¼æ§é ã«ããæ¢ç´¢èµ·ç¹æ±ºå®ãã°ã©ãã®ã¨ãã¸èª¿æ´ããã¹èª¿æ´ãè¡ãNGT-ONNGã¯ANN Benchmark *3ã§ãããã¯ã©ã¹ã®æ§è½ãå©ãåºãã¦ãã¾ãã
https://github.com/yahoojapan/NGT
NGT-ONNGã®èª¿æ´ãã¸ãã¯ã¯é常ã«é¢ç½ãã®ã§è«æ *4ããããã¯ä¸è¨ã®ã¢ã«ã´ãªãºã éçºè ã®NGTæ¥æ¬èªè§£èª¬è¨äºãã覧ãã ããã
Vald
NGTãå é¨ã§å©ç¨ããã¹ã±ã¼ã©ãã«ãªåæ£åãã¯ãã«æ¤ç´¢ã¨ã³ã¸ã³ã¨ãã¦ç»å ´ããã®ãValdã§ããValdã®å©ç¹ã¨ãã¦Kubernetes friendlyãªç¹ãããããã¾ããHelmãå ¬å¼ããæä¾ããã¦ãããç°¡åã«Kubernetesã«ãããã¤ãã¦ã¹ã±ã¼ã©ãã«ãªåæ£åãã¯ãã«æ¤ç´¢ã¨ã³ã¸ã³ãã»ããã¢ããã§ãã¾ããå人çã«Goã§æ¸ããã¦ããã®ã好ã¿ã§ãã
ä¸æ¹ã§å ã»ã©ç´¹ä»ããNGT-ONNGãªã©ã®ã°ã©ãåæ§ç¯ããç³»ã®ã¢ã«ã´ãªãºã ã§ã¯åçãªæ´æ°ãåé¤ãã§ããªãã®ã§ãValdã§ã¯NGT-ANNG*5ãå©ç¨ããã¦ãã¾ãã
ValdÃSententce-BERTã§é¡ä¼¼ææ¸æ¤ç´¢
ä»åã®æ¤è¨¼ã§ã¯ãAskdoctorsã®ç´è¿ã®è³ªåãã¼ã¿ç´3ä¸ä»¶ã§ãã¿ã¤ãã«ã ãã®åãè¾¼ã¿ãå©ç¨ãã¦Valdã§æ¤ç´¢ããçµæãå®æ§çã«ã¿ã¦ã¿ã¾ãã
æ¤è¨¼ç°å¢ã¯ä¸è¨ã«ãªãã¾ãã
Vald = "v1.1.0" Python = "v3.9" # 主㪠Python modules torch = "^1.8.1" vald-client-python = "^1.0.4" transformers = "^4.5.1"
Valdã®ã»ããã¢ãã
Valdã®ã»ããã¢ããã«é¢ãã¦ã¯ããã¥ã¡ã³ããããã®ã§ãã¡ããåèã«ã»ããã¢ããããã¨è¯ãã§ãããã
ãã¯ãã«ãµã¤ãºã ãè¨å®ãç´ãå¿
è¦ãããã¾ããexample/helm/values-scylla.yaml
ãããã¯example/helm/values-standalone-agent-ngt.yaml
ã®agent.ngt.dimension
ãä¿®æ£ãã¾ãã
ã¾ããä»åã¯ææ¸é¡ä¼¼æ¤ç´¢ã®å®çªã®Cosine Similarityãæå®ãã¾ããããã¥ã¡ã³ãã®Quick Startã§ã¯ããã©ã«ãã§L2ãªã®ã§æ³¨æãã¦ãã ããã
agent: # ... ngt: # The number of dimensions for feature vector of fashion-mnist dataset. dimension: 768 distance_type: cosine # ...
ã©ããªçµæã«ãªããã ã試ãããå ´åã¯Valdå ¨ä½ã§ã¯ãªãNGT Agentã ããDockerã§ç«ã¡ä¸ããã®ãè¯ãã§ãããã
k8sã¸æ¥ç¶ã§ãããã¨ã確èªããããæ©éHelmã§ãããã¤ãã¾ãã
$ helm install vald vald/vald --values example/helm/values-scylla.yaml
ããã§Valdã®æºåãã§ãã¾ããã
ãã¼ã¿æºå
ãã¼ã¿ã¯listã§ç¨æãã¾ãã
titles = ["æ°åã³ããã¯ã¯ãã³äºé²æ¥ç¨®ã«ã¤ãã¦", "èã¬ã³ã®æè¡", ...]
Sentence-BERTã§ææ¸ãã¯ãã«çæ
å¦ç¿æ¸ã¿Sentence-BERTã®ã¢ãã«ãèªã¿è¾¼ãã§ã
å®è£ ã¯ä¸è¨ã®æ¬ã大ãã«åèã«ãã¦ããã¾ãã®ã§BERTã¢ãã«ã®ã»ããã¢ãããªã©è©³ãã解説ã¯ä¸è¨ã®æ¬ãã覧ãã ãããç§ã®ãããªã½ããã¦ã§ã¢ã¨ã³ã¸ãã¢ã§ãPythonÃPyTorchã§èªç¶è¨èªå¦çã®åºæ¬ãå¦ã¹ãç´ æ´ãããæ¬ãªã®ã§ãå§ãã§ãã
ææ¸ãã¯ãã«ãå¾ãããã®ã³ã¼ããæ¸ãã¾ãã
from transformers import BertJapaneseTokenizer from transformers.models.bert_japanese import tokenization_bert_japanese from transformers import BertModel, BertConfig import torch from torch.nn.utils.rnn import pad_sequence tknz = BertJapaneseTokenizer(vocab_file="resources/sentence-bert/vocab.txt", do_lower_case=False, do_basic_tokenize=False) tknz.word_tokenizer = tokenization_bert_japanese.MecabTokenizer() config = BertConfig.from_json_file("resources/sentence-bert/config.json") net = BertModel.from_pretrained("resources/sentence-bert/pytorch_model.bin", config=config) def mean_pooling(model_output, attention_mask): token_embeddings = model_output[0] input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float() sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1) sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9) return sum_embeddings / sum_mask def embeddings(titles): xs1, xmsk = [], [] for i in range(len(titles)): tid = tknz.encode(titles[i]) xs1.append(torch.LongTensor(tid)) xmsk.append(torch.LongTensor([1] * len(tid))) xs1 = pad_sequence(xs1, batch_first=True) xmsk = pad_sequence(xmsk, batch_first=True) out = net(xs1,xmsk) return mean_pooling(out, xmsk)
Valdã§ãã¯ãã«ãã¤ã³ããã¯ã¹&æ¤ç´¢ãã
ç¶ãã¦Valdã«ãã¯ãã«ãInsertãã¦ããã¾ããValdã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã¯gRPCã§æä¾ããã¦ãã¾ããPythonã§ã¯å ¬å¼ã¯ã©ã¤ã¢ã³ãã©ã¤ãã©ãªã§ããvald-client-pythonãæä¾ããã¦ããã®ã§ããã使ãã¾ãããã®ä»ã«ãGoãJavaãªã©ã®ã¯ã©ã¤ã¢ã³ããå ¬å¼ããæä¾ããã¦ãã¾ãã
import grpc from vald.v1.vald import insert_pb2_grpc, search_pb2_grpc, update_pb2_grpc, remove_pb2_grpc from vald.v1.payload import payload_pb2 channel = grpc.insecure_channel("127.0.0.1:8081") istub = insert_pb2_grpc.InsertStub(channel) icfg = payload_pb2.Insert.Config(skip_strict_exist_check=True) doc_id = d ts = embeddings(titles) for i, t in enumerate(ts): vec = payload_pb2.Object.Vector(id=str(i), vector=s) istub.Insert(payload_pb2.Insert.Request(vector=vec, config=icfg)) doc_id+=1
次ã«ã¯ã¨ãªãç¨æãã¾ããã¯ã¨ãªã¯åèªãã¼ã¹ã®More Like Thisã§é£ããã¨æãããã¯ã¨ãªãç¬æã¨åè¦ã§ç¨æãã¾ããã
queries = [ 'ä¸æ¥éã®è ¹ç', #æ°å¤è¡¨ç¾ 'èã¬ã³ã®æè¡', #èã¬ã³ã®ã·ããã ãæãããã 'è¸ããã£ã¨çèç', #ãã£ã¨ã¨ããæéã表ãè¡¨ç¾ 'çå¾6ã¶æã®ä¹³å ã®èª¤é£²', #æ°å¤è¡¨ç¾ã¨èª¤é£²ã¨ããå°ãçããè¡¨ç¾ 'ç±ã¯ãªããé ãçã', #å¦å®è¡¨ç¾ ]
æå¾ã«ããããValdã«æ¤ç´¢ããããã³ã¼ããæ¸ãã¦ããã¾ãã
qs = embeddings(queries) scfg = payload_pb2.Search.Config(num=5, radius=-1.0, epsilon=0.3, timeout=3000000000) for i, s in enumerate(qs): res = sstub.Search(payload_pb2.Search.Request(vector=s, config=scfg)) print("---------") print(f"query: { queries[i] }") for r in enumerate(res.results): print(f"title: { titles[int(r[1].id)] }")
payload_pb2.Search.Config
ã«ä½ãããã©ã¡ã¼ã¿ã渡ãã¦ãã¾ããNGTã¯æ¢ç´¢ç¯å²ã¨ãªãåã®åå¾ãçããªããæ¤ç´¢ããã¢ã«ã´ãªãºã ãªã®ã§ãæ¢ç´¢åå¾ã決å®ãããã©ã¡ã¼ã¿ã決ãã¦ãããå¿
è¦ãããã¾ãã
radius
ã¯åææ¢ç´¢åå¾ã§ããã-1
ã¯ãã¡ãã®ANNGã®è«æã§è¨åãããéãç¡é大ãæå®ãã¦ãããã®ã ã¨æããã¾ããããã«ããå¿
ãåæåå¾å
ã«æ¢ç´¢å¯¾è±¡ãåå¨ãããã¨ãä¿è¨¼ãããã®ã§ãæè¿åæ¢ç´¢ã¯1åã ãã§ååã«ãªãã¾ããhttps://github.com/yahoojapan/NGT/wiki#annghttps://github.com/yahoojapan/NGT/wiki#anng
epsilon
ã¯ç¯å²å
ã®ãã¼ãã®æ¢ç´¢ã«ããã¦ãæè¿åã®ãã¼ãã¸ã®çµè·¯ããç¯å²å¤ãçµç±ããªãã¨å°éã§ããªãå ´åãæ³å®ãã¦è¨å®ãããã©ã¡ã¼ã¿ã§ããã¤ã¾ãepsilon
ãé«ãè¨å®ãããã¨ã§åç¾çãåä¸ãã¾ãããèæ
®ããªããã°ãããªããã¼ããå¢ããã®ã§è¨ç®ã³ã¹ããå¢ãã¦ãã¾ãã¾ããANNGã®è«æã§ã¯epsilon
ã«å¯¾ããæ¤ç´¢ç²¾åº¦
ã50次å
ã®ãã¯ãã«ã§é度ãè¨æ¸¬ããã°ã©ãã示ããã¦ãã¾ãã
ããã§å®è£ ã¯çµäºã§ãã
çµæã確èª
å®è¡ãã¦çµæã1ã¤ãã¤è¦ã¦ããã¾ãã
query: ä¸æ¥éã®è ¹ç title: ï¼æéãè¶ ããè ¹ç title: è¸çãä¸æ¥ç¶ãã¦ãã¾ã title: 3é±é以ä¸ç¶ãä½èª¿ä¸è¯ title: 3æ¥åããè ¹ç title: ãè ¹çã4æ¥åãã3æ¥ã»ã©å¼·ãçã¿ãç¶ãã¾ãã
æ°å¤è¡¨ç¾ã¨æ°å¤è¡¨ç¾ãããç¨åº¦ç´ä»ãããã¦ãã¾ãããã3é±éããªã©ã®è¡¨ç¾ãå ¥ã£ã¦ãã¾ã£ã¦ãã¾ãã
query: èã¬ã³ã®æè¡ title: èããã®æè¡ã«ã¤ã㦠title: èããæè¡å¾ã®çã¿ title: èçã®åå title: èã®ç²èä¸è «çã«ã¤ã㦠title: èä½é¨ã«ç°å¸¸ãããã¨ã®äº
èã¬ã³/èãã/èçã®è¡¨è¨ãããæãã¦ãã¾ãããã®ä¸ã§ã注ç®ãã¹ãã¯ãèã®ç²èä¸è «çããªã©ã®è¡¨ç¾ãæãã¦ããã®ãå¬ããã§ããèããã¯å ¨ãéãã®ã§ããã¯ãã¤ãºã§ãã
query: è¸ããã£ã¨çèç title: è¸éª¨é¨ãã¨ã¦ãçãã title: ä½ãæ»ãã¨è¸ãçã title: è¸ã®çã¿ã¨æ¿ããåæ¸ title: ãã£ã¨ç¶ãã¦ããè¸ç title: è¸ãçã¿ã¾ã
çèçãçã¿ã§ãããã¨ãæå³ã¨ãã¦æãã¦ãããã¨ãåããã¾ããããã£ã¨ãã¨ããæéç¯å²ãä¼´ã表ç¾ã¯ãã¾ãç解ã§ãã¦ããªãããã§ãã
query: çå¾6ã¶æã®ä¹³å ã®èª¤é£² title: 6ã¶æ赤ã¡ãããåå title: çå¾6ã¶æåã®åå title: 6ã¶æã®èµ¤ã¡ãããé¡ãã¶ã¤ãã¦é¼»è¡ï¼ãã§ã¾ããã title: ï¼ã¶æã®ä¹³å ãï¼æéã»ã©åã«ååããï¼æéã»ã©åã«é ãã¶ã¤ãã¾ããã title: ï¼æ³ã®åä¾ã®ã²ã©ãè«æ¯
çå¾6ã¶æã®åå¾ã®ç¯å²ã«åããã¦èµ¤ã¡ãããä¹³å ãªã©ã®è¡¨ç¾ããããã¦ãã¾ããã誤飲ããä¸æãæãããã¦ãã¾ãããä»åç¨æãããã¼ã¿ã§ã¯ãçå¾ï¼ã¶ææ¯åã®èª¤é£²ã®å¯è½æ§ãã¨ãããããªé¢é£è¨äºãåå¨ãã¦ããã®ã§ããã®çµæã¯è¯ããªãã§ããã
query: ç±ã¯ãªããé ãçã title: å¤å°ã®æ¯è¦ãã ç±ãªã å³ãªã title: ä½æ¸©ã¯å¹³ç±ã ãã©ãé ãç±ã£ã½ã title: é çãã²ã©ãå³è¦ãããããç±ã¯ãªã title: ä½ãç±ã£ã½ããã¡ãã£ã¨ã ãã title: ç±ãå³ããªãã§ããåæã«éåæãéçãããã¾ã
æ£ããå¦å®è¡¨ç¾ãåãã¦ãã¾ããããã¯ããªãå¬ããã§ãã
ã¾ã¨ããã¨ãå®ç§ã«çç¶ãä¸è´ãã¦ããé¡ä¼¼ææ¸ãåãã¦ãã訳ã§ã¯ããã¾ããããå»çè¨èªå¦çã®èª²é¡ãããç¨åº¦çªç ´ãã¦ãæå³ã®è¿ãææ¸ãåå¾ã§ãã¦ãã¾ãã
誤飲ãªã©ã®çããåèªã®å ´åã¯ãåèªé »åº¦ãã¼ã¹ã®ææ³ã®æ¹ããã®åèªãå ¥ã£ã¦ããææ¸ã確å®ã«åå¾ã§ããå¯è½æ§ã®ããä¸æ¹ãæå³ãæããªããã°æå³ç解ãé£ããæç« æ§é ã®å ´åã¯ãã®ãããªææ¸ãã¯ãã«ã使ã£ãææ³ã®æ¹ãåãã¦ããã¨æããã¾ãã
èªåãã®ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ã©ã®ãããªå ¥åããããã®ããèæ ®ãã¦ã使ãææ³ã決ããã¹ãã§ãããã
Vald Agentã®ãã©ã¡ã¼ã¿ãå¤ãã¦è©¦ãã
epsilon
ã0.1
ãããã«ä¸ããã¨ç²¾åº¦ãä¸ããå¦å®å½¢ãåããªããªã£ã¦ããã
query: ç±ã¯ãªããé ãçã title: å³ã¨å¾®ç± title: å¾®ç±ã¨å³ãç¶ã title: å¾®ç±ã¨å¦æ æãããã¾ã title: å¾®ç±ã¨å¦æ æãç¶ãã¦ãã¾ãã title: å¾®ç±ãç¶ã
ããã¯åã®ç¯ã§è¿°ã¹ãããã«ãæ¢ç´¢åå¾å¤ã®æ¢ç´¢ãããç¨åº¦è¨±å®¹ããã¨ããé¸æè¢ãçããããã«ç²¾åº¦ãä¸ãã£ãçµæã¨è¨ãã¾ãã
ã¾ã radius
ã0.3
ãããã«ä¸ããã¨ãæåã®æ¢ç´¢ç¯å²ã極端ã«çããªããtop-kãåå¾ã§ããªããªãå ´åããããã¨ããããã¾ããã
query: ç±ã¯ãªããé ãçã // çµæãªã
ãã£ã¦æ¢ç´¢åå¾ã®ãã©ã¡ã¼ã¿ã¯ãã¯ãã«ã®ç¹æ§ã«ãã£ã¦èª¿ç¯ããå¿ è¦ãããã¾ãã
ãã¾ã: Elasticsearchã®è¿ä¼¼æè¿åæ¢ç´¢ã®ç¾ç¶
ä»åValdã調æ»ããï¼ã¤ã®çç±ã¨ãã¦ãå¼ç¤¾ã§å©ç¨ãã¦ããElasticserchã«ã¯ã¾ã è¿ä¼¼æè¿åæ¢ç´¢ãå®è£ ããã¦ããªãã¨ããç¹ãããã¾ããã
ããããAWSãªã©(ãã®è¾ºãããããªã®ã§ãã¾ãè¨åã§ãã¾ããã...)ã§å©ç¨ããã¦ããOpen Distro for Elasticsearchã§ã¯ãHierarchical Navigable Small world(HNSW)ã°ã©ã*6ãå©ç¨ããNMSLIBããã¼ã¹ã«ããæ©è½ãæä¾ããã¦ããããã§ãã
HNSWã¯NGTãå©ç¨ããã¢ã«ã´ãªãºã ã¨ã¯ã¾ãéãããã«ãã¬ã¤ã¤ã¼æ§é ãæã¤ã°ã©ããå©ç¨ãããã¨ã§é度ã¨ç²¾åº¦ã両ç«ããææ³ã§ãã
æ®å¿µãªããå¼ç¤¾ã§ã¯ç¾å¨Elastic Cloudãå©ç¨ãã¦ããã®ã§ãã®HNSWã¯å©ç¨ã§ãã¾ããããããææã¡ã¸ã£ã¼ãã¼ã¸ã§ã³ã®Lucene v9.0.0ã§ã¯HNSWãå®è£ ãããããã§ã!
[LUCENE-9004] Approximate nearest vector search - ASF JIRA
å®è£ ãè¦ãã¨ã¾ã 1é層ãããµãã¼ããã¦ãã¾ãããããã¤ã®æ¥ãElasticsearchã®å ¬å¼æ©è½ã¨ãã¦å©ç¨ã§ããã¨å¬ããã§ããæ¥æ¬èªã®Luceneã«HNSWå ¥ããè¨äºã¯ãã¡ãã詳ããã§ãã
https://mocobeta.medium.com/%E3%83%99%E3%82%AF%E3%83%88%E3%83%AB%E6%A4%9C%E7%B4%A2-%E8%BF%91%E4%BC%BC%E6%9C%80%E8%BF%91%E5%82%8D%E6%8E%A2%E7%B4%A2-%E3%81%A7%E3%81%84%E3%81%84%E6%84%9F%E3%81%98%E3%81%AE-morelikethis-%E3%82%92%E5%AE%9F%E7%8F%BE%E3%81%99%E3%82%8B-7eba63ffb593mocobeta.medium.com
ã¾ã¨ã
ä»åã¯Sentence-BERT à Valdã§é¡ä¼¼ææ¸æ¤ç´¢ã試ãã¾ãããå®ç§ã¨ã¯è¡ããªãã¾ã§ãããç¨åº¦ã¯æç« ã®æå³ãç解ããçµæãè¿ãããã¨ããããã¾ãããç¹ã«ãç±ã¯ãªããé ãçãããªã©ã®å¦å®å½¢ãå«ãæç« ã§ãæå³ãç解ãã¦çµæãè¿ãããã¨ã確èªã§ãã¾ããã
Valdã¯Helmãç¨æããã¦ãããããã¤ãç°¡åã«è¡ããä¸ã¤ãå種è¨èªã§ã¯ã©ã¤ã¢ã³ãã©ã¤ãã©ãªãæä¾ããã¦ãããããããã«åæ£å¯ãã¯ãã«æ¤ç´¢ã¨ã³ã¸ã³ãå©ç¨ã§ããã®ãã¡ãªããã ã¨æãã¾ãããããé¡ä¼¼ææ¸æ¤ç´¢ä»¥å¤ã§ãè¿ä¼¼æè¿åæ¢ç´¢ãããéã«ã¯Valdã¯ååæ¤è¨å¯¾è±¡ã«ãªãããã§ãããã®éã«ã¯æ³å®ãããæ¬çªãã¼ã¿ãµã¤ãºã¨æ¬¡å ã§ããã©ã¼ãã³ã¹ãã¹ããè¡ãããã¨æãã¾ãã
ã¾ããä»åã¯Valdã®ã¢ã¼ããã¯ãã£ã«è¸ã¿è¾¼ããªãã£ãã®ã§æ¬¡å調ã¹ãæ©ä¼ãããã°ã¾ãããã°ã§æ¸ããã¨æãã¾ãï¼
We're hiring !!!
ã¨ã ã¹ãªã¼ã§ã¯æ¤ç´¢&æ¨è¦åºç¤ã®éçº&æ¹åãéãã¦å»çãåé²ãããã¨ã³ã¸ãã¢ãåéãã¦ãã¾ãï¼ ç¤¾å ã§ã¯æ å ±æ¤ç´¢è«æ輪èªä¼ãçºè¶³ããæ¥ã æ¤ç´¢ãæ¨è¦ã«ã¤ãã¦ã®è°è«ãæ´»çºã«è¡ããã¦ãã¾ãã
ãã¡ãã£ã¨è©±ãèãã¦ã¿ãããããã¨ãã人ã¯ãã¡ãããï¼ jobs.m3.com
*1: Optimization of Indexing Based on k-Nearest Neighbor Graph for Proximity Search in High-dimensional Data (https://arxiv.org/abs/1810.07355)
*2:Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks (https://arxiv.org/abs/1908.10084)
*3: ANN Benchmark (https://github.com/erikbern/ann-benchmarks)
*4: Optimization of Indexing Based on k-Nearest Neighbor Graph for Proximity Search in High-dimensional Data (https://arxiv.org/abs/1810.07355)
*5: NGT-ANNG (https://github.com/yahoojapan/NGT#anng)
*6: Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs (https://arxiv.org/abs/1603.09320)