【docker版】Multilingual E5 Embedding を HTTP Server化して利用する (Multilingual E5 Embedding Server : REST API)

The English version of this is here.

https://qiita.com/oyahiroki/items/3f8a40c092322afa15c8

# nlp4j-llm-embeddings-e5


Multilingual-E5-large の Embedding をHTTPサーバー化して使うというのが本コンポーネントの趣旨です。

# 0. 前提

Docker の利用環境が構築されているのが前提です。

5GB ほどのイメージがダウンロードされます。

# 1. 導入

docker pull コマンドでイメージを取得します。

```
docker pull oyahiroki/nlp4j-llm-embeddings-e5:1.0.0.0
```

結果の例は以下のようになります。

```
>docker pull oyahiroki/nlp4j-llm-embeddings-e5:1.0.0.0
1.0.0.0: Pulling from oyahiroki/nlp4j-llm-embeddings-e5
e17464c8c9fb: Download complete
f344618db07e: Download complete
fd674058ff8f: Download complete
f7fe7c1564c1: Download complete
4f4fb700ef54: Download complete
4036d1c9d769: Download complete
a1235d039a7d: Download complete
22318a820e1b: Download complete
2ecbc2a20de9: Download complete
Digest: sha256:7d21fbdb572e1b99242179b4e99ff7cde6876febeb4f2ce981fccd39afd98f04
Status: Downloaded newer image for oyahiroki/nlp4j-llm-embeddings-e5:1.0.0.0
docker.io/oyahiroki/nlp4j-llm-embeddings-e5:1.0.0.0
```

イメージについては以下を参照してください

https://hub.docker.com/r/oyahiroki/nlp4j-llm-embeddings-e5


# 2. 実行

以下のコマンドで実行します。

お好みでオプションを追加してください。

初期化プロセスのなかで Multilingual-E5-large のモデルもダウンロードされるので、さらに5GB ほどのディスクが消費されます。モデルのダウンロードをともなう初期化プロセスは最初の起動時のみなので、２回目以降の起動時には発生しません。

```
docker run -d --name nlp4j-llm-embeddings-e5 -p 8888:8888 oyahiroki/nlp4j-llm-embeddings-e5:1.0.0.0
```

Docker Desktopでは以下のように見えます。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/110265/0bd44a22-40fe-a5d4-c4a2-2ed6b25867f4.png)

５分ほど待って初期化プロセスが終わると、CPUの使用率が下がります。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/110265/09b13860-5001-3df6-0539-89ff692cca34.png)

# 3. 動作確認

Curl コマンドで REST API にテキストを送信することでベクトル化が可能です。

```
curl http://127.0.0.1:8888/?text=%E3%81%93%E3%82%8C%E3%81%AF%E3%83%86%E3%82%B9%E3%83%88%E3%81%A7%E3%81%99%E3%80%82
```

以下のような結果が返ればOKです。

```
{"message": "ok", "time": "2025-01-04T05:49:20", "text": "\u3053\u308c\u306f\u30c6\u30b9\u30c8\u3067\u3059\u3002", "embeddings": [0.04231279715895653, -0.0035561532713472843, -0.014567538164556026, -0.05735648050904274, 0.0339919812977314, -0.023742269724607468, 0.006811155471950769, 0.0830383449792862, 0.041998427361249924, -0.009564925916492939, 0.021144241094589233, 0.03838073089718819, -0.03303127363324165, -0.00032863442902453244, -0.03512480482459068, -0.016866829246282578, -0.013489240780472755, 0.01558159664273262, 0.028106780722737312, -0.004634382203221321, 0.01627136766910553, -0.010889444500207901, -0.04045294225215912, -0.02741953916847706, -0.026021577417850494, 0.008194061927497387, -0.05707988515496254, -0.028787249699234962, -0.009535274468362331, -0.04099910333752632, 0.012657918967306614, 0.021215656772255898, -0.046045996248722076, -0.042320773005485535, -0.027079155668616295, 0.032212063670158386, 0.033910397440195084, 0.02527390979230404, -0.011053706519305706, 0.022486215457320213, -0.0207266416400671, 0.01321722287684679, -0.007527207490056753, -0.027816051617264748, -0.007766799069941044, 0.017956113442778587, 0.03221069648861885, -0.012765568681061268, -0.014981063082814217, 0.038999926298856735, 0.02593628503382206, 0.004660701844841242, 0.020233793184161186, -0.027318844571709633, -0.023600807413458824, 0.040527358651161194, -0.02116200141608715, 0.0022805780172348022, -0.03332344815135002, 0.017284713685512543, -0.025399673730134964, -0.0015814929502084851, 0.02567838691174984, -0.03803717717528343, -0.03288925439119339, 0.028018858283758163, 0.03861956670880318, 0.017869915813207626, -0.04524414613842964, 0.03814176470041275, -0.006115890108048916, 0.013067426159977913, -0.020388297736644745, 0.002818951616063714, -0.03316311910748482, -0.014772161841392517, 0.036299336701631546, -0.012907251715660095, 0.012932186014950275, -0.014632911421358585, 0.05422934144735336, -0.012177618220448494, 0.02602391317486763, 0.0004178207600489259, 0.050816457718610764, 0.02723040245473385, 0.005543327424675226, 0.023635726422071457, 0.03814251720905304, 0.014872463420033455, -0.017189500853419304, 0.026089051738381386, 0.03398870676755905, -0.009544781409204006, -0.049388155341148376, 0.002603424247354269, 0.011951562017202377, 0.021953202784061432, -0.017844267189502716, -0.03105289116501808, -0.02368745394051075, 0.005575175397098064, 0.04329823702573776, -0.04044771566987038, -0.044065121561288834, 0.016936585307121277, 0.016967909410595894, 0.055434323847293854, 0.02478811703622341, 0.01912476308643818, 0.03200775757431984, 0.04732456058263779, -0.005747492425143719, -0.008110404014587402, -0.0316026508808136, -0.0027479170821607113, -0.0028655531350523233, -0.013074439950287342, -0.01523576583713293, 0.03488835319876671, 0.048614367842674255, 0.043841585516929626, 0.004942167550325394, -0.030833451077342033, 0.023243464529514313, -0.020601918920874596, 0.028957722708582878, 0.013689047656953335, -0.014714978635311127, 0.005966223776340485, 0.021354179829359055, 0.020645588636398315, -0.04192153364419937, -0.01505578774958849, -0.08056322485208511, -0.03799143806099892, -0.006913835648447275, 0.038278304040431976, -0.012762364000082016, 0.004370247013866901, -0.018412137404084206, 0.03155054152011871, 0.014093687757849693, -0.026477959007024765, -0.0005849076551385224, -0.03904000297188759, -0.0572974756360054, 0.019116131588816643, -0.013920113444328308, -0.011862070299685001, -0.002121425699442625, -0.011579231359064579, -0.04221655800938606, 0.008988137356936932, 0.012729577720165253, 0.0017614905955269933, 0.030742140486836433, 0.03496529161930084, 0.025887155905365944, 0.013972705230116844, -0.02593965455889702, -0.07448515295982361, -0.0030435689259320498, -0.020558763295412064, -0.017030201852321625, 0.012353455647826195, 0.040631476789712906, 0.04400736838579178, 0.012320912443101406, -0.022698072716593742, -0.006245745811611414, -0.0434897355735302, 0.020419729873538017, -0.06450913101434708, -0.006840455811470747, 0.03141261637210846, 0.04036753624677658, 0.039559923112392426, 0.03421510383486748, -0.03794233128428459, 0.0025826427154242992, 0.04662986844778061, 0.026379819959402084, -0.02856980822980404, -0.011073226109147072, 0.018456585705280304, 0.04542248696088791, 0.025126442313194275, 0.049210064113140106, 0.016478193923830986, 0.01106607262045145, -0.02673233300447464, -0.021207531914114952, -0.0036969187203794718, -0.03186405822634697, 0.023659510537981987, 0.05176158249378204, 0.01935948245227337, -0.021342510357499123, -0.030490949749946594, 0.008866505697369576, 0.017086928710341454, -0.06149863824248314, -0.01076927687972784, 0.0009254722390323877, -0.033721674233675, -0.04678523913025856, -0.023972464725375175, 0.031425442546606064, -0.08103220164775848, -0.03176060691475868, -0.029707064852118492, 0.04360980913043022, -0.011374031193554401, -0.027132218703627586, -0.04328945279121399, -0.03391542658209801, -0.029291899874806404, 0.02509016916155815, -0.011719613336026669, 0.030080437660217285, 0.06376168876886368, 0.014841072261333466, 0.03212153539061546, 0.027172653004527092, 0.020585455000400543, 0.041555870324373245, 0.05334329232573509, 0.06147296726703644, 0.025663383305072784, 0.009771201759576797, 0.0023985158186405897, -0.05356297641992569, -0.01983320154249668, 0.028780315071344376, -0.015771890059113503, -0.022141380235552788, -0.007726147770881653, 0.031927116215229034, 0.044953398406505585, -0.03246240317821503, 0.007369492668658495, 0.028481043875217438, -0.02225133217871189, -0.002622585976496339, -0.02561233937740326, 0.02900838293135166, -0.026322457939386368, 0.03202326223254204, -0.02953767590224743, 0.010895407758653164, 0.041326332837343216, -0.04530838131904602, -0.018320631235837936, 0.013190403580665588, 0.01600050926208496, 0.02309834398329258, 0.01547524519264698, -0.023977451026439667, -0.00025430438108742237, 0.012473943643271923, 0.019584987312555313, -0.007058503106236458, 0.05648516118526459, 0.0091595109552145, 0.013403155840933323, -0.0179806649684906, -0.022216616198420525, -0.013498546555638313, -0.06532636284828186, -0.040087632834911346, -0.0547492615878582, -0.050090450793504715, -0.04354534298181534, -0.02984190545976162, 0.04062904044985771, -0.0381566658616066, -0.01339318323880434, 0.011353988200426102, -0.01548770908266306, -0.022096088156104088, -0.0269260685890913, 0.022577481344342232, -0.012820122763514519, 0.01553620956838131, -0.0020274436101317406, 0.028622334823012352, -0.011376213282346725, 0.02426512911915779, 0.0019890321418642998, 0.04041244462132454, -0.0399237796664238, 0.09417814016342163, 0.0179128535091877, 0.008174058049917221, 0.02278314158320427, -0.026188241317868233, -0.09924446046352386, -0.03374661132693291, 0.025821110233664513, -0.02163717895746231, -0.05327051877975464, 0.030051466077566147, 0.03511771187186241, -0.035200297832489014, -0.0458611436188221, 0.02968587726354599, 0.03790997341275215, -0.06594277918338776, 0.00912010669708252, 0.051220618188381195, 0.03861203044652939, 0.00472007691860199, -0.02748827263712883, -0.07629454135894775, 0.0014915346400812268, -0.0396391823887825, 0.0204445980489254, -0.03899658843874931, 0.0347774438560009, -0.023995812982320786, 0.0057777236215770245, -0.06649839878082275, 0.026845553889870644, 0.02946973405778408, 0.02376004308462143, 0.042305026203393936, -0.05380106344819069, 0.00825471617281437, -0.03182615339756012, 0.04213903099298477, -0.029329659417271614, 0.01548351626843214, 0.026673126965761185, -0.0323069766163826, -0.001904722535982728, -0.04542872682213783, 0.018476014956831932, 0.049171168357133865, -0.010156135074794292, 0.02275273948907852, 0.005707188975065947, -0.035918816924095154, 0.002209380269050598, 0.004799611400812864, -0.03378070518374443, 0.021791454404592514, -0.0026054298505187035, 0.022482002153992653, -0.004729272332042456, 0.00010776951967272907, -0.02249261923134327, 0.011921961791813374, 0.017895393073558807, -0.014762843027710915, 0.01818609982728958, -0.015328320674598217, -0.02301902510225773, 0.0204427782446146, 0.00047964492114260793, 0.021607594564557076, -0.015619652345776558, 0.034819334745407104, -0.03373267874121666, -0.03351264446973801, -0.007204626686871052, -0.021185176447033882, -0.0028014781419187784, -0.037366095930337906, -0.036139242351055145, 0.02287406660616398, -0.010579983703792095, -0.022566236555576324, 0.02871149592101574, 0.020435770973563194, -0.019197523593902588, -0.07485561817884445, -0.009554168209433556, 0.014045669697225094, -0.04664478078484535, -0.011301010847091675, -0.040097642689943314, -0.008801843039691448, -0.02726910635828972, 0.0004174251516815275, -0.020309768617153168, 0.169036403298378, 0.02782691828906536, 0.05430418625473976, -0.04859069734811783, -0.024727454409003258, 0.026046793907880783, 0.009347443468868732, 0.011786123737692833, 0.02414213865995407, 0.015757881104946136, -0.027378082275390625, -0.005802768282592297, 0.032289717346429825, -0.03180873766541481, 0.019100720062851906, 0.04401685670018196, 0.010228877887129784, 0.026636064052581787, 0.04933673143386841, -0.008548838086426258, 0.03723253682255745, -0.04696538671851158, 0.012330932542681694, 0.011067967861890793, -0.09181257337331772, -0.023971857503056526, -0.031703319400548935, 0.01631278358399868, -0.04504425823688507, 0.02250184677541256, -0.02228928729891777, 0.02799486368894577, -0.02339014783501625, -0.021472645923495293, 0.04341651499271393, 0.001486074412241578, 0.006151812616735697, -0.050091493874788284, 0.03875531256198883, -0.018446827307343483, -0.0357588492333889, 0.00558597594499588, -0.04020712897181511, 0.02415134571492672, 0.005839446093887091, 0.05372075363993645, 0.045843832194805145, -0.0008021531975828111, 0.0026069919113069773, 0.051993731409311295, 0.025460166856646538, 0.019608406350016594, -0.016619406640529633, -0.020750554278492928, -0.006321351043879986, -0.030364135280251503, -0.043585021048784256, -0.060744304209947586, 0.003988294396549463, 0.020613498985767365, 0.020081575959920883, -0.0005998869892209768, -0.03567909076809883, -0.026748070493340492, 0.030412133783102036, 0.03850742429494858, -0.017640672624111176, -0.05908206105232239, -0.02465543895959854, -0.006918673869222403, -0.017721401527523994, -0.024930384010076523, -0.023436594754457474, 0.010397444479167461, 0.01903376542031765, -0.0038835955783724785, -0.03723648563027382, 0.051108766347169876, 0.06231571361422539, 0.013827132061123848, 0.021570704877376556, -0.012235230766236782, -0.01694590412080288, 0.025618109852075577, 0.05012392997741699, -0.036579303443431854, 0.0339759923517704, 0.025092631578445435, -0.038370490074157715, 0.016560610383749008, 0.017469635233283043, 0.025508249178528786, -0.062446899712085724, 0.03759590908885002, 0.011061953380703926, -0.0638219565153122, 0.009955300018191338, -0.0034573005978018045, -0.04337330907583237, -0.026049984619021416, -0.018907317891716957, 0.013273127377033234, -0.02240254543721676, -0.012809543870389462, -0.0012025776086375117, -0.03483114019036293, 0.017179004848003387, 0.05103413760662079, 0.03425617516040802, 0.0069724880158901215, 0.017995817586779594, 0.008300266228616238, 0.02079443447291851, -0.027145719155669212, 0.057785309851169586, 0.019434621557593346, 0.029433293268084526, -0.03275389224290848, 0.033746082335710526, 0.02007787674665451, -0.037593644112348557, 0.05832195281982422, -0.04230186343193054, 0.0778665542602539, -0.01874200627207756, 0.05118267610669136, -0.022323977202177048, -0.0008880702662281692, 0.0411427840590477, 0.03173231706023216, 0.010550660081207752, -0.020490601658821106, -0.021857470273971558, 0.014289448037743568, 0.01924867555499077, -0.025985680520534515, 0.07886948436498642, -0.0129946144297719, 0.012262457981705666, 0.06438840180635452, -0.03169683367013931, 0.03873642906546593, -0.029722150415182114, 0.03382985666394234, 0.023388756439089775, 0.009699096903204918, -0.026299647986888885, -0.046769943088293076, -0.03071020357310772, -0.03540986776351929, 0.03957977890968323, -0.03674701228737831, 0.018996035680174828, -0.006740766577422619, -0.008334504440426826, -0.039157502353191376, 0.01903657428920269, -0.0028901020996272564, 0.025932524353265762, -0.05465070530772209, -0.03173505887389183, -0.018351886421442032, 0.027185751125216484, 0.09112925827503204, 0.041312020272016525, 0.04031621664762497, -0.030815763399004936, 0.01374738197773695, 0.07294604182243347, 0.013595033437013626, -0.024373292922973633, -0.015105760656297207, -0.013964596204459667, 0.038038671016693115, 0.01846850849688053, -0.024274157360196114, -0.023870669305324554, 0.026138553395867348, -0.03083772212266922, 0.01008997205644846, -0.03116985410451889, 0.004686841741204262, 0.022402921691536903, -0.02971562184393406, -0.05471983179450035, 0.03186442330479622, 0.02093820460140705, -0.04201531037688255, -0.027526836842298508, -0.01660110242664814, -0.03185606002807617, 0.06328070163726807, -0.012661055661737919, 0.0009266574634239078, -0.022846288979053497, -0.013832605443894863, 0.0275852233171463, -0.005252272356301546, -0.011298701167106628, -0.020723382011055946, 0.013810176402330399, -0.031242599710822105, -0.012417604215443134, -0.02357335574924946, -0.03574661910533905, -0.03156261891126633, 0.0063550109043717384, 0.003894341876730323, 0.019823241978883743, 0.050611067563295364, 0.008791496977210045, -0.028278525918722153, 0.025154944509267807, -0.0027415070217102766, 0.025002099573612213, 0.0041356198489665985, 0.04587981849908829, 0.021419692784547806, 0.019290583208203316, -0.015657655894756317, 0.0050271362997591496, 0.0022678207606077194, 0.022057967260479927, -0.041709672659635544, -0.03883996978402138, -0.00837220624089241, 0.014296798966825008, 0.007975142449140549, 0.0050065484829247, -0.03275291249155998, 0.006268491502851248, -0.0018961593741551042, -0.0119522325694561, -0.04354949668049812, -9.299701923737302e-05, -0.010265003889799118, 0.03363347053527832, 0.011073446832597256, 0.0025105446111410856, -0.050194624811410904, 0.023733457550406456, 0.016729334369301796, 0.03519941121339798, -0.021057363599538803, -0.005863908212631941, 0.04017190262675285, -0.059069108217954636, -0.007173184305429459, 0.040705740451812744, 0.009879079647362232, 0.008042681962251663, -0.033972110599279404, 0.023163627833127975, 0.05856615677475929, -0.016750074923038483, -0.0007205299334600568, 0.0051727620884776115, -0.030872270464897156, -0.07582508772611618, -0.012812563218176365, 0.016636677086353302, 0.008593466132879257, -0.02412179298698902, 0.028977053239941597, -0.021150656044483185, -0.02323712594807148, 0.04418699070811272, -0.01007300429046154, -0.0004387367516756058, -0.03509264066815376, 0.02625107392668724, -0.0076643554493784904, -0.018923813477158546, -0.06462859362363815, 0.08214685320854187, 0.015779191628098488, -0.015177457593381405, -0.02689146250486374, -0.047322336584329605, -0.014045020565390587, 0.014141419902443886, 0.0009968063095584512, -0.016604628413915634, -0.037582654505968094, 0.03784623369574547, 0.025797974318265915, -0.049339137971401215, 0.033058833330869675, 0.009735936298966408, -0.013857240788638592, -0.015751441940665245, 0.01849410869181156, -0.015912745147943497, -0.017037222161889076, -0.08346451818943024, -0.046065554022789, -0.044970668852329254, -0.04191718250513077, -0.016793865710496902, -0.026344550773501396, 0.0069471742026507854, -0.027120230719447136, -0.0668608769774437, -0.02483380399644375, 7.90316698839888e-05, 0.0156327523291111, -0.025998277589678764, 0.008958792313933372, 0.027909914031624794, 0.05367252603173256, -0.002966898726299405, -0.06600834429264069, 0.0034105523955076933, 0.02604232169687748, 0.0079621197655797, 0.018635328859090805, 0.0077711837366223335, -0.02183208242058754, -0.01772656850516796, 0.04405154287815094, -0.038013823330402374, -0.028375763446092606, -0.012394034303724766, -0.019942069426178932, 0.02132224291563034, -0.010171507485210896, 0.030151281505823135, 0.00726179126650095, 0.01580972410738468, -0.036739856004714966, 0.03426143154501915, -0.0022888961248099804, -0.02031528390944004, -0.013421650044620037, -0.028584590181708336, 0.00046818144619464874, -0.029585758224129677, -0.025843560695648193, -0.031412702053785324, -0.03589403256773949, -0.012896393425762653, -0.0006128612440079451, 0.03966309130191803, -0.049389373511075974, 0.03567994758486748, 0.0042389691807329655, -0.011647139675915241, 0.04462265223264694, -0.036182913929224014, -0.020899176597595215, -0.013062747195363045, 0.03717135265469551, -0.008456994779407978, -0.01008339412510395, -0.018810126930475235, 0.04666918143630028, -0.0032016420736908913, 0.034658897668123245, 0.0183985885232687, -0.04905548319220543, -0.024756547063589096, -0.015316593460738659, 0.034697532653808594, -0.022186564281582832, -0.030952423810958862, 0.0043751937337219715, -0.004162608180195093, 0.03717070072889328, -0.057880256325006485, 0.009966593235731125, -0.017720911651849747, 0.08242195099592209, -0.036700475960969925, -0.03134440258145332, -0.007367775775492191, 0.03857540711760521, -0.04609330743551254, -0.009278999641537666, 0.021541155874729156, -0.001381049514748156, 0.04263763129711151, -0.0541689433157444, -0.03168488293886185, -0.007342619821429253, 0.03125125914812088, -0.038270607590675354, -0.0015721163945272565, 0.036599189043045044, 0.0019632563926279545, 0.02751692570745945, -0.011384380050003529, 0.05562213435769081, -0.014238649047911167, 0.028252223506569862, -0.08491909503936768, -0.01974162459373474, -0.013815749436616898, -0.01793896034359932, -0.025363322347402573, -0.006552106700837612, -0.010404824279248714, 0.01766560599207878, 0.007731991354376078, -0.05189933255314827, 0.01364467665553093, 0.027472734451293945, 0.03538556769490242, -0.018563689664006233, 0.005201642867177725, 0.017969246953725815, 0.032403986901044846, 0.009695777669548988, 0.01268896833062172, 0.047150831669569016, 0.03460048884153366, -0.021075155586004257, 0.0006638852646574378, 0.011906112544238567, 0.012316053733229637, 0.014500441960990429, 0.008464031852781773, 0.012336191721260548, -0.01838814467191696, -0.06543803215026855, -0.0017553129000589252, -0.030140599235892296, -0.0062059033662080765, 0.04245215654373169, -0.05092210695147514, 0.032668303698301315, -0.021937400102615356, -0.018739113584160805, -0.005232544615864754, -0.003687936346977949, -0.033735278993844986, 0.0377204529941082, -0.042704496532678604, 0.006427197251468897, 0.02552689053118229, 0.020452508702874184, 0.0030112459789961576, -0.01798461563885212, 0.006823597010225058, -0.032337576150894165, -0.03024478256702423, -0.0015847801696509123, 0.020125849172472954, 0.05965109542012215, 0.019030632451176643, 0.044103045016527176, 0.022774161770939827, -0.03725363314151764, 0.017931446433067322, 0.04620305821299553, -0.0030202651396393776, -0.010924911126494408, -0.019801020622253418, -0.019790906459093094, -0.0299961157143116, -0.012306608259677887, -0.09995106607675552, 0.0005921195261180401, -0.02158822864294052, 0.03308514133095741, -0.0032988956663757563, -0.02997361496090889, 0.020182164385914803, -0.0025272059720009565, 0.008267715573310852, -0.004553230945020914, -0.006584221962839365, 0.003979245200753212, 0.04757964611053467, -0.011593795381486416, -0.03312135860323906, -0.027103740721940994, 0.039775438606739044, 0.03522750735282898, -0.038182687014341354, 0.02945069968700409, -0.013187598437070847, 0.011662544682621956, -0.031419094651937485, 0.008027720265090466, -0.05414923280477524, 0.015536714345216751, 0.01704579032957554, -0.03706458583474159, -0.020808640867471695, -0.027942759916186333, -0.034534554928541183, -0.0039139362052083015, -0.006916904356330633, 0.03508568927645683, -0.015202967450022697, -0.010319504886865616, 0.012520634569227695, 0.011160455644130707, 0.0021434961818158627, 0.018841657787561417, 0.055027157068252563, -0.0036051699426025152, 0.042358141392469406, -0.018652722239494324, -0.03279532864689827, -0.029613377526402473, -0.03410319983959198, -0.018511896952986717, -0.04164871573448181, 0.023000672459602356, -0.021638620644807816, 0.025281110778450966, -0.024853045120835304, -0.016384467482566833, -0.006527244579046965, -0.054718729108572006, 0.03412358835339546, -0.005176553502678871, 0.018194563686847687, -0.0251181498169899, 0.019215183332562447, -0.0605732724070549, -0.006491199601441622, -0.02368960529565811, 0.036249060183763504, -0.08361057937145233, 0.04173267260193825, 0.02535310573875904, -0.025447344407439232, -0.02728741057217121, -0.028511909767985344, 0.055752918124198914, -0.015273002907633781, 0.01837337575852871, -0.02100985124707222, -0.039749398827552795, -0.03137373924255371, -0.015520508401095867, -0.03965923190116882, 0.03565525263547897, -0.04514510557055473, -0.030364802107214928, -0.005717948544770479, -0.0030565522611141205, 0.03826206922531128, -0.02248767577111721, -0.042315393686294556, 0.024843143299221992, 0.01578696258366108, 0.01048743724822998, 0.016933085396885872, -0.015267654322087765, 0.018462931737303734, 0.02204413153231144, -0.014949205331504345, 0.015251722186803818, -0.0621858611702919, 0.01646341383457184, -0.01674887351691723, -0.02313089556992054, 0.0058433362282812595, 0.0302513986825943, -0.03707281872630119, -0.021608222275972366, -0.003464300651103258, 0.02803819067776203, -0.025880873203277588, 0.02361144870519638, 0.036843009293079376, 0.005511480383574963, 0.03573623672127724, 0.028736017644405365, 0.04406377673149109, 0.054429791867733, -0.0025860690511763096, 0.0014134208904579282, -0.021666239947080612, 0.025263164192438126, 0.04277830198407173, 0.036318011581897736, 0.01112707331776619, 0.03007788583636284, -0.03594789281487465, 0.032287128269672394, -0.023480180650949478, 0.036008644849061966, -0.08037299662828445, 0.029377363622188568, 0.05876234173774719, -0.045468900352716446, -0.004315889906138182, 0.016398590058088303, -0.042826827615499496, 0.008568416349589825, -0.01274930965155363, 0.011812232434749603, 0.018529487773776054, -0.006119921803474426, -0.0281387772411108, -0.013990412466228008, -0.023087559267878532, -0.008097660727798939, -0.033297501504421234, 0.03710770234465599, 0.03627709299325943, 8.814484317554161e-05, 0.034625157713890076, 0.03499387577176094, -0.006878448184579611, 0.037984445691108704, 0.03068266250193119, -0.019643470644950867, -0.011084373109042645, 0.015571339055895805, 0.018623346462845802, 0.050923384726047516, 0.0014475631760433316, 0.01957513578236103, 0.0013707693433389068, 0.032454658299684525, -0.05871383845806122, 0.012190387584269047, -0.012486889027059078, -0.01679045334458351, 0.013265193440020084, 0.017298679798841476, 0.025774428620934486, 0.01676488295197487, 0.0017289286479353905, -0.020951002836227417, 0.08859511464834213, -0.025477832183241844, 0.011606679297983646, 0.0027499974239617586, -0.01630283333361149, -0.02498553693294525, -0.032136302441358566, 0.022928481921553612]}
```

# 4. 利用

Python で利用したい場合は以下のようになります。

https://github.com/oyahiroki/nlp4j-llm-embeddings-e5/blob/main/bin/nlp4j-embedding-server-e5-testclient.py

```python
import requests
import json
import time

# リクエストを送信するURL
url = "http://127.0.0.1:8888/"
params = {"text": "これはテストです。"}

try:
    # リクエスト送信前のタイムスタンプ
    start_time = time.time()
    # GETリクエストを送信
    response = requests.get(url, params=params)
    # リクエスト送信後のタイムスタンプ
    end_time = time.time()
    # レスポンスのステータスコードを確認
    response.raise_for_status()
    # JSONレスポンスをパース
    data = response.json()
    # 処理時間を計算
    elapsed_time = end_time - start_time
    # 結果を表示
    print("Message:", data["message"])
    print("Time:", data["time"])
    print("Text:", data["text"])
    print("Embeddings (first 5):", data["embeddings"][:5])  # 埋め込みの最初の5要素を表示
    print(f"リクエストからレスポンス受信までの時間: {elapsed_time:.4f} 秒")
except requests.exceptions.RequestException as e:
    print(f"HTTPリクエスト中にエラーが発生しました: {e}")
except json.JSONDecodeError as e:
    print(f"JSONのパース中にエラーが発生しました: {e}")
```

REST API なので Java などのほかの言語からも利用可能です。

Java向けには専用のライブラリも用意してあります。

https://github.com/oyahiroki/nlp4j/blob/master/nlp4j/nlp4j-llm/src/test/java/nlp4j/llm/embeddings/EmbeddingServiceViaHttpTestCase.java

```java
String text = "今日はとてもいい天気です。";
String endPoint = "http://localhost:8888/";
EmbeddingServiceViaHttp nlp = new EmbeddingServiceViaHttp(endPoint);
NlpServiceResponse res = nlp.process(text);
EmbeddingResponse r = (new Gson()).fromJson(res.getOriginalResponseBody(), EmbeddingResponse.class);
System.err.println(Arrays.toString(r.getEmbeddings()));
  ```
  
# [EOF]

以上.