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

Cube 소개

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

예제

입력 인자 (필수) Cube Semantic Loader는 2개의 인자가 필요합니다:
  • cube_api_url: Cube 배포의 REST API URL입니다. base path 구성에 대한 자세한 내용은 Cube 문서를 참조하세요.
  • cube_api_token: Cube의 API secret을 기반으로 생성된 인증 토큰입니다. JSON Web Token(JWT) 생성 방법은 Cube 문서를 참조하세요.
입력 인자 (선택)
  • load_dimension_values: 모든 문자열 dimension에 대해 dimension 값을 로드할지 여부입니다.
  • dimension_values_limit: 로드할 dimension 값의 최대 개수입니다.
  • dimension_values_max_retries: dimension 값을 로드하기 위한 최대 재시도 횟수입니다.
  • dimension_values_retry_delay: dimension 값을 로드하기 위한 재시도 간 지연 시간입니다.
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()
다음 속성을 가진 document 목록을 반환합니다:
  • 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