Elastic Playground:使用 Elastic 连接器与你的数据聊天

作者:来自 Elastic Jeffrey RengifoTomás Murúa

了解如何使用 Elastic 连接器通过 Playground 创建统一的知识库。

Elastic 连接器可以轻松索引和组合来自不同来源的数据以运行统一搜索。通过添加 Playground,你可以设置一个可以与之聊天和提问的知识库。

连接器(Connectors)是一种 Elastic 集成,有助于将来自不同来源的数据同步到 Elasticsearch 索引。

在本文中,我们将了解如何使用 Elastic 连接器索引 Confluence Wiki,配置索引以运行语义查询,然后使用 Playground 与数据聊天。

步骤

  • 配置连接器
  • 准备索引
  • 使用 Playground 与数据聊天

配置连接器

在我们的示例中,我们的 Wiki 作为医院的集中存储库,包含以下信息:

  • 医生资料:专业、可用性、联系信息。
  • 患者档案:医疗记录和其他相关数据。
  • 医院指南:政策、应急方案和员工指导。

我们将使用 Elasticsearch 管理的 Confluence 连接器索引 Wiki 中的内容。

第一步是获取您的 Atlassian API 密钥

配置 Confluence 原生连接器

你可以按照此处的步骤指导你完成配置:

  1. 访问你的 Kibana 实例并转到 Search > Connectors
  2. 单击 "添加连接器"并从列表中选择 "Confluence"。
  3. 将新连接器命名为 "hospital"。
  4. 然后单击 "创建新索引" 按钮。
  5. 单击"edit configurations",对于此示例,我们需要修改 "confluence cloud" 的数据源。必填字段为:
    1. Confluence Cloud 帐户电子邮件
    2. API 密钥
    3. Confluence URL 标签
  6. 保存配置并转到下一步。

默认情况下,连接器将索引:

  • Pages
  • Spaces
  • Blog Posts
  • Attachments

为确保仅索引 wiki,你需要使用高级过滤规则,仅包含名为 "Hospital Health" 的空间内标识为 "HH" 的页面。

markdown 复制代码
1.  [
2.    {
3.      "query": "type = 'page' AND space.key = 'HH'"
4.    }
5.  ]

你可以在此处查看更多示例。

现在,让我们运行 "Full Content Sync" 来索引我们的 wiki。

完成后,我们可以在 "Documents" 选项卡上检查索引文档。

准备索引

凭借目前所拥有的,我们可以对内容运行全文查询(full text)。由于我们想要提出问题而不是寻找关键词,因此我们现在需要进行语义搜索

为此,我们将使用 Elasticsearch ELSER 模型作为嵌入提供程序。

要配置此功能,请使用 Elasticsearch 的推理 API(inference API)。

转到 Kibana Dev Tools 并复制此代码以启动端点:

bash 复制代码
1.  PUT _inference/sparse_embedding/hospital-inference
2.  {
3.    "service": "elser",
4.    "service_settings": {
5.      "num_allocations": 1,
6.      "num_threads": 1
7.    }
8.  }

现在模型正在后台加载。如果你以前没有使用过 ELSER 模型,可能会收到 502 Bad Gateway 错误。要确保模型正在加载,请检查 Machine Learning > Trained Models:

让我们使用 UI 添加 semantic_text 字段。转到 connector 页面,选择索引映射,然后单击 Add Field

选择 "Semantic text" 作为字段类型。对于此示例,引用字段将为 "body",字段名称为 content_semantic。最后,选择我们刚刚配置的推理端点。

在单击 "Add field" 之前,请检查你的配置是否与以下内容类似:

现在点击 "Save mapping":

从 UI 运行 Full Content Sync 后,让我们通过运行语义查询来检查它是否正常:

bash 复制代码
1.  GET hospital/_search
2.  {
3.    "size": 1,
4.    "_source": {
5.      "excludes": [
6.        "*embeddings",
7.        "*chunks"
8.      ]
9.    },
10.    "query": {
11.      "semantic": {
12.        "field": "content_semantic",
13.        "query": "doctors information"
14.      }
15.    }
16.  }

响应看起来应该是这样的:

xml 复制代码
1.  "hits": {
2.      "total": {
3.        "value": 4,
4.        "relation": "eq"
5.      },
6.      "max_score": 6.8836327,
7.      "hits": [
8.        {
9.          "_index": "hospital",
10.          "_id": "7602523",
11.          "_score": 6.8836327,
12.          "_ignored": [
13.            "body.enum"
14.          ],
15.          "_source": {
16.            "author": "your-confluence-name",
17.            "content_semantic": {
18.              "inference": {
19.                "inference_id": "hospital-inference",
20.                "model_settings": {
21.                  "task_type": "sparse_embedding"
22.                }
23.              }
24.            },
25.            "type": "page",
26.            "title": "Patient Records",
27.            "body": """<p>Patient: Maria Gonzalez</p><ac:structured-macro ac:><ac:plain-text-body><![CDATA[• Patient ID: P-10234 • Date of Birth: January 15, 1985 • Gender: Female • Blood Type: O+ • Emergency Contact: • Name: Juan Gonzalez (Husband) • Phone: +56 9 1234 5678 • Allergies: Penicillin • Chronic Conditions: Type 2 Diabetes • Current Medications: • Metformin 500 mg (twice daily) • Lisinopril 10 mg (once daily) • Recent Visits: 1. October 5, 2024: • Reason: Regular diabetes check-up. • Findings: Stable HbA1c levels (6.8%). • Treatment: Continue current medication. 2. November 2, 2024: • Reason: Minor injury (ankle sprain). • Treatment: Bandage, physical therapy recommended. • Primary Physician: Dr. Juan Pérez Rodríguez (Cardiology) • Notes: • Patient shows good compliance with diabetes management plan. • Follow-up appointment scheduled for January 10, 2025.]]></ac:plain-text-body></ac:structured-macro><p>Patient: Carlos Lopez</p><ac:structured-macro ac:><ac:plain-text-body><![CDATA[• Patient ID: P-10987 • Date of Birth: March 23, 1970 • Gender: Male • Blood Type: A- • Emergency Contact: • Name: Sofia Lopez (Daughter) • Phone: +56 9 2345 6789 • Allergies: None reported • Chronic Conditions: Hypertension • Current Medications: • Losartan 50 mg (once daily) • Atorvastatin 20 mg (once daily) • Recent Visits: 1. September 10, 2024: • Reason: Chest pain. • Findings: No evidence of cardiac issues; diagnosed as acid reflux. • Treatment: Prescribed omeprazole. 2. October 20, 2024: • Reason: Blood pressure follow-up. • Findings: BP controlled at 130/85 mmHg. 3. November 15, 2024: • Reason: Flu symptoms. • Treatment: Prescribed antiviral medication. • Primary Physician: Dr. Maria Fernanda López (Pediatrics/General Medicine) • Notes: • Needs annual cardiovascular evaluation. • Recommended diet and exercise modifications.]]></ac:plain-text-body></ac:structured-macro><p>Patient: Ana Torres</p><ac:structured-macro ac:><ac:plain-text-body><![CDATA[• Patient ID: P-12345 • Date of Birth: July 12, 1992 • Gender: Female • Blood Type: AB+ • Emergency Contact: • Name: Luis Torres (Brother) • Phone: +56 9 3456 7890 • Allergies: None reported • Chronic Conditions: None reported • Current Medications: None • Recent Visits: 1. June 18, 2024: • Reason: Routine physical exam. • Findings: All tests normal. 2. October 5, 2024: • Reason: Severe headache. • Findings: Diagnosed with tension headache. • Treatment: Prescribed ibuprofen and stress management techniques. • Primary Physician: Dr. Carolina Martínez Torres (Dermatology) • Notes: • Advised to monitor hydration and sleep patterns. • Referred to counseling for stress management.]]></ac:plain-text-body></ac:structured-macro><p>Patient: Roberto Castillo</p><ac:structured-macro ac:><ac:plain-text-body><![CDATA[• Patient ID: P-15432 • Date of Birth: August 5, 1965 • Gender: Male • Blood Type: B+ • Emergency Contact: • Name: Elena Castillo (Wife) • Phone: +56 9 4567 8901 • Allergies: Sulfa drugs • Chronic Conditions: Chronic Obstructive Pulmonary Disease (COPD) • Current Medications: • Tiotropium inhaler (once daily) • Salbutamol (as needed) • Recent Visits: 1. August 20, 2024: • Reason: Difficulty breathing. • Findings: COPD exacerbation due to respiratory infection. • Treatment: Prescribed antibiotics and corticosteroids. 2. November 10, 2024: • Reason: Routine COPD management. • Findings: Improved lung function post-treatment. • Primary Physician: Dr. Esteban González Martínez (Orthopedics/General Care) • Notes: • Patient advised to avoid smoking and cold weather. • Pulmonary rehabilitation program recommended.]]></ac:plain-text-body></ac:structured-macro><p>Patient: Lucia Rivera</p><ac:structured-macro ac:><ac:plain-text-body><![CDATA[• Patient ID: P-17654 • Date of Birth: May 19, 2000 • Gender: Female • Blood Type: O- • Emergency Contact: • Name: Pedro Rivera (Father) • Phone: +56 9 5678 9012 • Allergies: Latex • Chronic Conditions: Asthma • Current Medications: • Fluticasone inhaler (daily) • Albuterol (as needed for acute symptoms) • Recent Visits: 1. July 15, 2024: • Reason: Asthma exacerbation. • Findings: Trigger identified as seasonal pollen. • Treatment: Adjusted inhaler dosage. 2. October 25, 2024: • Reason: Follow-up visit. • Findings: Asthma under control; no acute symptoms reported. • Primary Physician: Dr. Maria Fernanda López (Pediatrics) • Notes: • Recommended allergy testing for better management. • Advised to carry rescue inhaler at all times.]]></ac:plain-text-body></ac:structured-macro>""",
28.            "space": "Hospital Health",
29.            "url": "https://tomasmurua.atlassian.net/wiki/spaces/HH/pages/7602523/Patient+Records",
30.            "labels": [],
31.            "createdDate": "2024-11-19T16:08:47.765Z",
32.            "id": "7602523",
33.            "ancestors": [
34.              {
35.                "title": "Hospital Health"
36.              }
37.            ],
38.            "_timestamp": "2024-11-19T16:09:33.434Z",
39.            "_allow_access_control": [
40.              "account_id:712020:88983800-6c97-469a-9451-79c2dd3732b5",
41.              "group_id:5c41d427-6ce5-4936-9e07-dada287179e8",
42.              "group_id:26497e10-fe1b-4510-87e4-356c8f60fe49",
43.              "group_id:bbdc180e-eec3-4723-9647-867efb4491be",
44.              "group_id:55332682-d081-46e4-bd8c-9e3a37d03b14"
45.            ]
46.          }
47.        }
48.      ]
49.    }

使用 Playground 与数据聊天

什么是 Playground?

Playground 是一个托管在 Kibana 中的低代码平台,可让你轻松创建 RAG 应用程序并向你的索引提问,无论它们是否具有嵌入。

Playground 不仅提供带有引用的 UI 聊天并提供对查询的完全控制,而且还处理不同的 LLM 来合成答案。

你可以阅读本文以获得更深入的见解,并测试在线演示以熟悉它。

配置 Playground

首先,你只需要任何兼容模型的凭据:

  • OpenAI(或任何与 OpenAI API 兼容的本地模型)
  • Amazon Bedrock
  • Google Gemini

打开 Playground 时,你可以选择配置 LLM 提供程序并选择包含要用作知识库的文档的索引。

对于此示例,我们将使用 OpenAI。你可以查看此链接以了解如何获取 API 密钥

让我们通过单击 "Connect to an LLM > OpenAI" 来创建 OpenAI 连接器,然后填写字段,如下图所示:

要选择我们使用 Confluence connector 创建的索引,请单击 "Add data sources",然后单击该索引。

注意:如果需要,你可以选择多个索引。

现在我们已经完成配置,我们可以开始向模型提出问题。

除了选择在答案中包含源文档的引用之外,你还可以控制将哪些字段发送到 LLM 以用于搜索。

View Code 窗口提供了将其集成到应用程序所需的 Python 代码。

结论

在本文中,我们了解到,我们可以使用连接器来搜索不同来源的信息以及使用 Playground 的知识库。我们还学会了轻松部署 RAG 应用程序来与您的数据进行聊天,而无需离开 Elastic 环境。

想要获得 Elastic 认证?了解下一次 Elasticsearch 工程师培训何时开始!

Elasticsearch 包含许多新功能,可帮助你为你的用例构建最佳搜索解决方案。深入了解我们的示例笔记本以了解更多信息,开始免费云试用,或立即在你的本地机器上试用 Elastic。

原文:Elastic Playground: Using Elastic connectors to chat with your data - Elasticsearch Labs

相关推荐
老纪的技术唠嗑局20 小时前
告别OpenClaw配置丢失——Mindkeeper内测版邀测
大数据·elasticsearch·搜索引擎
Elasticsearch20 小时前
使用 Elasticsearch + Jina embeddings 进行无监督文档聚类
elasticsearch
勇哥的编程江湖1 天前
flinkcdc streaming 同步数据到es记录过程
大数据·elasticsearch·flink·flinkcdc
曾阿伦1 天前
Elasticsearch 7.x 常用命令备忘录
大数据·elasticsearch·搜索引擎
斯特凡今天也很帅1 天前
Elasticsearch数据库专栏(二)DSL语句总结(更新中)
大数据·elasticsearch·搜索引擎
要记得喝水1 天前
适用于 Git Bash 的脚本,批量提交和推送多个仓库的修改
git·elasticsearch·bash
二十七剑1 天前
Elasticsearch的索引问题
大数据·elasticsearch·搜索引擎
A__tao1 天前
Elasticsearch Mapping 一键生成 Java 实体类(支持嵌套 + 自动过滤注释)
java·python·elasticsearch
A__tao1 天前
Elasticsearch Mapping 一键生成 Proto 文件(支持嵌套 + 注释过滤)
大数据·elasticsearch·jenkins
Devin~Y1 天前
高并发电商与AI智能客服场景下的Java面试实战:从Spring Boot到RAG与向量数据库落地
java·spring boot·redis·elasticsearch·spring cloud·kafka·rag