Skip to main content
이 노트북은 Cube의 데이터 모델 메타데이터를 LLM에 임베딩으로 전달하기에 적합한 형식으로 검색하여 컨텍스트 정보를 향상시키는 프로세스를 보여줍니다.

Cube 소개

Cube는 데이터 앱을 구축하기 위한 시맨틱 레이어입니다. 데이터 엔지니어와 애플리케이션 개발자가 최신 데이터 저장소에서 데이터에 액세스하고, 일관된 정의로 구성하며, 모든 애플리케이션에 제공할 수 있도록 지원합니다. Cube의 데이터 모델은 LLM이 데이터를 이해하고 올바른 쿼리를 생성하기 위한 컨텍스트로 사용되는 구조와 정의를 제공합니다. Cube는 복잡한 조인 및 메트릭 계산을 추상화하고 SQL 테이블 및 열 이름 대신 비즈니스 수준 용어로 작동하는 간단한 인터페이스를 제공하므로 LLM이 복잡한 조인과 메트릭 계산을 탐색할 필요가 없습니다. 이러한 단순화는 LLM이 오류를 줄이고 환각을 방지하는 데 도움이 됩니다.

예제

입력 인수 (필수) Cube Semantic Loader에는 2개의 인수가 필요합니다:
  • cube_api_url: Cube 배포의 REST API URL입니다. 기본 경로 구성에 대한 자세한 내용은 Cube 문서를 참조하세요.
  • cube_api_token: Cube의 API 시크릿을 기반으로 생성된 인증 토큰입니다. JSON 웹 토큰(JWT) 생성 방법에 대한 지침은 Cube 문서를 참조하세요.
입력 인수 (선택사항)
  • load_dimension_values: 모든 문자열 차원에 대해 차원 값을 로드할지 여부입니다.
  • dimension_values_limit: 로드할 최대 차원 값 수입니다.
  • dimension_values_max_retries: 차원 값을 로드하기 위한 최대 재시도 횟수입니다.
  • dimension_values_retry_delay: 차원 값 로드 재시도 간 지연 시간입니다.
import jwt
from langchain_community.document_loaders import CubeSemanticLoader

api_url = "https://api-example.gcp-us-central1.cubecloudapp.dev/cubejs-api/v1/meta"
cubejs_api_secret = "api-secret-here"
security_context = {}
# Read more about security context here: https://cube.dev/docs/security
api_token = jwt.encode(security_context, cubejs_api_secret, algorithm="HS256")

loader = CubeSemanticLoader(api_url, api_token)

documents = loader.load()
Returns a list of documents with the following attributes:
  • page_content
  • metadata
    • table_name
    • column_name
    • column_data_type
    • column_title
    • column_description
    • column_values
    • cube_data_obj_type
# Given string containing page content
page_content = "Users View City, None"

# Given dictionary containing metadata
metadata = {
    "table_name": "users_view",
    "column_name": "users_view.city",
    "column_data_type": "string",
    "column_title": "Users View City",
    "column_description": "None",
    "column_member_type": "dimension",
    "column_values": [
        "Austin",
        "Chicago",
        "Los Angeles",
        "Mountain View",
        "New York",
        "Palo Alto",
        "San Francisco",
        "Seattle",
    ],
    "cube_data_obj_type": "view",
}

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I