作者:來自 Elastic?Andre Luiz
了解如何在 Elasticsearch 中使用 Amazon Nova 系列模型。
在本文中,我們將討論 Amazon 的 AI 模型家族——Amazon Nova,并學習如何將其與 Elasticsearch 結合使用。
關于 Amazon Nova
Amazon Nova 是 Amazon 的一系列人工智能模型,可在 Amazon Bedrock 上使用,旨在提供高性能和成本效益。這些模型支持文本、圖像和視頻輸入,生成文本輸出,并針對不同的準確性、速度和成本需求進行了優化。
Amazon Nova 主要模型
-
Amazon Nova Micro:專注于文本處理的快速、經濟高效模型,適用于翻譯、推理、代碼補全和數學問題求解。其生成速度超過 200 個 token 每秒,非常適合需要即時響應的應用。
-
Amazon Nova Lite:一種低成本的多模態模型,可快速處理圖像、視頻和文本。其速度和準確性表現突出,適用于交互式和高數據量的應用,尤其是成本敏感的場景。
-
Amazon Nova Pro:最高級的選擇,結合了高準確性、速度和成本效益。適用于視頻摘要、問答、軟件開發和 AI 代理等復雜任務。專家評測表明,它在文本和視覺理解方面表現卓越,并且能夠遵循指令執行自動化工作流。
Amazon Nova 模型適用于多種應用場景,包括內容創作、數據分析、軟件開發以及基于 AI 的流程自動化。
我們將展示如何將 Amazon Nova 模型與 Elasticsearch 結合使用,以實現自動化的產品評論分析。
我們將進行以下步驟:
-
通過 Inference API 創建一個端點,將 Amazon Bedrock 與 Elasticsearch 集成。
-
使用 Inference Processor 創建一個數據處理管道,該管道將調用 Inference API 端點。
-
索引產品評論,并使用管道自動生成評論分析。
-
分析集成后的結果。
在 Inference API 中創建端點
首先,我們配置 Inference API 以將 Amazon Bedrock 與 Elasticsearch 集成。我們選擇 Amazon Nova Lite 作為使用的模型,其 ID 為 amazon.nova-lite-v1:0,因為它在速度、準確性和成本之間提供了良好的平衡。
注意:你需要有效的憑據才能使用 Amazon Bedrock。你可以在此處查看文檔以獲取訪問密鑰:
PUT _inference/completion/bedrock_completion_amazon_nova-lite
{"service": "amazonbedrock","service_settings": {"access_key": "#access_key#","secret_key": "#secret_key#","region": "us-east-1","provider": "amazontitan","model": "amazon.nova-lite-v1:0"}
}
創建評論分析 pipeline
現在,我們創建一個處理流水線,該流水線將使用 Inference Processor 來執行評論分析提示(prompt)。該提示會將評論數據發送到 Amazon Nova Lite,并執行以下操作:
-
情感分類(正面、負面或中立)
-
評論摘要生成
-
關鍵詞提取
-
真實性評估(真實 | 可疑 | 泛化)
PUT /_ingest/pipeline/review_analyzer_ai
{"processors": [{"script": {"source": """ctx.prompt = "Analyze the following product review and return a structured JSON. Task: - Summarize the review concisely. - Detect and classify the sentiment as positive, neutral, or negative.- Generate relevant tags (keywords) based on the review content and detected sentiment. - Evaluate the authenticity of the review (authentic, suspicious, or generic). Review: " + ctx.review + " Respond in JSON format with the following fields: \"review_analyze\": {\"sentiment\": \"<positive | neutral | negative>\", \"authenticity\": \"<authentic | suspicious | generic>\",\"summary\": \"<short review summary>\", \"keywords\": [\"<keyword 1>\", \"<keyword 2>\", \"...\"]}}}""""}},{"inference": {"model_id": "bedrock_completion_amazon_nova-lite","input_output": {"input_field": "prompt","output_field": "result"}}},{"gsub": {"field": "result","pattern": "```json","replacement": ""} },{"json" : {"field" : "result","strict_json_parsing": false,"add_to_root" : true}},{"remove": {"field": "result"}},{"remove": {"field": "prompt"}}]
}
索引評論
現在,我們使用 Bulk API 索引產品評論。之前創建的流水線將自動應用,并將 Nova 模型生成的分析結果添加到索引的文檔中。
POST bulk/
{ "index": { "_index" : "products", "_id": 1, "pipeline":"review_analyzer_ai" } }
{ "product": "Pampers Pants Premium Care Fralda", "review": "Best diaper ever! Great material, lots of cotton, without all that plastic. Doesn't leak! My baby is a boy and every diaper leaked around the waist, this model solved the problem. Even on a small baby it's worth the effort of putting on the short diaper. I put it on my baby at 9 pm and only take it off in the morning, without any leaks." }
{ "index": { "_index" : "products", "_id": 2, "pipeline":"review_analyzer_ai" } }
{ "product": "Portable Electric Body Massager", "review": "It broke in three months for no apparent reason, thank goodness I didn't review it before. I don't recommend buying it because it has a short lifespan." }
{ "index": { "_index" : "products", "_id": 3, "pipeline":"review_analyzer_ai" } }
{ "product": "Havit Fuxi-H3 Black Quad-Mode Wired and Wireless Gaming Headset", "review": "The sound is good for the price, but the connectivity is horrible. You always need to be playing audio, otherwise it loses connection (I work from home, and this is very annoying). Sometimes it loses connection and you have to turn it off and on again to get it back on. The microphone is very sensitive, so it loses connection frequently and you have to turn the headset off and on for the microphone to work again. The flexibility of the stem is useless, because if you move it, the microphone can turn off. Sometimes I need to use Linux and the headset simply doesn't work. It's light and comfortable, the sound is adequate, but the connectivity is terrible." }
{ "index": { "_index" : "products", "_id": 4, "pipeline":"review_analyzer_ai" } }
{ "product": "Air Fryer 4L Oil Free Fryer Mondial", "review": "For those looking for value for money, it's a good option, but the tray (which is underneath the perforated basket) is already peeling a lot. My mother has one just like it and said that hers is even rusting, in other words, the material is MUCH inferior. There's also something that bothers me, because it looks like a microwave, it doesn't fry evenly, it's weaker in the middle and stronger on the sides. Buy at your own risk." }
查詢和分析結果
最后,我們運行查詢以查看 Amazon Nova Lite 模型如何分析和分類評論。通過執行 GET products/_search,我們可以獲取已經被評論內容增強的文檔。
該模型能夠識別主要情感(正面、中立或負面),生成簡要摘要,提取相關關鍵詞,并評估每條評論的 真實性。這些字段有助于理解客戶的意見,而無需閱讀完整文本。
在解釋結果時,我們關注以下方面:
-
情感:指示消費者對產品的整體感受。
-
摘要:提煉評論中提及的主要觀點。
-
關鍵詞:可用于分組相似評論或識別反饋模式。
-
真實性:判斷評論是否可信,對內容審核或篩選有幫助。
"hits": [{"_index": "products","_id": "1","_score": 1,"_ignored": ["review.keyword"],"_source": {"product": "Pampers Pants Premium Care Fralda","model_id": "bedrock_completion_amazon_nova-lite","review_analyze": {"summary": "The reviewer praises the diaper for its great material, high cotton content, and leak-proof design, especially highlighting its effectiveness for their baby.","sentiment": "positive","keywords": ["best diaper","great material","cotton","no plastic","leak-proof","baby","effective"],"authenticity": "authentic"},"review": "Best diaper ever! Great material, lots of cotton, without all that plastic. Doesn't leak! My baby is a boy and every diaper leaked around the waist, this model solved the problem. Even on a small baby it's worth the effort of putting on the short diaper. I put it on my baby at 9 pm and only take it off in the morning, without any leaks."}},{"_index": "products","_id": "2","_score": 1,"_source": {"product": "Portable Electric Body Massager","model_id": "bedrock_completion_amazon_nova-lite","review_analyze": {"summary": "The product broke in three months for no apparent reason and the reviewer does not recommend it due to its short lifespan.","sentiment": "negative","keywords": ["broke","short lifespan","not recommend"],"authenticity": "authentic"},"review": "It broke in three months for no apparent reason, thank goodness I didn't review it before. I don't recommend buying it because it has a short lifespan."}},{"_index": "products","_id": "3","_score": 1,"_ignored": ["review.keyword"],"_source": {"product": "Havit Fuxi-H3 Black Quad-Mode Wired and Wireless Gaming Headset","model_id": "bedrock_completion_amazon_nova-lite","review_analyze": {"summary": "The headset has good sound quality for the price but suffers from poor connectivity, especially when using the microphone or moving the headset. It also has compatibility issues with Linux.","sentiment": "negative","keywords": ["sound","connectivity","microphone","compatibility","annoying","turn off and on","Linux","flexible stem","work from home"],"authenticity": "authentic"},"review": "The sound is good for the price, but the connectivity is horrible. You always need to be playing audio, otherwise it loses connection (I work from home, and this is very annoying). Sometimes it loses connection and you have to turn it off and on again to get it back on. The microphone is very sensitive, so it loses connection frequently and you have to turn the headset off and on for the microphone to work again. The flexibility of the stem is useless, because if you move it, the microphone can turn off. Sometimes I need to use Linux and the headset simply doesn't work. It's light and comfortable, the sound is adequate, but the connectivity is terrible."}},{"_index": "products","_id": "4","_score": 1,"_ignored": ["review.keyword"],"_source": {"product": "Air Fryer 4L Oil Free Fryer Mondial","model_id": "bedrock_completion_amazon_nova-lite","review_analyze": {"summary": "The product offers value for money but has issues with peeling, rusting, and uneven frying.","sentiment": "negative","keywords": ["value for money","peeling","rusting","uneven frying","weaker in the middle"],"authenticity": "authentic"},"review": "For those looking for value for money, it's a good option, but the tray (which is underneath the perforated basket) is already peeling a lot. My mother has one just like it and said that hers is even rusting, in other words, the material is MUCH inferior. There's also something that bothers me, because it looks like a microwave, it doesn't fry evenly, it's weaker in the middle and stronger on the sides. Buy at your own risk."}}]
最終想法
Amazon Nova Lite 與 Elasticsearch 的集成展示了語言模型如何將原始評論轉化為結構化且有價值的信息。通過流水線處理評論,我們能夠自動且一致地提取 情感、真實性、摘要 和 關鍵詞。
結果表明,該模型能夠理解評論的上下文、分類用戶的意見,并突出顯示每個體驗中最相關的點。這使數據集更加豐富,可用于提升搜索能力。
想要獲得 Elastic 認證?查看下一次 Elasticsearch Engineer 培訓時間!
Elasticsearch 擁有眾多新功能,可幫助你構建最佳搜索解決方案。探索我們的示例 notebooks 了解更多信息,開啟 免費云試用,或立即在本地機器嘗試 Elastic!
原文:https://www.elastic.co/search-labs/blog/amazon-nova-models-elasticsearch