在 Elasticsearch 中使用 Amazon Nova 模型
了解如何在 Elasticsearch 中使用 Amazon Nova 模型,自动从产品评论中提取情感倾向、真实性判断、内容摘要及关键词。
在本文中,我们将讨论亚马逊的人工智能模型系列 Amazon Nova,并学习如何将其与 Elasticsearch 结合使用。
关于亚马逊新星
Amazon Nova 是亚马逊人工智能模型系列,可在亚马逊 Bedrock 上使用,旨在提供高性能和高成本效益。这些模型可使用文本、图像和视频输入,生成文本输出,并针对不同的精度、速度和成本需求进行了优化。
亚马逊 Nova 主要型号
亚马逊 Nova Micro:该机型专门针对文本,速度快、性价比高,是翻译、推理、代码补全和解决数学问题的理想之选。其生成速度超过每秒 200 个令牌,非常适合需要即时响应的应用。
Amazon Nova Lite:一款低成本多模态模型,能够快速处理图像、视频及文本数据。该模型以其速度和准确性脱颖而出,适用于成本因素显著的大流量交互式应用场景。
亚马逊新星专业版:最先进的选择,集高精度、高速度和高性价比于一身。是视频摘要、问答、软件开发和人工智能代理等复杂任务的理想选择。专家评论证明了它在文本和视觉理解方面的卓越表现,以及它遵循指令和执行自动工作流程的能力。
亚马逊 Nova 模型适用于各种应用,从内容创建和数据分析到软件开发和人工智能驱动的流程自动化。
下面,我们将演示如何结合 Elasticsearch 使用 Amazon Nova 模型进行自动产品评论分析。
我们将做什么
通过 Inference API 创建一个端点,将 Amazon Bedrock 与 Elasticsearch 集成在一起。
使用推理处理器创建一个管道,该管道将调用推理 API 端点。
索引产品评论,并使用管道自动生成评论分析。
分析整合结果。
使用 Amazon Nova Lite 在推理 API 中创建终端
首先,我们配置 Inference API,将 Amazon Bedrock 与 Elasticsearch 集成。我们定义了亚马逊 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"
}
}创建审查分析管道
现在,我们创建一个处理管道,使用推理处理器来执行审查分析提示。此提示将把评论数据发送到 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"
}
}
]
}索引审查
现在,我们使用批量 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." }查询和分析结果
最后,我们运行一个查询,看看亚马逊 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 的整合展示了语言模型如何将原始评论转化为结构化的有价值信息。通过管道处理评论,我们能够自动、一致地提取情感、真实性、摘要和关键词。
结果表明,该模型可以理解评论的上下文,对用户意见进行分类,并突出每个体验中最相关的要点。这将创建一个更丰富的数据集,可用于提高搜索能力。




