ETL Module API Reference¶
Auto-generated from Python docstrings
Pipeline¶
green_gov_rag.etl.pipeline ¶
Enhanced ETL Pipeline with Automated Metadata Tagging.
This module provides an end-to-end ETL pipeline that: 1. Loads documents from config or cloud storage 2. Downloads and parses PDFs 3. Auto-tags with ESG/NGER metadata 4. Chunks with preserved metadata 5. Saves chunks to cloud or local storage 6. Builds embeddings and vector store
Supports both local filesystem and cloud storage (AWS S3, Azure Blob) via the ETL storage adapter.
EnhancedETLPipeline ¶
ETL pipeline with automated metadata extraction and cloud storage support.
Source code in green_gov_rag/etl/pipeline.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__init__ ¶
__init__(enable_auto_tagging: bool = True, chunk_size: int = 1000, chunk_overlap: int = 100, use_cloud: bool | None = None, storage_adapter: ETLStorageAdapter | None = None)
Initialize ETL pipeline.
enable_auto_tagging: Whether to auto-tag documents with ESG metadata
chunk_size: Size of text chunks
chunk_overlap: Overlap between chunks
use_cloud: Whether to use cloud storage. If None, uses settings.
storage_adapter: Optional custom storage adapter instance
Source code in green_gov_rag/etl/pipeline.py
load_and_parse_documents ¶
Load documents from config and parse them.
config_path: Path to documents config YAML
List of parsed Document objects with metadata
Source code in green_gov_rag/etl/pipeline.py
auto_tag_documents ¶
Auto-tag documents with ESG/NGER metadata using LLM.
documents: List of Document objects
Documents with enriched metadata
Source code in green_gov_rag/etl/pipeline.py
chunk_documents ¶
Chunk documents while preserving metadata.
documents: List of Document objects
List of chunked documents with metadata
Source code in green_gov_rag/etl/pipeline.py
run ¶
run(config_path: str = 'configs/documents_config.yml', output_path: str | None = None, document_ids: list[str] | None = None) -> list[dict[str, Any]]
Run the complete ETL pipeline.
config_path: Path to documents config
output_path: Optional path to save processed chunks (local mode)
document_ids: Optional list of document IDs to process (cloud mode)
List of processed and chunked documents
Source code in green_gov_rag/etl/pipeline.py
process_pdf_with_tagging ¶
process_pdf_with_tagging(pdf_path: str, base_metadata: dict[str, Any] | None = None, auto_tag: bool = True) -> list[dict[str, Any]]
Process a single PDF with optional auto-tagging.
pdf_path: Path to PDF file
base_metadata: Base metadata from config
auto_tag: Whether to auto-tag with ESG metadata
List of chunked documents with metadata
Source code in green_gov_rag/etl/pipeline.py
Ingest¶
green_gov_rag.etl.ingest ¶
Document ingestion script for GreenGovRAG.
Supports both local filesystem and cloud storage (AWS S3, Azure Blob) via the ETL storage adapter. Provider selection is controlled via CLOUD_PROVIDER environment variable.
load_config ¶
sha256sum ¶
Compute SHA256 hash of a file.
download_file ¶
download_file(url, dest_path, retries=DEFAULT_DOWNLOAD_RETRIES, backoff=DEFAULT_DOWNLOAD_BACKOFF) -> bool
Download file with retry logic.
Uses browser-like headers to avoid bot detection (Cloudflare, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | URL to download | required | |
dest_path | Destination file path | required | |
retries | Number of retry attempts | DEFAULT_DOWNLOAD_RETRIES | |
backoff | Backoff multiplier for retries | DEFAULT_DOWNLOAD_BACKOFF |
Returns:
| Type | Description |
|---|---|
bool | True if successful, False otherwise |
Source code in green_gov_rag/etl/ingest.py
detect_file_type ¶
Detect file type from magic bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | Path | Path to file | required |
Returns:
| Type | Description |
|---|---|
str | None | File extension (.pdf, .html, etc.) or None if unknown |
Source code in green_gov_rag/etl/ingest.py
safe_filename ¶
process_document ¶
process_document(doc: dict[str, Any], storage_adapter: ETLStorageAdapter | None = None, use_cloud: bool = False) -> None
Download and save a single document with metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc | dict[str, Any] | Document configuration dictionary | required |
storage_adapter | ETLStorageAdapter | None | Optional ETL storage adapter (for cloud storage) | None |
use_cloud | bool | Whether to use cloud storage (requires storage_adapter) | False |
Source code in green_gov_rag/etl/ingest.py
download_documents ¶
Download multiple documents to output directory.
:param docs: List of document dicts with 'download_urls' key :param output_dir: Directory to save downloaded files :return: List of downloaded file paths
Source code in green_gov_rag/etl/ingest.py
ingest_documents ¶
Ingest documents from config using plugin system (single source of truth).
This function uses the document source plugin architecture to: - Validate configurations - Generate consistent document IDs (for delta indexing) - Create hierarchical directory structures - Extract metadata using source-specific logic
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_cloud | bool | None | Whether to use cloud storage. If None, uses CLOUD_PROVIDER setting. | None |
config_path | str | Path | None | Path to config file. Defaults to CONFIG_PATH. | None |
Returns:
| Type | Description |
|---|---|
list[str] | List of document IDs (cloud mode) or file paths (local mode) |
Source code in green_gov_rag/etl/ingest.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
main ¶
Main entry point for CLI usage.
Source code in green_gov_rag/etl/ingest.py
Loader¶
green_gov_rag.etl.loader ¶
load_documents_config ¶
Load document metadata from YAML config.
This function maintains backward compatibility with the original API while supporting the new plugin-based architecture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path | str | Path to documents configuration file | 'configs/documents_config.yml' |
Returns:
| Type | Description |
|---|---|
| List of document configuration dictionaries |
Source code in green_gov_rag/etl/loader.py
load_document_sources ¶
Load document sources using the plugin-based architecture.
This is the new API that returns DocumentSource objects instead of raw configuration dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path | str | Path to documents configuration file | 'configs/documents_config.yml' |
Returns:
| Type | Description |
|---|---|
list[DocumentSource] | List of DocumentSource plugin instances |
Example
sources = load_document_sources() for source in sources: ... metadata = source.get_metadata() ... urls = source.get_download_urls() ... validation = source.validate()
Source code in green_gov_rag/etl/loader.py
get_document_sources ¶
Returns a list of all source URLs for ingestion.
This function maintains backward compatibility with the original API.
Returns:
| Type | Description |
|---|---|
| List of download URLs |
Source code in green_gov_rag/etl/loader.py
get_document_sources_by_type ¶
Get document sources filtered by type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_type | str | Source type identifier (e.g., 'federal_legislation') | required |
Returns:
| Type | Description |
|---|---|
list[DocumentSource] | List of DocumentSource instances matching the type |
Example
federal_sources = get_document_sources_by_type('federal_legislation') emissions_sources = get_document_sources_by_type('emissions_reporting')
Source code in green_gov_rag/etl/loader.py
get_document_sources_by_jurisdiction ¶
Get document sources filtered by jurisdiction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jurisdiction | str | Jurisdiction filter ('federal', 'state', 'local') | required |
Returns:
| Type | Description |
|---|---|
list[DocumentSource] | List of DocumentSource instances matching the jurisdiction |
Example
federal_sources = get_document_sources_by_jurisdiction('federal') local_sources = get_document_sources_by_jurisdiction('local')
Source code in green_gov_rag/etl/loader.py
load_yaml ¶
Load YAML file and return as dictionary.
:param file_path: Path to YAML file :return: Parsed YAML content as dictionary
Source code in green_gov_rag/etl/loader.py
load_documents_from_storage ¶
load_documents_from_storage(jurisdiction: str | None = None, category: str | None = None, topic: str | None = None, storage_adapter: ETLStorageAdapter | None = None) -> list[dict]
Load documents from cloud storage with optional filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jurisdiction | str | None | Filter by jurisdiction | None |
category | str | None | Filter by category | None |
topic | str | None | Filter by topic | None |
storage_adapter | ETLStorageAdapter | None | Optional custom storage adapter | None |
Returns:
| Type | Description |
|---|---|
list[dict] | List of document metadata dictionaries |
Example
Load all federal documents¶
docs = load_documents_from_storage(jurisdiction='federal')
Load specific topic¶
docs = load_documents_from_storage( ... jurisdiction='federal', ... category='environment', ... topic='emissions_reporting' ... )
Source code in green_gov_rag/etl/loader.py
get_document_content_from_storage ¶
get_document_content_from_storage(document_id: str, storage_adapter: ETLStorageAdapter | None = None) -> tuple[bytes, dict]
Load document content and metadata from storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_id | str | Document ID | required |
storage_adapter | ETLStorageAdapter | None | Optional custom storage adapter | None |
Returns:
| Type | Description |
|---|---|
tuple[bytes, dict] | Tuple of (content bytes, metadata dict) |
Example
content, metadata = get_document_content_from_storage('abc123') print(metadata['title']) 'NGER Guidelines 2024'
Source code in green_gov_rag/etl/loader.py
get_document_chunks_from_storage ¶
get_document_chunks_from_storage(document_id: str, storage_adapter: ETLStorageAdapter | None = None) -> list[dict]
Load processed chunks for a document from storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_id | str | Document ID | required |
storage_adapter | ETLStorageAdapter | None | Optional custom storage adapter | None |
Returns:
| Type | Description |
|---|---|
list[dict] | List of chunk dictionaries |
Example
chunks = get_document_chunks_from_storage('abc123') print(f"Loaded {len(chunks)} chunks") print(chunks[0]['content'])
Source code in green_gov_rag/etl/loader.py
Chunker¶
green_gov_rag.etl.chunker ¶
Chunker module for splitting documents into smaller text chunks using LangChain text splitters.
- Uses RecursiveCharacterTextSplitter (handles paragraphs → sentences → words).
- Configurable chunk_size, chunk_overlap, and separators.
- Skips empty/whitespace-only texts.
- Returns flat list of chunks for indexing or embeddings.
TextChunker ¶
Source code in green_gov_rag/etl/chunker.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
__init__ ¶
__init__(chunk_size: int = DEFAULT_CHUNK_SIZE, chunk_overlap: int = DEFAULT_CHUNK_OVERLAP, splitter_type: str = 'recursive')
Initialize text chunker. :param chunk_size: Max characters or tokens per chunk :param chunk_overlap: Overlap between chunks :param splitter_type: "recursive" or "token".
Source code in green_gov_rag/etl/chunker.py
chunk_text ¶
chunk_docs ¶
Split list of documents into smaller chunks. Each doc should have: {"content": str, "metadata": dict}.
Source code in green_gov_rag/etl/chunker.py
chunk_with_hierarchy ¶
Chunk hierarchical documents while preserving section metadata.
For documents parsed with HierarchicalPDFParser, this preserves section hierarchy, page numbers, and structural context.
hierarchical_chunks: Chunks from HierarchicalPDFParser with metadata
List of smaller chunks with preserved hierarchical metadata
Source code in green_gov_rag/etl/chunker.py
chunk_text ¶
chunk_text(text: str, chunk_size: int = DEFAULT_CHUNK_SIZE, chunk_overlap: int = DEFAULT_CHUNK_OVERLAP, splitter_type: str = 'recursive') -> list[str]
Convenience function to chunk text without creating a TextChunker instance.
Source code in green_gov_rag/etl/chunker.py
Metadata Tagger¶
green_gov_rag.etl.metadata_tagger ¶
Automated Metadata Tagging using LangChain.
This module provides LLM-powered metadata extraction for ESG/NGER documents, automating the tagging process to ensure consistent categorization.
ESGMetadata ¶
Bases: BaseModel
ESG metadata schema for automated tagging.
Source code in green_gov_rag/etl/metadata_tagger.py
DocumentMetadata ¶
Bases: BaseModel
General document metadata schema.
Source code in green_gov_rag/etl/metadata_tagger.py
MetadataTagger ¶
LLM-powered metadata tagger for automatic document categorization.
Source code in green_gov_rag/etl/metadata_tagger.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
__init__ ¶
Initialize metadata tagger.
model_name: OpenAI model to use for tagging
temperature: Model temperature (0 for deterministic)
Source code in green_gov_rag/etl/metadata_tagger.py
tag_esg_metadata ¶
Extract ESG metadata from document text.
text: Document text to analyze
Dict of ESG metadata
Source code in green_gov_rag/etl/metadata_tagger.py
tag_document_metadata ¶
Extract general document metadata from text.
text: Document text to analyze
Dict of document metadata
Source code in green_gov_rag/etl/metadata_tagger.py
tag_document ¶
Tag a LangChain Document with metadata.
document: LangChain Document to tag
include_esg: Whether to extract ESG metadata
Document with enriched metadata
Source code in green_gov_rag/etl/metadata_tagger.py
tag_documents ¶
Tag multiple documents with metadata.
documents: List of LangChain Documents
include_esg: Whether to extract ESG metadata
List of Documents with enriched metadata
Source code in green_gov_rag/etl/metadata_tagger.py
CustomPromptTagger ¶
Metadata tagger with custom prompts for specific use cases.
Source code in green_gov_rag/etl/metadata_tagger.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
__init__ ¶
Initialize custom prompt tagger.
model_name: OpenAI model to use
temperature: Model temperature
Source code in green_gov_rag/etl/metadata_tagger.py
extract_scope_3_categories ¶
Extract Scope 3 categories from text using custom prompt.
text: Document text
List of Scope 3 category names
Source code in green_gov_rag/etl/metadata_tagger.py
identify_regulatory_framework ¶
Identify regulatory framework and compliance requirements.
text: Document text
Dict with framework, regulator, and compliance info
Source code in green_gov_rag/etl/metadata_tagger.py
ESGOpenAITagger ¶
Wrapper for OpenAIMetadataTagger with ESG-specific schemas.
Source code in green_gov_rag/etl/metadata_tagger.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
__init__ ¶
Initialize ESG metadata tagger with predefined schemas.
Source code in green_gov_rag/etl/metadata_tagger.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
tag_esg_metadata ¶
Tag documents with ESG metadata.
documents: List of LangChain Documents
Documents with ESG metadata added
Source code in green_gov_rag/etl/metadata_tagger.py
tag_document_metadata ¶
Tag documents with general metadata.
documents: List of LangChain Documents
Documents with general metadata added
Source code in green_gov_rag/etl/metadata_tagger.py
tag_all ¶
Tag documents with both ESG and general metadata.
documents: List of LangChain Documents
Fully tagged documents
Source code in green_gov_rag/etl/metadata_tagger.py
DB Writer¶
green_gov_rag.etl.db_writer ¶
Database writer for ETL pipeline.
Supports tracking both local filesystem and cloud storage paths for documents and chunks with normalized schema: - document_sources: Config entries (1:many with files) - document_files: Individual PDFs - document_chunks: Text segments
create_document_id ¶
Generate unique document ID from URL and title.
save_document_source ¶
save_document_source(title: str, source_url: str, jurisdiction: str, topic: str, region: Optional[str] = None, category: Optional[str] = None, metadata: Optional[dict] = None, esg_metadata: Optional[dict] = None, spatial_metadata: Optional[dict] = None, status: str = 'pending') -> DocumentSource
Save document source (config entry) to database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title | str | Source title | required |
source_url | str | Source website URL (homepage) | required |
jurisdiction | str | Federal/State/Local | required |
topic | str | Document topic | required |
region | Optional[str] | Geographic region | None |
category | Optional[str] | Document category | None |
metadata | Optional[dict] | Additional metadata | None |
esg_metadata | Optional[dict] | ESG/emissions metadata (frameworks, scopes, gases, etc.) | None |
spatial_metadata | Optional[dict] | Spatial metadata (LGA codes, state, spatial scope, etc.) | None |
status | str | Processing status | 'pending' |
Returns:
| Name | Type | Description |
|---|---|---|
DocumentSource | DocumentSource | Saved document source |
Source code in green_gov_rag/etl/db_writer.py
save_document_file ¶
save_document_file(source_id: str, filename: str, file_url: str, content_hash: str, file_size_bytes: Optional[int] = None, file_metadata: Optional[dict] = None, status: str = 'pending') -> DocumentFile
Save document file (individual PDF) to database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id | str | Parent document source ID | required |
filename | str | Original filename | required |
file_url | str | Direct download URL for this file | required |
content_hash | str | SHA256 hash of file content | required |
file_size_bytes | Optional[int] | File size in bytes | None |
file_metadata | Optional[dict] | File-specific metadata (page count, format, etc.) | None |
status | str | Processing status | 'pending' |
Returns:
| Name | Type | Description |
|---|---|---|
DocumentFile | DocumentFile | Saved document file |
Source code in green_gov_rag/etl/db_writer.py
update_document_source_status ¶
update_document_source_status(source_id: str, status: str, error_message: Optional[str] = None, chunk_count: Optional[int] = None, embedding_model: Optional[str] = None) -> None
Update document source processing status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id | str | Document source ID | required |
status | str | New status (pending/processing/completed/failed) | required |
error_message | Optional[str] | Error message if failed | None |
chunk_count | Optional[int] | Number of chunks created | None |
embedding_model | Optional[str] | Embedding model used | None |
Source code in green_gov_rag/etl/db_writer.py
update_document_file_status ¶
update_document_file_status(file_id: str, status: str, error_message: Optional[str] = None, chunk_count: Optional[int] = None) -> None
Update document file processing status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id | str | Document file ID | required |
status | str | New status (pending/downloading/processing/completed/failed) | required |
error_message | Optional[str] | Error message if failed | None |
chunk_count | Optional[int] | Number of chunks from this file | None |
Source code in green_gov_rag/etl/db_writer.py
save_chunk ¶
save_chunk(source_id: str, file_id: str, chunk_index: int, text: str, page_number: Optional[int] = None, page_range: Optional[list[int]] = None, section_title: Optional[str] = None, section_hierarchy: Optional[list[str]] = None, clause_reference: Optional[str] = None, source_pdf_url: Optional[str] = None, deep_link: Optional[str] = None, citation: Optional[str] = None, embedding_index: Optional[int] = None, embedding_model: Optional[str] = None, metadata: Optional[dict] = None) -> Chunk
Save text chunk to database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id | str | Parent document source ID (config entry) | required |
file_id | str | Specific file this chunk came from | required |
chunk_index | int | Chunk position in document | required |
text | str | Chunk text | required |
page_number | Optional[int] | Page number if PDF | None |
page_range | Optional[list[int]] | Page range if chunk spans multiple pages [start, end] | None |
section_title | Optional[str] | Section title | None |
section_hierarchy | Optional[list[str]] | Full section hierarchy from document root | None |
clause_reference | Optional[str] | Legal clause/section reference (e.g., 's.3.2.1') | None |
source_pdf_url | Optional[str] | Direct PDF URL for deep linking | None |
deep_link | Optional[str] | Deep link to specific section/page in source document | None |
citation | Optional[str] | Formatted citation string for display | None |
embedding_index | Optional[int] | Index in vector store | None |
embedding_model | Optional[str] | Embedding model used | None |
metadata | Optional[dict] | Additional chunk metadata | None |
Returns:
| Name | Type | Description |
|---|---|---|
Chunk | Chunk | Saved chunk |
Source code in green_gov_rag/etl/db_writer.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
get_document_source_by_id ¶
Get document source by ID.
Source code in green_gov_rag/etl/db_writer.py
get_document_file_by_id ¶
Get document file by ID.
Source code in green_gov_rag/etl/db_writer.py
get_chunks_by_source ¶
Get all chunks for a document source.
Source code in green_gov_rag/etl/db_writer.py
get_chunks_by_file ¶
Get all chunks for a document file.
save_document_source_from_storage_metadata ¶
Save document source to database from cloud storage metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_metadata | dict[str, Any] | Metadata dict from ETL storage adapter | required |
Returns:
| Name | Type | Description |
|---|---|---|
DocumentSource | DocumentSource | Saved document source |
Source code in green_gov_rag/etl/db_writer.py
save_chunks_from_storage ¶
save_chunks_from_storage(source_id: str, file_id: str, chunks: list[dict[str, Any]], embedding_model: Optional[str] = None) -> list[Chunk]
Save chunks to database from cloud storage chunk data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id | str | Parent document source ID | required |
file_id | str | Parent document file ID | required |
chunks | list[dict[str, Any]] | List of chunk dicts from ETL storage adapter | required |
embedding_model | Optional[str] | Optional embedding model name | None |
Returns:
| Type | Description |
|---|---|
list[Chunk] | List of saved Chunk objects |
Source code in green_gov_rag/etl/db_writer.py
save_document_version ¶
save_document_version(file_id: str, source_id: str, content_hash: str, source_url: str, file_size_bytes: Optional[int] = None, change_type: str = 'new', remote_last_modified: Optional[datetime] = None, remote_etag: Optional[str] = None, metadata: Optional[dict] = None) -> DocumentVersion
Create a new document version record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id | str | Specific document file ID | required |
source_id | str | Parent document source ID | required |
content_hash | str | SHA256 hash of document content | required |
source_url | str | URL where document was retrieved | required |
file_size_bytes | Optional[int] | File size in bytes | None |
change_type | str | Type of change ('new', 'updated', 'unchanged') | 'new' |
remote_last_modified | Optional[datetime] | Last-Modified header from server | None |
remote_etag | Optional[str] | ETag header from server | None |
metadata | Optional[dict] | Additional version metadata | None |
Returns:
| Name | Type | Description |
|---|---|---|
DocumentVersion | DocumentVersion | Created version record |