作者:來(lái)自 Elastic?Serena Chou, Jonathan Buttner, Dave Kyle
我們很高興地宣布 Elasticsearch 現(xiàn)在支持 Cohere 嵌入! 發(fā)布此功能是與 Cohere 團(tuán)隊(duì)合作的一次偉大旅程,未來(lái)還會(huì)有更多合作。 Cohere 是生成式 AI 領(lǐng)域令人興奮的創(chuàng)新者,我們很自豪能夠讓開(kāi)發(fā)人員使用 Cohere 令人難以置信。
Elastic 的交付方法:頻繁、生產(chǎn)就緒的迭代
在我們深入探討之前,如果你是 Elastic 的新手(歡迎!),我們始終相信投資我們選擇的技術(shù) (Apache Lucene) 并確保貢獻(xiàn)可以用作生產(chǎn)級(jí)功能,以我們最快的發(fā)布模式可以提供。
讓我們深入了解一下我們迄今為止所構(gòu)建的內(nèi)容以及我們很快將能夠提供的內(nèi)容:
- 2023 年 8 月,我們討論了我們對(duì) Lucene 的貢獻(xiàn),以實(shí)現(xiàn)最大內(nèi)積并使 Cohere 嵌入成為 Elastic Stack 的一等公民。
- 它首先被貢獻(xiàn)到 Lucene 中,并在 Elasticsearch 8.11 版本中發(fā)布。
- 在同一版本中,我們還推出了 /_inference API 端點(diǎn)的技術(shù)預(yù)覽,該端點(diǎn)支持 Elasticsearch 中管理的模型的嵌入,但很快在接下來(lái)的版本中,我們建立了與 Hugging Face 和 OpenAI 等第三方模型提供商的集成模式。
Cohere 嵌入支持已經(jīng)向參與我們?cè)?Elastic Cloud 上的 stateless 產(chǎn)品預(yù)覽的客戶(hù)提供,并且很快將在即將發(fā)布的 Elasticsearch 版本中向所有人提供。
你需要一個(gè) Cohere 帳戶(hù),以及一些 Cohere Embed 端點(diǎn)的使用知識(shí)。 你可以選擇可用的模型,但如果你只是第一次嘗試,我們建議你使用模型 embed-english-v3.0,或者如果你正在尋找多語(yǔ)言變體,請(qǐng)嘗試 embed-multilingual-v3.0,維度大小為 1024。
在 Kibana 中,即使沒(méi)有設(shè)置 IDE,你也可以訪問(wèn)控制臺(tái),以便在 Elasticsearch 中輸入這些后續(xù)步驟。
PUT _inference/text_embedding/cohere_embeddings
{
"service": "cohere",
"service_settings": {
"api_key": <api-key>,
"model_id": "embed-english-v3.0",
"embedding_type": "byte"
}
}
當(dāng)你選擇在控制臺(tái)中運(yùn)行此命令時(shí),你應(yīng)該會(huì)看到相應(yīng)的 200,用于創(chuàng)建你的命名 Cohere 推理服務(wù)。 在此配置中,我們指定 embedding_type 為 byte,這相當(dāng)于要求 Cohere 返回帶符號(hào)的 int8 嵌入。 僅當(dāng)你選擇使用 v3 模型時(shí),這才是有效的配置。
你需要在索引中設(shè)置映射,以便為存儲(chǔ)即將從 Cohere 檢索的嵌入做好準(zhǔn)備。
Cohere 嵌入的 Elasticsearch 向量數(shù)據(jù)庫(kù)
PUT cohere-embeddings
{
"mappings": {
"properties": {
"name_embedding": {
"type": "dense_vector",
"dims": 1024,
"element_type": "byte"
},
"name": {
"type": "text"
}
}
}
}
在映射的定義中,你會(huì)發(fā)現(xiàn) Elastic 團(tuán)隊(duì)對(duì) Lucene 做出的另一個(gè)貢獻(xiàn)的一個(gè)很好的例子,即使用標(biāo)量量化的能力。
只是為了好玩,我們粘貼了你將在入門(mén)體驗(yàn)中看到的命令,該命令攝取簡(jiǎn)單的圖書(shū)目錄。
POST _bulk?pretty
{ "index" : { "_index" : "books" } }
{"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
{ "index" : { "_index" : "books" } }
{"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
{ "index" : { "_index" : "books" } }
{"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
{ "index" : { "_index" : "books" } }
{"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
{ "index" : { "_index" : "books" } }
{"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
{ "index" : { "_index" : "books" } }
{"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
此時(shí),你的 books 內(nèi)容已位于 Elasticsearch 索引中,現(xiàn)在你需要啟用 Cohere 在文檔上生成嵌入!
為了完成此步驟,你將設(shè)置一個(gè) ingest pipeline,該管道使用我們的 inference processor 來(lái)調(diào)用你在第一個(gè) PUT 請(qǐng)求中定義的推理服務(wù)。
PUT _ingest/pipeline/cohere_embeddings
{
"processors": [
{
"inference": {
"model_id": "cohere_embeddings",
"input_output": {
"input_field": "name",
"output_field": "name_embedding"
}
}
}
]
}
如果你沒(méi)有攝取像本書(shū)目錄這樣簡(jiǎn)單的內(nèi)容,你可能想知道如何處理所選模型的 token 限制。
如果需要,你可以快速修改創(chuàng)建的 ingest pipeline 以對(duì)大型文檔進(jìn)行分塊,或者在首次攝取之前使用其他轉(zhuǎn)換工具來(lái)處理分塊。
如果你正在尋找其他工具來(lái)幫助確定分塊策略,那么搜索實(shí)驗(yàn)室中的這些 notebooks 就是你的最佳選擇。
有趣的是,在不久的將來(lái),Elasticsearch 開(kāi)發(fā)人員將完全可以選擇此步驟。 正如本博客開(kāi)頭所提到的,我們今天向你展示的這種集成為未來(lái)的更多變化奠定了堅(jiān)實(shí)的基礎(chǔ)。 其中之一將是此步驟的大幅簡(jiǎn)化,你根本不必?fù)?dān)心分塊,也不必?fù)?dān)心攝取管道的構(gòu)建和設(shè)計(jì)。 Elastic 將以出色的默認(rèn)設(shè)置為你處理這些步驟!
你已經(jīng)設(shè)置了目標(biāo)索引和攝取管道,現(xiàn)在是時(shí)候重新索引以強(qiáng)制文檔完成該步驟了。
POST _reindex
{
"source": {
"index": "books",
"size": 50
},
"dest": {
"index": "cohere-embeddings",
"pipeline": "cohere_embeddings"
}
}
用于 Cohere 向量嵌入的 Elastic?kNN 搜索
現(xiàn)在你已準(zhǔn)備好使用 Cohere 嵌入進(jìn)行第一個(gè)向量搜索。
GET cohere-embeddings/_search
{
"knn": {
"field": "content_embedding",
"query_vector_builder": {
"text_embedding": {
"model_id": "cohere_embeddings",
"model_text": "Snow"
}
},
"k": 10,
"num_candidates": 100
},
"_source": [
"name",
"author"
]
}
就這么簡(jiǎn)單。
如果你已經(jīng)對(duì)向量搜索有了很好的理解,我們強(qiáng)烈建議你閱讀這篇關(guān)于將 kNN 作為查詢(xún)運(yùn)行的博客 - 這將解鎖專(zhuān)家模式!
與 Cohere 的集成以 stateless 方式提供,很快就可以在 Elastic Cloud、筆記本電腦或自我管理環(huán)境中的版本化 Elasticsearch 版本中進(jìn)行嘗試。
祝你搜索愉快,再次感謝 Cohere 團(tuán)隊(duì)在此項(xiàng)目上的合作!
準(zhǔn)備好將 RAG 構(gòu)建到你的應(yīng)用程序中了嗎? 想要嘗試使用向量數(shù)據(jù)庫(kù)的不同 LLMs?
在 Github 上查看我們的 LangChain、Cohere 等示例 notebooks,并參加即將開(kāi)始的 Elasticsearch 工程師培訓(xùn)!文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-845925.html
原文:Elasticsearch open inference API adds support for Cohere Embeddings — Elastic Search Labs文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-845925.html
到了這里,關(guān)于Elasticsearch 開(kāi)放 inference API 增加了對(duì) Cohere Embeddings 的支持的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!