第 2 章 在您的税务树中添加知识


您可以自定义税务树,以便模型能够了解特定域的信息。对于 RHEL AI,您的知识数据托管在 Git 存储库中。知识贡献使用 qna.yaml 文件来了解如何阅读您要呈现模型的文档。每个用于知识的 qna.yaml 文件都包含一组键的键值条目:

Expand
表 2.1. Red Hat Enterprise Linux AI
字段描述约束(constraint)Example

version

qna.yaml 文件中使用的 taxonomy 模式版本。

此参数当前支持的值是 3

3

created_by

供稿者的名称或用户名。

-

kbrown

domain

知识文档的主题或类别。域在复合数据生成期间向教员模型提示并添加额外的上下文。

建议您的 domain 字段不超过三个单词。

有关 Phoenix contestation 的知识文档,域将是 Astronomy

有关健康保险信息的知识文档,域将是 Healthcare

seed_examples

包含与知识文档中的上下文的问答对的字段。

qna.yaml 文件中至少需要五个 seed 示例。

seed_examples:
  - context:
    questions_and_answers:

context

从知识文档中完全获取的信息块。突出显示不同类型的内容,包括表格、段落或列表,以帮助指导教员模型。

每个 qna.yaml 需要五个上下文块,且最大令牌计数为 500 个令牌。

Phoenix 是南部的小拥塞。在 mythical Phoenix_(myththology)后命名,最初在其 1603 Uranometria 的 celestial atlas 上被描述。法语学习者和 astronomer Nicolas Louis de Lacaille 图表了右边星,并在 1756 中给出了他们的"swonomer"设计。

questions_and_answers

包含您模型要学的问题和答案的字段。

每个 qna.yaml 需要每个 上下文 块的三个问题和回答对。

questions_and_answers:
  - question:
    answer:

问题

相关上下文中与 和 相关的问题。提供各种问题和问题类型,包括基于事实的问题、原因或说明。

最大令牌数量为 250 个令牌。

谁绘制了 Phoenix 销售?

回答

对指定问题的回答。答案应处于完整的句子中,并在 context 字段中引用。

最大令牌数量为 250 个令牌。

Phoenix constellation 由 french explorer 和 astronomer Nicolas Louis de Lacaille 图表。

document_outline

文档的简要摘要,类似于sis 语句。这为文档的内容提供了高级别的上下文。

必须详细地参考 context 字段中的内容。

有关 Phoenix Constellation 的信息,包括销售中星星的历史记录、特征和功能。

document

包含您的知识数据源的字段。

-

document:
   repo:
   commit:
   patterns:

repo

包含您的知识文件的 git 存储库的 URL。

-

github.com/<profile>/<repo-name>

commit

与 repo 中文档对应的完整提交哈希

-

-

模式

包含 git 存储库中的文件

有效值包括 .md.pdf

phoenix_constellation.md

用于创建 qna.yaml的其他资源

2.1. 创建知识 YAML 文件

以下流程演示了如何创建一个 qna.yaml 文件,该文件使用 RHEL AI 工具集指导您的 LLM 有关您提供的知识文件。

先决条件

  • 已使用可引导容器镜像安装了 RHEL AI。
  • 安装了 git CLI。
  • 您初始化了 InstructLab,可以使用 ilab CLI。
  • 在机器上具有 root 用户访问权限。

流程

  1. 由于您在 git 存储库中托管您的知识文件,因此在更新税务时,您需要签出一个正常工作的分支。
  2. 导航到 taxonomy 文件夹。RHEL AI 包含可与之交互的税务树。
  3. 导航到 taxonomy 目录中的 knowledge 文件夹。
  4. 在您要添加知识 qna.yaml 文件的 taxonomy 树中添加目录和文件夹。

    taxonomy 树中的文件路径示例

    taxonomy/knowledge/technical_documents/product_customer_cases/qna.yaml

  5. 使用所需的文本编辑器,创建 qna.yaml 文件。您的 YAML 必须具有 qna.yaml 标题。

    注意

    要使 SDG 正确运行,必须至少包含五个 上下文块和三个问题,并在 questions_and_answers 参数中回答每个上下文值的 seeds。

  6. 将所需的密钥添加到 qna.yaml 文件中并保存您的更改。有关格式化 qna.yaml 文件的更多信息,请参阅"Sample knowledge YAML 规格"。

验证

  • 要验证您的知识 qna.yaml 文件是否正确格式,您可以运行以下命令:

    $ ilab taxonomy diff

    如果您的 taxonomy 树和 qna.yaml 文件有效且正确格式化,则 CLI 会显示。CLI 还会显示您在哪里可以修复遇到的任何错误。

    有效 taxonomy 树和 qna.yaml 文件示例

    knowledge/technical_documents/product_customer_cases/qna.yaml
    Taxonomy in /taxonomy/ is valid :)

    无效的 taxonomy 树和 qna.yaml 文件的输出示例

    9:15 error syntax error: mapping values are not allowed here (syntax)
    Reading taxonomy failed with the following error: 1 taxonomy with errors! Exiting.

2.1.1. 知识 YAML 规格示例

知识贡献使用 qna.yaml 文件来了解如何阅读您要呈现模型的文档。在 RHEL AI 上,合成数据生成(SDG)进程使用 qna.yaml seed 示例来创建大量人工数据。这个过程使其使其具有更多数据,以便从中获取更多数据,而不依赖于提供的示例。

知识库 qna.yaml 文件示例

version: 3 
1

domain: astronomy 
2

document_outline: | 
3

  Information about the Phoenix Constellation including the
  history, characteristics, and features of the stars in the constellation.
created_by: <user-name> 
4

seed_examples:
  - context: | 
5

      **Phoenix** is a minor constellation in the southern sky. Named after the mythical
      Phoenix_(mythology), it was first depicted on a celestial atlas by Johann Bayerin his 1603
      Uranometria. The French explorer and astronomer Nicolas Louis de Lacaille charted the brighter stars
      and gave their Bayer designations in 1756. The constellation stretches from roughly −39 degrees to −57
      degrees declination, and from 23.5h to 2.5h of right ascension. The constellations Phoenix, Grus,
      Pavo and Tucana are known as the Southern Birds.
    questions_and_answers:
      - question: | 
6

          What is the Phoenix constellation?
        answer: | 
7

         The Phoenix constellation is a minor constellation in the southern sky.
      - question: |
          Who charted the Phoenix constellation?
        answer: |
          The Phoenix constellation was charted by french explorer and
          astronomer Nicolas Louis de Lacaille.
      - question: |
          How far does the Phoenix constellation stretch?
        answer: |
          The phoenix constellation stretches from roughly −39° to −57°
          declination, and from 23.5h to 2.5h of right ascension.
  - context: |
      Phoenix was the largest of the 12 constellations established by Petrus Plancius from the observations
      of Pieter Dirkszoon Keyser and Frederick de Houtman. It first appeared on a 35cm diameter celestial globe
      published in 1597 (or 1598) in Amsterdam by Plancius with Jodocus Hondius. The first depiction of this
      constellation in a celestial atlas was in Johann Bayer *Uranometria* of 1603. De Houtman included it in
      his southern star catalog the same year under the Dutch name *Den voghel Fenicx*, "The Bird Phoenix",
      symbolising the phoenix of classical mythology. One name of the brightest star Alpha Phoenicis—Ankaa—is
      derived from the Arabic: العنقاء, romanized: al-‘anqā’, lit. 'the phoenix', and was coined sometime after
      1800 in relation to the constellation.
    questions_and_answers:
      - question: |
          What is the brightest star in the Phoenix constellation
          called?
        answer: |
          Alpha Phoenicis or Ankaa is the brightest star in the Phoenix
          Constellation.
      - question: Where did the Phoenix constellation first appear?
        answer: |
          The Phoenix constellation first appeared on a 35-cm diameter
          celestial globe published in 1597 (or 1598) in Amsterdam by
          Plancius with Jodocus Hondius.
      - question: |
          What does "The Bird Phoenix" symbolize?
        answer: |
          "The Bird Phoenix" symbolizes the phoenix of classical mythology.
  - context: |
      Phoenix is a small constellation bordered by Fornax and Sculptor to the north, Grus to the west,
      Tucana to the south, touching on the corner of Hydrus to the south, and Eridanus to the east and southeast.
      The bright star Achernar is nearby. The three-letter abbreviation for the constellation, as adopted by
      the International Astronomical Union in 1922, is "Phe". The official constellation boundaries,
      as set by Belgian astronomer Eugène Delporte in 1930, are defined by a polygon of 10 segments.
      In the equatorial coordinate system, the right ascension coordinates of these borders lie
      between 23<sup>h</sup> 26.5<sup>m</sup> and 02<sup>h</sup> 25.0<sup>m</sup>,
      while the declination coordinates are between −39.31° and −57.84°. This means it remains
      below the horizon to anyone living north of the 40th parallel in the Northern
      Hemisphere, and remains low in the sky for anyone living north of the equator. It is most
      visible from locations such as Australia and South Africa during late Southern Hemisphere spring.
      Most of the constellation lies within, and can be located by, forming a triangle of the bright
      stars Achernar, Fomalhaut and Beta Ceti—Ankaa lies roughly in the centre of this.
    questions_and_answers:
      - question: What are the characteristics of the Phoenix constellation?
        answer: |
          Phoenix is a small constellation bordered by Fornax and Sculptor to
          the north, Grus to the west, Tucana to the south, touching on the
          corner of Hydrus to the south, and Eridanus to the east and southeast.
          The bright star Achernar is nearby.
      - question: |
          When is the phoenix constellation most visible?
        answer: |
          Phoenix is most visible from locations such as Australia and
          South Africa during late Southern Hemisphere spring.
      - question: |
          What are the Phoenix Constellation boundaries?
        answer: |
          The official constellation boundaries for Phoenix, as set by Belgian
          astronomer Eugène Delporte in 1930, are defined by a polygon of 10
          segments.
  - context: |
      Ten stars have been found to have planets to date, and four planetary systems have been
      discovered with the SuperWASP project. HD 142 is a yellow giant that has an apparent magnitude
      of 5.7, and has a planet (HD 142b) 1.36 times the mass of Jupiter which orbits every 328 days.
      HD 2039 is a yellow subgiant with an apparent magnitude of 9.0 around 330 light years away which
      has a planet (HD 2039) six times the mass of Jupiter. WASP-18 is a star of magnitude 9.29 which
      was discovered to have a hot Jupiter-like planet (WASP-18b) taking less than a day to orbit the star.
      The planet is suspected to be causing WASP-18 to appear older than it really is. WASP-4and WASP-5
      are solar-type yellow stars around 1000 light years distant and of 13th magnitude, each with a single
      planet larger than Jupiter. WASP-29 is an orange dwarf of spectral type K4V and visual magnitude 11.3,
      which has a planetary companion of similar size and mass to Saturn. The planet completes an orbit
      every 3.9 days.
    questions_and_answers:
      - question: In the Phoenix constellation, how many stars have planets?
        answer: |
          In the Phoenix constellation, ten stars have been found to have
          planets to date, and four planetary systems have been discovered
          with the SuperWASP project.
      - question: |
          What is HD 142?
        answer: |
          HD 142 is a yellow giant that has an apparent magnitude of 5.7, and
          has a planet (HD 142 b) 1.36 times the mass of Jupiter which
          orbits every 328 days.
      - question: |
          Are WASP-4 and WASP-5 solar-type yellow stars?
        answer: |
          Yes, WASP-4 and WASP-5 are solar-type yellow stars around 1000 light
          years distant and of 13th magnitude, each with a single planet
          larger than Jupiter.
  - context: |
      The constellation does not lie on the galactic plane of the Milky Way, and there are no prominent star
      clusters. NGC 625 is a dwarf irregular galaxy of apparent magnitude 11.0 and lying some 12.7 million
      light years distant. Only 24000 light years in diameter, it is an outlying member of the Sculptor Group.
      NGC 625 is thought to have been involved in a collision and is experiencing a burst of active star formation.
      NGC 37 is a lenticular galaxy of apparent magnitude 14.66. It is approximately 42 kiloparsecs 137,000
      light-years in diameter and about 12.9 billion years old. Robert's Quartet composed of the irregular galaxy
      NGC 87, and three spiral galaxies NGC 88, NGC 89 and NGC 92 is a group of four galaxies located around 160 million
      light-years away which are in the process of colliding and merging. They are within a circle of radius of 1.6 arcmin,
      corresponding to about 75,000 light-years. Located in the galaxy ESO 243-49 is HLX-1, an intermediate-mass
      black hole—the first one of its kind identified. It is thought to be a remnant of a dwarf galaxy that was absorbed
      in a collision with ESO 243-49. Before its discovery, this class of black hole was only hypothesized.
    questions_and_answers:
      - question: |
          Is the Phoenix Constellation part of the Milky Way?
        answer: |
          The Phoenix constellation does not lie on the galactic plane of
          the Milky Way, and there are no prominent star clusters.
      - question: |
          How many light years away is NGC 625?
        answer: |
          NGC 625 is 24000 light years in diameter and is an outlying
          member of the Sculptor Group.
      - question: |
          What is Robert's Quartet composed of?
        answer: |
          Robert's Quartet is composed of the irregular galaxy NGC 87,
          and three spiral galaxies NGC 88, NGC 89 and NGC 92.
document:
  repo: https://github.com/<profile>/<repo-name> /
8

  commit: <commit hash> 
9

  patterns:
  - phoenix_constellation.md 
10

  - phoenix_history.md

1
指定 knowledge qna.yaml 格式的版本。目前,有效的值为 3
2
指定文档的主题或类别。例如,"技术文档"或"安装指南"。
3
指定文档内容概述。建议引用您在 document_outline 字段中 上下文 参数中包含的主题。例如,如果文档是安装指南,且每个 上下文 都包含有关不同云供应商的详情,则 document_outline 将是 "Installation Guide for AWS, GCP, 和 Azure"。
4
指定名称或 git username。
5
指定您的知识数据的段落。这是您的问题和答案要基于的内容。上下文块的格式必须与您的知识文件的格式匹配。例如,如果您的知识库文章为 Markdown,您的 上下文 块也必须采用 Markdown 格式。
6
为模型指定一个问题。问题应基于 上下文 字段中的信息。例如,"产品的最新版本是什么?"
7
指定来自模型所需的响应。必须包含回答信息,但不从 上下文 块复制,并处于完整的句子中。回答应处于完整的句子。例如,"产品的最新版本为 1.5 版本"。
8
指定包含您的知识文件的存储库的 URL。
9
指定来自您的知识文件的 git 存储库中的提交的 SHA。
10
指定 git 存储库中的文档。有效的文档类型值包括 .md.pdf。单个 qna.yaml 文件只能引用一个文档类型,不支持在同一 qna.yaml 中混合文件类型。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部