[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,119 +1,193 @@
|
||||
---
|
||||
id: wiki-2026-0508-structured-data
|
||||
title: Structured Data
|
||||
category: Computer_Science_and_Theory
|
||||
status: needs_review
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-SDA-001]
|
||||
aliases: [Tabular-Data, Schema-Data]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [auto-reinforced, structured-data, inverted-index, indexing, data-organization, search-engine]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [data, schema, tabular, structured, formats]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-04
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: python
|
||||
framework: pandas-polars-arrow
|
||||
---
|
||||
|
||||
# [[Structured Data|Structured Data]]
|
||||
# Structured Data
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "검색을 위한 지식의 설계도: 비정형 텍스트를 기계가 빠르고 정확하게 찾아낼 수 있도록 특정 규칙(색인, 스키마 등)에 맞춰 재조직함으로써 검색 효율성을 극대화하는 데이터 가공 체계."
|
||||
## 매 한 줄
|
||||
> **"매 schema 가 있는 data — row × column 의 표"**. Structured 의 strict schema (RDB, Parquet), semi-structured 의 flexible (JSON, XML), unstructured 의 free-form (text, image). 1970 Codd's relational model 에서 시작 — 2026 에 Parquet/Arrow + JSON Schema + Pydantic 의 표준.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
구조화된 데이터(Structured Data)는 정보 검색 시스템이 데이터를 효율적으로 저장하고 조회할 수 있도록 미리 정의된 데이터 모델이나 색인 구조를 갖춘 데이터입니다.
|
||||
## 매 핵심
|
||||
|
||||
1. **전통적 구조화 기술**:
|
||||
* **[[Inverted Index|Inverted Index (역색인)]]**: 각 단어가 어떤 문서들에 포함되어 있는지 기록한 리스트입니다. 키워드 검색의 속도를 보장하는 핵심 구조입니다.
|
||||
* **[[TF-IDF|TF-IDF]] / [[BM25|BM25]]**: 단어의 통계적 특징을 수치화하여 정형화된 점수(Score)를 산출합니다.
|
||||
### 매 spectrum
|
||||
- **Fully structured**: RDB, Parquet, CSV (with schema). 매 row=record, column=field, type 의 fixed.
|
||||
- **Semi-structured**: JSON, XML, YAML, Avro. 매 schema 의 optional, flexible.
|
||||
- **Unstructured**: text, image, audio, video. 매 schema 없음.
|
||||
- 매 LLM era 의 unstructured → embedding 으로 structured 화 의 가능.
|
||||
|
||||
2. **검색 엔진 최적화(SEO)와 구조화**:
|
||||
* **Schema Markup (JSON-LD)**: 웹페이지의 의미(제품, 인물, 리뷰 등)를 검색 엔진이 즉시 이해할 수 있도록 HTML에 삽입하는 메타데이터입니다.
|
||||
* **리치 스니펫 (Rich Snippets)**: 구조화된 데이터를 기반으로 검색 결과창에 이미지나 별점 등을 추가로 노출하여 가시성을 높입니다.
|
||||
### 매 representation
|
||||
- **Row-oriented**: CSV, JSON Lines, RDB OLTP. 매 record-at-a-time access.
|
||||
- **Column-oriented**: Parquet, ORC, Arrow. 매 analytic scan / compression 의 우월.
|
||||
- **Document**: MongoDB, Elasticsearch. 매 nested, schema-on-read.
|
||||
- **Graph**: Neo4j, JanusGraph. 매 edge-first.
|
||||
|
||||
3. **지식 관리의 구조화 ([[P-Reinforce|P-Reinforce]])**:
|
||||
* 파편화된 메모를 [[Frontmatter|Frontmatter]], [[Hierarchy|계층형 폴더]], [[Internal Link|내부 링크]] 등으로 구조화하여 AI 에이전트가 쉽게 지식을 탐색하도록 만듭니다.
|
||||
### 매 schema
|
||||
- **Schema-on-write**: RDB, Parquet — 매 write 시 validation. 매 strict, fast read.
|
||||
- **Schema-on-read**: JSON, MongoDB — 매 read 시 interpret. 매 flexible, slower read.
|
||||
- **Schema evolution**: Avro, Protobuf — 매 backward/forward compat.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
* **유연성 부족**: 너무 엄격한 스키마는 비정형 데이터가 가진 풍부한 맥락을 훼손하거나, 새로운 형태의 데이터를 수용하기 어렵게 만들 수 있습니다.
|
||||
* **가공 비용**: 비정형 데이터를 구조화하는 데는 전처리 파이프라인 구축과 데이터 정제(Cleaning)를 위한 초기 비용이 발생합니다.
|
||||
* **오류 전파**: 구조화 과정에서 잘못된 레이블이 붙거나 인덱싱 오류가 발생하면 검색 결과 전체의 신뢰도가 떨어집니다.
|
||||
### 매 응용
|
||||
1. Data warehouse — Parquet on S3 + Snowflake/BigQuery.
|
||||
2. ML training — TFRecord, Parquet, HuggingFace datasets.
|
||||
3. API — JSON + JSON Schema / OpenAPI.
|
||||
4. Streaming — Avro / Protobuf in Kafka.
|
||||
5. LLM tool calling — Pydantic schema → JSON.
|
||||
|
||||
## 💻 실전 구현 코드 (Boilerplate)
|
||||
검색 엔진이 이해하기 쉬운 `JSON-LD` 형식의 구조화된 데이터 예시입니다.
|
||||
## 💻 패턴
|
||||
|
||||
```html
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"headline": "Astra P-Reinforce v3.0 표준 가이드",
|
||||
"author": {
|
||||
"@type": "Person",
|
||||
"name": "Antigravity Agent"
|
||||
},
|
||||
"description": "지식의 자동화 및 구조화를 위한 P-Reinforce 표준 프로토콜 상세 설명.",
|
||||
"keywords": "AI, Knowledge Management, P-Reinforce, Wiki"
|
||||
### 1. Parquet — write/read with schema
|
||||
```python
|
||||
import pandas as pd
|
||||
df.to_parquet("data.parquet", engine="pyarrow", compression="zstd")
|
||||
df2 = pd.read_parquet("data.parquet", columns=["id", "value"]) # 매 column projection
|
||||
```
|
||||
|
||||
### 2. Polars (lazy, 2026 fast)
|
||||
```python
|
||||
import polars as pl
|
||||
lf = pl.scan_parquet("data/*.parquet")
|
||||
result = (
|
||||
lf.filter(pl.col("value") > 100)
|
||||
.group_by("category")
|
||||
.agg(pl.col("value").mean())
|
||||
.collect()
|
||||
)
|
||||
```
|
||||
|
||||
### 3. Arrow (zero-copy interchange)
|
||||
```python
|
||||
import pyarrow as pa
|
||||
import pyarrow.parquet as pq
|
||||
table = pa.Table.from_pandas(df)
|
||||
pq.write_table(table, "data.parquet")
|
||||
# 매 pandas, polars, duckdb 사이 zero-copy
|
||||
```
|
||||
|
||||
### 4. Pydantic (Python schema validation, 2026)
|
||||
```python
|
||||
from pydantic import BaseModel, Field
|
||||
class User(BaseModel):
|
||||
id: int
|
||||
name: str = Field(min_length=1)
|
||||
email: str
|
||||
age: int | None = None
|
||||
|
||||
user = User.model_validate({"id": 1, "name": "Alice", "email": "a@b.com"})
|
||||
schema = User.model_json_schema() # 매 LLM tool calling 의 사용 가능
|
||||
```
|
||||
|
||||
### 5. JSON Schema validation
|
||||
```python
|
||||
import jsonschema
|
||||
schema = {"type": "object", "properties": {"id": {"type": "integer"}}, "required": ["id"]}
|
||||
jsonschema.validate(instance={"id": 42}, schema=schema)
|
||||
```
|
||||
|
||||
### 6. SQL (DuckDB on local Parquet, 2026)
|
||||
```python
|
||||
import duckdb
|
||||
con = duckdb.connect()
|
||||
result = con.sql("""
|
||||
SELECT category, AVG(value) FROM 'data/*.parquet'
|
||||
WHERE date >= '2026-01-01' GROUP BY category
|
||||
""").df()
|
||||
```
|
||||
|
||||
### 7. Schema evolution (Avro)
|
||||
```python
|
||||
# 매 v1 → v2: optional field 의 add (with default) → backward compat
|
||||
schema_v2 = {
|
||||
"type": "record",
|
||||
"fields": [
|
||||
{"name": "id", "type": "int"},
|
||||
{"name": "name", "type": "string"},
|
||||
{"name": "tier", "type": "string", "default": "free"} # NEW
|
||||
]
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
* **상위 개념**: [[Computer Science and Theory|Computer Science]], [[Data Engineering|Data Engineering]]
|
||||
* **핵심 기술**: [[Inverted Index|Inverted Index]], [[SEO|SEO (Search Engine Optimization)]]
|
||||
* **관련 모델**: [[Knowledge Graph|Knowledge Graph]], [[Vector Database|Vector Database (Unstructured-to-Structured)]]
|
||||
### 8. LLM structured output (Pydantic + Anthropic)
|
||||
```python
|
||||
from anthropic import Anthropic
|
||||
from pydantic import BaseModel
|
||||
|
||||
---
|
||||
*Last updated: 2026-05-04*
|
||||
class Extract(BaseModel):
|
||||
name: str
|
||||
age: int
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
# 매 tool calling with schema
|
||||
schema = Extract.model_json_schema()
|
||||
client = Anthropic()
|
||||
resp = client.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=1024,
|
||||
tools=[{"name": "extract", "input_schema": schema}],
|
||||
messages=[{"role": "user", "content": "Alice is 30 years old."}],
|
||||
)
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### 9. Iceberg / Delta (2026 lakehouse)
|
||||
```python
|
||||
# Iceberg — Parquet + manifest + snapshot 의 ACID
|
||||
from pyiceberg.catalog import load_catalog
|
||||
cat = load_catalog("local")
|
||||
table = cat.load_table("ns.users")
|
||||
df = table.scan().to_pandas()
|
||||
```
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Analytic / scan-heavy | Parquet (column) |
|
||||
| Transactional / row-by-row | RDB / RocksDB |
|
||||
| Streaming, schema evolve | Avro / Protobuf |
|
||||
| Human-edit, config | YAML / TOML |
|
||||
| API contract | JSON + Pydantic / JSON Schema / OpenAPI |
|
||||
| Data lake | Parquet + Iceberg / Delta |
|
||||
| ML training | Parquet / HuggingFace datasets / TFRecord |
|
||||
| LLM tool input | JSON Schema (from Pydantic) |
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
**기본값**: Parquet for storage + Pydantic for validation + DuckDB/Polars for query.
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
## 🔗 Graph
|
||||
- 부모: [[Information Theory]] · [[Knowledge Graph]]
|
||||
- 변형: [[Knowledge-Structure]] · [[Knowledge-Graph-Foundations]]
|
||||
- 응용: [[Information Retrieval (IR)]] · [[Statistics]]
|
||||
- Adjacent: [[Hash-Functions-and-Maps]] · [[B-Tree]]
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
## 🤖 LLM 활용
|
||||
**언제**: schema design, JSON-Schema generation, tool calling input/output, data validation guidance, format conversion explanation.
|
||||
**언제 X**: 매 large-volume parse — pandas/polars/duckdb 의 사용.
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
## ❌ 안티패턴
|
||||
- **CSV for production data**: type loss, encoding bugs, no compression — 매 Parquet 의 default.
|
||||
- **JSON for analytic at scale**: 매 row-by-row parse 의 slow, 100x larger 의 Parquet vs.
|
||||
- **No schema validation at boundary**: 매 silent corruption — Pydantic / JSON Schema 의 enforce.
|
||||
- **Schema-on-read for hot path**: 매 latency penalty — 매 schema-on-write + indices.
|
||||
- **Wide tables (1000+ cols)**: 매 most ops 의 unused — 매 column projection / split table.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Apache Parquet/Arrow specs, Pydantic v2 docs, Iceberg spec).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — formats spectrum, Parquet/Pydantic/DuckDB patterns. |
|
||||
|
||||
Reference in New Issue
Block a user