Skip to main content

Data Ingestion

Data ingestion prepares raw government documents for retrieval and grounded answering. It validates inputs, stores raw bytes, parses or OCRs content, extracts metadata, chunks text, embeds approved chunks, builds lexical text, persists rows, and exposes processing status.

Supported sources

The data model recognizes five source types: JDIH, OpenData, PPID, SatuData, and upload. Uploads use the ingestion service directly, and source connectors for JDIH, OpenData, PPID, and SatuData feed the same service so documents follow one validation, parsing, OCR, chunking, and indexing path.

SourceContent profileIngestion status
JDIHLaws, regulations, legal opinions, statute referencesSource connector
OpenDataStructured/tabular public datasetsSource connector and uploaded/batch CSV/XLSX parsing
PPIDPublic-information documentsSource connector
SatuDataStandardized government datasetsSource connector
UploadManual or batch files from users/integrationsUpload and batch APIs

Supported formats

Docling Slim is the born-digital parser boundary for PDF, DOCX, PPTX, XLSX, CSV, MD, and HTML. TXT is handled locally. Images and scanned documents route through OCR.

Ingestion methods

MethodEndpoint or seamCurrent behavior
Manual multipart uploadPOST /documentsStores files, creates a job, queues each file, returns job and document IDs
Inline textPOST /documents/txtCreates one document directly from request JSON and indexes it
Batch object-storage prefixPOST /ingestion/batch with prefixLists keys under a prefix and enqueues one job for matched objects
Batch manifestPOST /ingestion/batch with explicit keysEnqueues selected object keys
API integrationAny endpoint via APIG/FastAPIExternal clients call the same API, not a side path
Scheduled ingestionScheduler calling API/batch connectorCalls the same batch/source APIs as other integrations
Streaming ingestionKafka/DMS worker processingAsync queue processing supports source-specific adapters

End-to-end pipeline

Validation

Validation happens before storage, before parsing, and before indexing.

StageValidation
Upload requestAPI key, supported extension/type, file size, batch size
Object storageBackend errors mapped to domain errors; partial upload cleanup prevents orphans
Worker messageRequired fields: document ID, content SHA-256, filename, source type, source version
Raw bytesArchive-bomb limits run before parse/OCR
Parsed textEmpty documents rejected
Chunk textLow-signal/gibberish content routed to review before embedding
OCR chunksConfidence threshold and confidence-comparability gate
RepositoryDuplicate ordinals rejected; indexed chunks require embeddings; needs_ocr_review chunks are excluded from retrieval

Metadata extraction and persistence

The ingestion model stores document-level and chunk-level metadata.

Document rows contain title, source type, format, source version, ingest timestamp, status, and metadata JSON. Chunk rows contain document ID, ordinal, text, embedding, lexical text, generated lexical_tsv, OCR confidence, chunk status, page number, section path, legal reference, character spans, and metadata JSON.

The current ingestion service records parser metadata, OCR confidence threshold, content hash, source key, OCR model, confidence comparability, and page/source span fields.

Chunking and indexing

The architecture targets roughly 512-token windows with overlap. The service uses a configurable chunk size and preserves character spans. Approved chunks get embeddings and lexical text. PostgreSQL stores HNSW vector index data and generated full-text search vectors.

Storage design

StorageData
OBS / S3-compatible object storageRaw uploads, batch corpus objects, future processed artifacts
PostgreSQL documentsStable document identity and source metadata
PostgreSQL chunksText, embeddings, lexical text, OCR confidence, citations metadata
pgvector HNSWSemantic retrieval over approved embeddings
PostgreSQL GIN FTSLexical retrieval over approved lexical text
Redis / queue state storeJob state in local/in-memory path, DCS target in production
Kafka / DMSAsync document-processing events in target architecture

Idempotency and re-ingestion

The worker message carries content_sha256, and document identity uses source type, source version, and stable source key. For batch ingestion, the full object key is used as the source key so same-basename files in different folders persist as separate documents. Re-ingesting the same source replaces stale chunks transactionally.

Availability to AI services

A document becomes available to AI services only after at least one approved chunk is indexed. needs_ocr_review chunks persist for review but are excluded from semantic and lexical retrieval. /search can retrieve ranked chunks, and /query can synthesize a cited answer only from retrieved chunks.

Operational states

StateMeaning
queuedUpload accepted and waiting for worker processing
processingWorker has started ingestion
doneProcessing completed and approved chunks were persisted
needs_reviewHuman review required, usually OCR confidence related
failed / permanently_failedProcessing failed and will not complete without operator action
retryingWorker will retry after a transient failure
skippedDuplicate or already-processed work skipped