RAG AI Phase 1 Implementation Plan (Build — Wrangler & Dev)
Purpose: Define stepwise scope, dependencies, and deliverables to implement Phase 1 (Build) from rag-ai-edge-architecture-plan.md. No code generation — implementation order and specification only.
References: RAG AI plan §2 (core components), §3 (Zuplo metering·billing), §4 (Vectorize·D1 provisioning), §6.1 (Phase 1 goals).
1. Implementation order and dependencies
[1] Vectorize·D1 provisioning (Pulumi or dashboard)
[1] required for Vectorize index and D1; [3][4] depend on it. [2] D1 tables used by [3][4][5] for tenant settings, quota, usage. [4] must return token count (header/body) for [5] Post-proc. [5] deployed via Zuplo; Zuplo calls [4] backend.
2. Step deliverables (summary)
2.1 Provisioning: Pulumi or runbook → D1 (prego_hr_master_db), Vectorize (prego-hr-knowledge-base, preset cf-baai-bge-small-en-v1.5), API Token. Outputs: D1_DATABASE_ID, VECTORIZE_INDEX_NAME, Token (secret).
2.2 D1 schema: Migration 0008_rag_ai.sql — tenant_ai_settings, tenant_ai_usage_daily, meters.ai_tokens. Join with tenants_master, plan_entitlements for Quota·Stripe.
2.3 Data Ingestion: Trigger (R2 event or POST /admin/ingest). Pipeline: R2 read → text extract → chunk → Workers AI Embedding → Vectorize upsert (namespace=tenant_id). Wrangler: R2, Vectorize, D1 bindings.
2.4 RAG Query: POST /ai/query (routed by Zuplo). Pipeline: Privacy Masking → embed → Vectorize search (namespace=tenant_id) → Workers AI → response. Return x-ai-usage-tokens (or body) for metering. Skeleton: workers/rag-query/ (wrangler.toml, GET /health, POST /ai/query).
[4] 에서 응답에 토큰 수(헤더/바디)를 포함해야 [5] Post-proc에서 기록 가능.
[5] 는 Zuplo 대시보드 또는 Config as Code로 배치; [4] 백엔드 URL을 Zuplo가 호출.
2. 단계별 산출물
2.1 Vectorize·D1 프로비저닝 (순서 1)
산출물
내용
Pulumi 스크립트 또는 Runbook
고객 Cloudflare Account ID 입력 시 D1 DB(prego_hr_master_db), Vectorize 인덱스(prego-hr-knowledge-base, preset cf-baai-bge-small-en-v1.5), API Token(Workers R2/D1/Scripts 권한) 생성. 기획서 §4 참조.
산출값
D1_DATABASE_ID, VECTORIZE_INDEX_NAME, API Token(Secret). Control Plane 또는 Zuplo env에 저장.
기존 tenants_master, plan_entitlements와 조인하여 플랜별 Quota·Stripe subscription_item_id 매핑.
2.3 Data Ingestion Worker (순서 3)
산출물
내용
트리거
R2에 문서 업로드 시(Event Notifications 또는 수동 API 호출). 또는 관리자 API POST /admin/ingest 로 버킷 경로 지정.
파이프라인
① R2에서 객체 읽기(PDF/Office 등) ② Workers에서 텍스트 추출(라이브러리 또는 Workers AI 문서 이해 API) ③ 청크 분할 ④ Workers AI Embedding으로 벡터화 ⑤ Vectorize에 upsert(namespace=tenant_id).