feat: 기존 ContextFlow에 연결 즉시 의미 준비형 질의 추가#253
Open
o2mandoo wants to merge 11 commits into
Open
Conversation
Constraint: Preserve Lang2SQL's ports-and-adapters shape and Discord-first UX. Rejected: Port the full semantic-data-context runtime | It would recreate abstraction and onboarding friction. Confidence: high Scope-risk: broad Directive: Keep raw SQL unavailable whenever a semantic catalog exists. Tested: 186 pytest; ruff src tests; mypy src/lang2sql; Gemma 26B first-connect and five-domain local smoke. Not-tested: Live Discord gateway, production remote databases, and role-based semantic approval.
Build a metadata-only semantic catalog, bounded typed selection, steward review, source-bound execution, disclosure guards, and Discord recovery so unseen SQLite schemas can be queried without widening model authority. Constraint: No dataset-specific mappings, raw value profiling, or raw SQL fallback in governed mode Rejected: Let the model infer schema-wide SQL directly | It cannot provide deterministic policy, review, or disclosure guarantees Confidence: high Scope-risk: broad Directive: Keep dataset gold plans and source-specific mappings out of src/lang2sql Tested: 313 pytest; Ruff; mypy on 88 source files; controlled and public 28-case oracle runs; Gemma4 26B selection run Not-tested: Non-SQLite dialect parity and live production Discord gateway
Expose a typed host runtime and close the privacy, lifecycle, audit, and Discord policy gaps required for safe SQLite/DuckDB first use. Constraint: Keep raw SQL out of public and model contracts; limit governed execution to verified file-backed SQLite and DuckDB. Rejected: Persisting review questions and literals | restart now requires fresh candidate discovery instead. Confidence: high Scope-risk: broad Directive: Preserve candidate binding, atomic audit, and fail-closed dialect and predicate boundaries when extending this runtime. Tested: 354 pytest cases; Ruff; mypy on 96 source files; Black on 28 changed Python files; workflow YAML; diff check; two independent red-team verdicts; Gemma4 26B 17-case smoke. Not-tested: Live Discord gateway; GitHub Actions Python 3.10 and 3.12 runners; governed execution on remote database dialects.
Add a newcomer glossary, separate legacy and governed lifecycles, document recovery actions, and provide a self-contained SQL-free SQLite quickstart checked by CI. Constraint: Keep the public contract honest about human review, fail-closed behavior, and SQLite/DuckDB-only governed execution. Rejected: Explaining the feature only in the pull request body | repository documentation must remain useful after merge. Confidence: high Scope-risk: narrow Directive: Keep the executable quickstart in Ruff, mypy, and full-suite verification when the public runtime changes. Tested: 355 pytest cases; PR1 186 tests; PR2 313 tests; Ruff; mypy on 97 files; Black; workflow YAML; hostile-env quickstart; exact uv sync/uvx/uv run documentation path. Not-tested: Live Discord gateway; GitHub-hosted Python 3.10/3.12 runners.
Names the public flow by its actual lazy-review behavior and applies the repository-pinned formatter so the consolidated branch passes its existing all-files hook. Constraint: Keep internal governed_* contracts stable while making the user-facing feature and handoff intuitive. Rejected: Rename internal APIs and symbols | compatibility risk without user-facing benefit. Confidence: high Scope-risk: narrow Directive: Keep public copy aligned with candidate-before-review behavior and verified dialect limits. Tested: 355 pytest cases; Ruff; mypy 97 files; Black 129 files; offline quickstart; Markdown links; formatting AST equality. Not-tested: Live Discord transport and unverified remote dialect execution.
Formats the remaining benchmark modules selected by the repository-wide Black hook without changing their Python AST. Constraint: The existing pre-commit workflow scans every tracked Python file, including benchmark modules outside the semantic-runtime lint command. Rejected: Exclude benchmark files from the hook | would weaken the repository gate. Confidence: high Scope-risk: narrow Directive: Run pre-commit against all files before future handoff changes. Tested: pre-commit Black 134 files; 355 pytest cases; Ruff; mypy 97 files; benchmark AST equality. Not-tested: Live Discord transport and unverified remote dialect execution.
Reuse DB comments and source-bound Enrich descriptions only as candidate hints, with an optional metadata-only model pass and explicit degraded status. Constraint: Preserve existing Enrich, Federation, Memory, Discord, and Safety flows without raw-row sampling in reviewed connections Rejected: Reuse legacy sample-to-LLM Enrich during reviewed connect | it would widen data disclosure and join authority Confidence: high Scope-risk: moderate Directive: Keep automatic suggestions candidate-only, fresh, and source/fingerprint-bound Tested: 357 pytest by independent verifier; 6 targeted pytest; Ruff; mypy; ruff format; git diff check Not-tested: Live Discord gateway and governed execution on remote dialects beyond existing SQLite/DuckDB evidence
Format the two files identified by the repository-pinned Black 26.1.0 hook so CI evaluates behavior instead of a formatter diff. Constraint: Preserve the already-reviewed ContextFlow integration without behavioral edits Rejected: Weaken or exclude the repository-wide Black hook | it is an existing project gate Confidence: high Scope-risk: narrow Directive: Run the pinned Black hook, not only Ruff format, before future pushes Tested: Black 26.1.0 check across 136 files; 3 targeted semantic enrichment tests Not-tested: Full suite was unchanged since the prior 357-test verifier run
Explain up front that database-specific facts live in a generated catalog while supported-database compiler rules remain generic, then trace one grounded question through bounded IDs to server-side SQL compilation. Constraint: Preserve the merged ContextFlow philosophy and avoid domain-specific SQL templates Rejected: Describe the feature only as rule-based SQL generation | newcomers cannot see what the model actually selects Confidence: high Scope-risk: narrow Directive: Keep examples grounded in actual CandidateSet and QueryDraft fields Tested: Markdown diff check; same-intelligence implementation-grounded documentation review Not-tested: Runtime suite not rerun because this commit changes documentation only
Document the connection, catalog, enrichment, state, shortlist, review, and execution lifecycle in a first-reader-friendly form. Constraint: Preserve ContextFlow and describe the implemented runtime contract only Rejected: Describe the shortlist as vector or relevance-only search | The runtime uses bounded lexical matching and may expose all candidates in a small catalog Confidence: high Scope-risk: narrow Directive: Keep this lifecycle aligned with reconnect and review-resume behavior Tested: git diff --check; independent code-to-README contract review Not-tested: Full runtime suite because this is a README-only change
DB 연결부터 catalog 생성, 작은 모델의 제한된 선택, 서버 재검증과 SQL 컴파일까지를 두 개의 정밀 SVG와 개조식 문서로 설명한다. 기존 ContextFlow와 이번 PR의 역할 차이도 명시한다. Constraint: 기존 ContextFlow 철학과 실제 런타임 계약을 보존 Rejected: 생성형 래스터 인포그래픽 | 한글 라벨과 실행 계약을 정확히 유지하기 어려움 Confidence: high Scope-risk: narrow Directive: catalog와 shortlist 상태 필드를 문서에서 하나의 version으로 합치지 말 것 Tested: staged diff check; SVG XML validation and 1600px visual QA; Markdown local-link/details validation; two independent contract and readability reviews; existing branch suite 357 passed Not-tested: live Discord interaction was not rerun because this commit changes documentation and SVG only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요약
이미 병합된 ContextFlow의 의미 발견·축적 철학을 그대로 유지합니다. Discord →
tenancy → agent loop와 Enrich·Federation·Memory·Ingestion 위에서, catalog가
활성화된 연결의 실행 경계에만 연결 즉시 의미 준비형 질의를 덧댑니다. 자동
보강은 검색 후보만 늘리며 승인이나 실행 권한을 만들지 않습니다.
run_sql·schema 탐색/Enrich 유지작은 모델이 가능한 이유
“규칙”은
매출 → orders.amount같은 도메인별if문이나 SQL template이아닙니다. 첫 연결에서 DB별 사실(허용 ID·타입·PK/FK·확인된 의미)을 catalog로
만들고, 지원 범위 안에서 DB와 무관한 집계·타입·join·parameter·공개 규칙으로
컴파일합니다.
질문마다 관련 table은 최대 6개, metric·dimension 후보는 각각 최대 12개로
줄입니다. 아래는 필요한 공개·표현 검토가 끝난 연결의 간단한 예입니다.
flowchart LR A["질문: ordered_on이 2025-01-01 이상<br/>2025-02-01 미만이고 status=paid인 amount 합계"] --> B["서버: 관련 metric·filter·기간 후보만 제공"] B --> C["작은 모델: SQL 대신 허용 ID·값 조립"] C --> D["서버: catalog·공통 규칙으로 SQL 컴파일"] D --> E{"의미·공개 범위 확정?"} E -- "예" --> F["기존 Safety → 읽기 전용 실행"] E -- "아니오/미지원" --> G["사람 검토·추가 질문·명시적 차단"]모델은 table·join·dialect를 추측하지 않고 소수 후보에서 정해진 칸만 채웁니다.
자연어의 숨은 조건을 놓치는 문제까지 자동 해결한다고 주장하지 않으며, 미확정
의미는 실행하지 않습니다.
핵심 변경
/setup직후 물리명·DB comment를 후보로 사용하고, 같은 source·물리fingerprint의 재연결이면 기존
/enrich설명 캐시도 재사용합니다.auto모드에서 실제 LLM provider가 있으면 raw row 없이 metadata-only 보강도 한 번
수행합니다.
run_sql로 우회하지 않고 명시적으로 차단합니다.상세 계약:
docs/REVIEWED_SEMANTIC_QUERY.md검증
권장 리뷰 순서: 문서 →
tools/__init__.py→semantic/→ 공개 API·Discord