구조화된 데이터(테이블) 질의하기
구조화된 데이터(테이블) 질의하기
이 페이지는 Cohere를 사용해 테이블 속 구조화된 데이터를 질의하는 방법을 설명해요. 테이블 데이터를 자연어 설명으로 바꾸고 관련 행을 검색해 모델에 전달하는 과정을 살펴볼게요.
출처: 문서
본문
이 튜토리얼에서는 테이블 속 구조화된 데이터를 질의하는 방법을 배우게 돼요.
단계는 다음과 같아요:
1단계: 테이블 데이터를 자연어 설명으로 변환해요.
2단계: 테이블에서 관련 행을 검색해요.
3단계: 모델에 행과 쿼리를 모두 입력해 쿼리를 수행해요.
완전한 코드 예시 (Complete code example)
전체 코드 예시는 다음과 같아요:
PYTHON
import cohere
co = cohere.ClientV2(api_key="YOUR_COHERE_API_KEY")
# Step 1: Convert the table data into a natural language description
table_desc = "This table contains columns: name, age, location, salary"
# Step 2: Retrieve relevant rows from the table
relevant_rows = [
{"name": "Alice", "age": 30, "location": "London", "salary": 50000},
{"name": "Bob", "age": 25, "location": "Paris", "salary": 40000},
{"name": "Carol", "age": 28, "location": "Berlin", "salary": 45000},
]
# Step 3: Perform the query by feeding the model both the rows and the query
response = co.chat(
model="command-a-03-2025",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f"Table description: {table_desc}\n\nRows: {relevant_rows}\n\nQuery: Which employees have salary higher than {40000}?"},
],
)
print(response.message.content[0].text)
다음 단계 (Next Steps)
다음 생성/에이전트 패턴들을 살펴보아요: