NL2SQL Analyst Copilot NL2SQL Analyst Copilot
자연어 질문을 SQL과 차트 결과로 연결하고, self-correction과 semantic cache를 함께 검증한 데이터 분석 prototype입니다. A data analysis prototype that connects natural-language questions to SQL and chart outputs while validating self-correction and semantic caching together.
이 프로젝트의 핵심은 비개발자가 SQL을 몰라도 BigQuery 데이터를 자연어로 조회하게 만드는 것입니다. 동시에 그 과정에서 발생하는 오류 처리와 응답 비용 문제를 엔지니어링으로 흡수해 실제 사용 가능한 분석 흐름으로 만드는 데 초점을 뒀습니다. The core of this project is enabling non-developers to query BigQuery in natural language without knowing SQL. It also focuses on absorbing error handling and response-cost problems through engineering so the analysis flow remains usable in practice.
Solution Solution
Gemini 기반 NL2SQL 엔진이 질문을 SQL로 변환하고, validator가 구문 오류를 감지하면 실패 사유를 다시 모델에 넣어 self-correction을 수행하도록 설계했습니다. 실행 가능한 SQL이 생성되면 BigQuery 조회 결과를 표와 차트 형태로 가공해 비개발자도 바로 읽을 수 있는 결과로 반환합니다. A Gemini-based NL2SQL engine translates questions into SQL, and when the validator detects syntax errors, the failure reason is fed back into the model for self-correction. Once valid SQL is produced, BigQuery results are transformed into tables and charts that non-developers can immediately interpret.
반복 질의에 대한 latency와 비용 문제는 인메모리 semantic cache 계층으로 풀었습니다. 동일하거나 의미적으로 가까운 질문은 재실행하지 않고 이전 결과와 시각화까지 재사용해 응답 체감을 줄이도록 구성했습니다. Latency and cost from repeated questions are handled through an in-memory semantic cache layer. Identical or semantically similar questions reuse prior results and visualizations instead of re-running the full flow.
Architecture Architecture
프론트엔드와 백엔드는 분리된 서버리스 구성으로 두고, 백엔드 앞단에서 cache hit 여부를 먼저 판단합니다. 캐시 미스일 때만 NL2SQL 엔진과 validator loop를 거쳐 BigQuery를 호출하고, 결과는 chart builder를 통해 가시화한 뒤 다시 cache에 저장합니다. The frontend and backend are separated in a serverless setup, and cache hit detection happens before model execution. Only cache misses pass through the NL2SQL engine and validator loop into BigQuery, after which the result is visualized and written back into cache.
이 구조 덕분에 UI는 단순한 질문 입력 경험을 유지하면서도 내부적으로는 query generation, validation, execution, visualization, semantic reuse가 각각 독립된 단계로 작동합니다. This keeps the UI experience simple while the backend internally separates query generation, validation, execution, visualization, and semantic reuse into distinct stages.
Technical Decisions Technical Decisions
Google OAuth 2.0 Google OAuth 2.0
커스텀 RBAC를 새로 만드는 대신 기존 인증 체계와 연결해 빠르게 enterprise access control을 확보했습니다. 구현 속도와 보안 안정성을 동시에 잡기 위한 선택이었습니다. Instead of building custom RBAC from scratch, we integrated with Legacy authentication to secure enterprise-grade access control quickly. The choice balanced implementation speed and security.
K-Means + Cosine Cache K-Means + Cosine Cache
단순 코사인 유사도만으로는 캐시가 커질수록 느리고 부정확해집니다. 질의를 먼저 군집화한 뒤 해당 군집 내부에서만 similarity를 계산하는 2-step 전략으로 효율과 정확도를 함께 잡았습니다. Cosine similarity alone becomes slow and noisy as cache grows. We used a two-step strategy that clusters queries first and computes similarity only inside the matched cluster.