Data ingestion pipeline for COPOM (Comitê de Política Monetária do Banco Central do Brasil) documents.
Automatically downloads Minutes and Communications from the BCB, extracts text from PDFs, chunks the content, generates embeddings, and stores everything in PostgreSQL + pgvector. It is the data foundation of the COPOM RAG ecosystem.
This project is one of three components of the COPOM RAG system:
Banco Central (PDFs)
│
▼
copom-vector-pipeline ← you are here (ingestion, chunking, embeddings)
│
▼
PostgreSQL + pgvector ← shared vector database (Neon)
│
▼
copom-rag-api ← semantic search + generation via Gemini
│
▼
copom-streamlit ← web interface for end users
BCB API ──► BcbDownloader ──► PdfParser ──► TextCleaner ──► TextChunker
│
EmbeddingProvider
(Gemini / pluggable)
│
PostgresHandler ──► PostgreSQL + pgvector
All collaborators are wired together by CopomPipeline using dependency injection. Swapping any component (embedding provider, chunking strategy, document source) does not require touching the pipeline logic.
- Python 3.11+
- Docker (for local PostgreSQL + pgvector)
- Google Gemini API key
# 1. Clone the repository
git clone https://github.com/<org>/copom-vector-pipeline.git
cd copom-vector-pipeline
# 2. Start PostgreSQL + pgvector
docker compose up -d
# 3. Install the package
pip install -e .
# 4. Configure environment variables
cp .env.example .env
# Edit .env and fill in GEMINI_API_KEY and DATABASE_URL
# 5. Apply the database schema (first time only)
docker exec -i copom_pgvector psql -U copom -d copom_rag < scripts/create_schema.sql
# 6. Run the pipeline
copom-pipeline --doc-type allcopom-pipeline [OPTIONS]
Options:
--doc-type {ata,comunicado,all} Document types to ingest (default: all)
--from-date YYYY-MM-DD Only process documents from this date
--to-date YYYY-MM-DD Only process documents up to this date
--resume Resume from the last saved checkpoint
--dry-run Fetch metadata only — no DB writes
--chunk-size INT Token chunk size (default: 500)
--chunk-overlap INT Token overlap between chunks (default: 20)
--batch-size INT Embedding batch size (default: 50)
--checkpoint-interval INT Save checkpoint every N documents (default: 20)
--checkpoint-dir PATH Directory for checkpoint files (default: ./checkpoints)
--log-dir PATH Directory for log files (default: ./logs)
--log-level {DEBUG,INFO,WARNING,ERROR}
Examples:
# Ingest all document types
copom-pipeline --doc-type all
# Only minutes from 2024
copom-pipeline --doc-type ata --from-date 2024-01-01 --to-date 2024-12-31
# Resume an interrupted run
copom-pipeline --doc-type all --resume
# Dry-run (no database writes)
copom-pipeline --doc-type all --dry-run| Variable | Required | Default | Description |
|---|---|---|---|
GEMINI_API_KEY |
Yes | — | Google AI API key |
DATABASE_URL |
Yes | — | PostgreSQL DSN (postgresql://user:pass@host/db) |
EMBEDDING_PROVIDER |
No | gemini |
Embedding provider name |
GEMINI_EMBEDDING_MODEL |
No | models/gemini-embedding-001 |
Gemini embedding model |
EMBEDDING_DIMENSIONS |
No | 1536 |
Output vector dimensions |
CHUNK_SIZE |
No | 500 |
Chunk size in tokens |
CHUNK_OVERLAP |
No | 20 |
Overlap between chunks in tokens |
BATCH_SIZE |
No | 50 |
Embedding batch size |
BCB_REQUEST_DELAY_SECONDS |
No | 1.0 |
Delay between HTTP requests to BCB |
BCB_MAX_RETRIES |
No | 3 |
Max retries per HTTP request |
Important:
GEMINI_EMBEDDING_MODELandEMBEDDING_DIMENSIONSmust be identical to those configured incopom-rag-api. Changing the embedding model requires re-ingesting all documents.
See scripts/create_schema.sql.
Two tables:
documents— one row per document (url, title, doc_type, meeting_date, source_hash)chunks— one row per text chunk, withembedding vector(1536)and an HNSW index
Deduplication is automatic via source_hash (SHA-256 of the content): re-running the pipeline will not duplicate already-ingested documents.
# General stats
python scripts/db_crud.py stats
# List ingested documents
python scripts/db_crud.py list
# Show details of a document
python scripts/db_crud.py show 1
# Manual semantic search
python scripts/db_crud.py search "taxa Selic 2026"
python scripts/db_crud.py search "inflação" --top-k 10 --doc-type ata
# Delete a document
python scripts/db_crud.py delete 3- Create
src/copom_pipeline/providers/my_provider.py - Subclass
EmbeddingProviderand implementembed_text,embed_batch, anddimensions - Decorate the class with
@register_embedding_provider("my-provider") - Add an import in
providers/factory.pyinside_load_providers() - Set
EMBEDDING_PROVIDER=my-providerin.env
No other files need to change.
pip install -e ".[dev]"
pytest tests/- copom-rag-api — RAG API that consumes the vector database
- copom-streamlit — web interface for natural language queries