Skip to content

Phân chia DB lưu trữ dữ liệu (dữ liệu lấy về)

Tổng quan

Sau khi thu thập dữ liệu từ các nguồn khác nhau, hệ thống cần lưu trữ dữ liệu một cách hiệu quả và có cấu trúc để phục vụ các nhu cầu khác nhau của hệ thống AI.

Các loại Database theo quy trình 3 bước

Bước 1: Raw Data Storage

  • Database: S-ERP-23-03-APPCODE-CR
  • Loại: PostgreSQL
  • Mục đích: Lưu trữ dữ liệu thô từ crawler
  • Dữ liệu: Raw documents từ I.Office và VB QPPL
  • Cơ quan: UBND, HĐND, Sở ban ngành, xã phường

Bước 2: Standardized Data & Search Index

  • Database: S-ERP-23-03-APPCODE
  • Loại: PostgreSQL
  • Mục đích: Dữ liệu đã chuẩn hóa và metadata
  • Index: s-erp-23-03-appcode (Elasticsearch)
  • Mục đích: Tìm kiếm toàn văn bản và filtering

Bước 3: AI Vector Database

  • Database: S-ERP-23-03-APPCODE-AI
  • Loại: PostgreSQL với pgvector
  • Mục đích: Vector embeddings cho tìm kiếm ngữ nghĩa
  • Dữ liệu: Vector representations của chunks văn bản
  • Truy vấn: Similarity search, semantic matching

Các Database bổ sung

File Storage (MinIO/S3)

  • Mục đích: Lưu trữ file gốc (PDF, DOC, etc.)
  • Dữ liệu: Binary files, documents
  • Truy vấn: Object storage access
  • Ưu điểm: Scalable, S3-compatible

Cache (Redis)

  • Mục đích: Tăng tốc truy cập dữ liệu thường dùng
  • Dữ liệu: Session data, frequent queries, embeddings
  • Truy vấn: Key-value access
  • Ưu điểm: High performance, in-memory

Message Queue (RabbitMQ)

  • Mục đích: Asynchronous processing, decoupling services
  • Dữ liệu: Task queues, events
  • Truy vấn: Queue operations
  • Ưu điểm: Reliability, scalability

Chiến lược phân chia dữ liệu

Theo loại dữ liệu

  • Structured: PostgreSQL
  • Semi-structured: Elasticsearch
  • Unstructured text: Vector DB
  • Binary files: MinIO
  • Ephemeral: Redis

Theo mục đích sử dụng

  • Search: Elasticsearch + Vector DB
  • Analytics: PostgreSQL + Elasticsearch
  • Serving: Cache + CDN
  • Processing: Message Queue

Data Flow Architecture theo 3 bước

Scaling Considerations

Horizontal Scaling

  • Vector DB: Auto-scaling clusters
  • Elasticsearch: Multi-node clusters
  • MinIO: Distributed storage
  • PostgreSQL: Read replicas

Data Consistency

  • Eventual consistency cho search
  • Strong consistency cho transactions
  • Version control cho documents

Backup & Recovery

Backup Strategy

  • PostgreSQL: Daily snapshots
  • Elasticsearch: Index snapshots
  • MinIO: Cross-region replication
  • Vector DB: Cloud backups

Disaster Recovery

  • Multi-region deployment
  • Automated failover
  • Data restoration procedures

Phân chia DB hợp lý giúp tối ưu hóa hiệu suất, chi phí và khả năng maintain của hệ thống.