4️⃣Documents & Nodes

LlamaIndex에서 DocumentNode는 핵심 데이터의 추상화를 목적으로 합니다.

Document

Document는 모든 데이터 소스를 위한 컨테이너입니다:

  • PDF

  • API 응답

  • 데이터베이스

  • 등등

Document 저장소:

  • 텍스트 데이터

  • 속성 데이터

    • metadata

    • relationships

예시:

from llama_index.core import Document
text_list = ["hello", "world"]
documents = [Document(text=t) for t in text_list]

사용자 지정 Document

사용자 지정 Document는 메타데이터 및 문서 ID 설정을 사용할 수 있습니다.

메타데이터는 문서가 작성될 때 지정하고, 문서 객체에서 수정하고, SimpleDirectoryReader를 사용하는 동안 설정할 수 있습니다.

  1. 빌드 시 지정

  2. 문서 개체에서 수정

  3. SimpleDirectoryReader를 사용하여 설정

    SimpleDirectoryReader를 사용하여 문서를 로드할 때는 file_metadata 콜백을 사용하여 설정

Document ID는 Document를 생성한 후에 설정할 수 있습니다.

Node

Node는 LlamaIndex의 가장 장점입니다. Node는 또한 Document에서와 동일한 유형의 데이터와 속성을 포함합니다.

Node는 일반적으로 두 가지 방식으로 구성됩니다:

  1. API에 직접 기반

  2. NodeParser를 사용하여 Document를 기반

Document에서 파생된 NodeDocument의 속성도 상속한다는 점에 유의하세요.

예시:

Custom Node

일반적으로 개발자는 Node를 다음과 같이 사용자 지정할 수 있습니다:

  1. Node 간의 관계를 정의합니다(relationship).

  2. Node ID 사용자 지정

Node 간의 관계 정의

RelationNodeInfo는 관계를 설정하는 데 사용됩니다. RelationNodeInfo는 구축 시 메타데이터를 설정하기 위한 파라미터 전달을 지원합니다.

사용자 지정 노드 ID


Documents & Nodes 실습

Construct Document

Customize Document

Metadata customization

  1. 문서 구성에서 사용자 지정

2. 문서 작성 후 사용자 지정

3. SimpleDirectoryReade 사용법 사용자 지정

Document ID Customization

Construct Node

개발자는 노드와 그 모든 속성을 직접 정의하거나 NodeParser 클래스를 통해 소스 문서를 노드로 구문 분석할 수 있습니다.

  1. 직접 구축

2. NodeParser에 의한 생성

위에서 로드한 document 변수를 재사용하겠습니다.

Customize Node

  1. nodes 관계 정의

2. node ID 사용자 지정

Last updated