Xây hệ thống RAG production không nói dối users
Pipeline RAG production-grade cần ingestion state, chunk metadata, vector isolation, citations, queue-based indexing và honest failure modes.
Hầu hết RAG tutorials chỉ cách upload PDF trong 10 dòng code. Demo đó chạy tốt cho đến document thứ hai. Rồi có người upload hợp đồng 400 trang và câu trả lời trích trang 287 không cách nào verify. Rồi người khác upload file HR mật, RAG expose vì vectors không có access control. Production RAG là data pipeline với hậu quả thật.
PostgreSQL cho metadata, Qdrant cho vectors
PostgreSQL lưu organizations, documents, chunks, sources và permissions. Qdrant lưu raw vectors keyed bằng chunk IDs. Cách tách này giúp bạn audit ai upload cái gì, chunks nào được retrieve và source nào tạo câu trả lời — không cần chạm vào vector store cho security queries.
async function indexDocument(doc: Document, orgId: string) {
// 1. Create doc record with 'processing' status
const docId = await db.documents.create({ organizationId: orgId, ... });
// 2. Enqueue indexing job — never block the upload request
await queue.enqueue('index:document', { docId, orgId });
return { docId, status: 'processing' };
}
// Worker processes asynchronously:
async function processIndex(job: IndexJob) {
const text = await extractText(job.doc);
const chunks = chunkText(text, { maxTokens: 800, overlap: 100 });
for (const [i, chunk] of chunks.entries()) {
const chunkId = await db.chunks.create({ documentId: job.docId, ... });
const embedding = await getEmbedding(chunk);
await qdrant.upsert(collection, { id: chunkId, vector: embedding });
}
await db.documents.update(job.docId, { status: 'indexed' });
}Citations không phải optional
Mỗi câu trả lời phải cite documents và chunks nào tạo ra nó. Đây là khác biệt giữa công cụ users tin và công cụ họ bỏ sau một câu sai. Citations cho phép users verify, operators debug retrieval quality và compliance teams trace data lineage. System nên validate cited sources thực sự tồn tại trong retrieval results trước khi hiển thị.
Cập nhật:
Sẵn sàng dựng sản phẩm AI của bạn?
Bắt đầu free, route nhiều provider, đo chi phí và readiness trung thực ngay từ ngày đầu.
Bài viết liên quan
- Product
VeloxAI: control plane multi-model cho đội sản phẩm
Vì sao đội sản phẩm cần một API cho models, agents, RAG, billing, analytics và readiness thay vì thêm một proxy mỏng.
- Models
Cách chọn AI model phù hợp cho từng workflow sản phẩm
Framework chọn model được kiểm chứng thực tế, bao gồm cost, latency, context window, tool calling, vision, reasoning — kèm số liệu thật và ma trận quyết định.
- Agent Security
Agent tools rất mạnh. Chính vì thế chúng cần sandbox.
Agent hữu ích có thể gọi tools. Agent an toàn validate tool schemas, cô lập execution, giới hạn runtime, chặn network egress và log mọi call.