VeloxAI
Quay lại Blog
Knowledge Base· 13 phút đọc

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.

Nguyen Son Everestt
Nguyen Son EveresttFounder & Engineering Lead, VeloxAI
#rag#knowledge-base#qdrant
Kiến trúc RAG
Kiến trúc RAG

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' });
}
Queue-backed indexing với metadata-vector split

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.