|
| 1 | +```python Python Ingest v2 |
| 2 | +import os |
| 3 | + |
| 4 | +from unstructured_ingest.v2.pipeline.pipeline import Pipeline |
| 5 | +from unstructured_ingest.v2.interfaces import ProcessorConfig |
| 6 | + |
| 7 | +from unstructured_ingest.v2.processes.connectors.sql.postgres import ( |
| 8 | + PostgresIndexerConfig, |
| 9 | + PostgresDownloaderConfig, |
| 10 | + PostgresConnectionConfig, |
| 11 | + PostgresAccessConfig |
| 12 | +) |
| 13 | + |
| 14 | +from unstructured_ingest.v2.processes.partitioner import PartitionerConfig |
| 15 | +from unstructured_ingest.v2.processes.chunker import ChunkerConfig |
| 16 | +from unstructured_ingest.v2.processes.embedder import EmbedderConfig |
| 17 | + |
| 18 | +from unstructured_ingest.v2.processes.connectors.local import ( |
| 19 | + LocalConnectionConfig, |
| 20 | + LocalUploaderConfig |
| 21 | +) |
| 22 | + |
| 23 | +# Chunking and embedding are optional. |
| 24 | + |
| 25 | +if __name__ == "__main__": |
| 26 | + Pipeline.from_configs( |
| 27 | + context=ProcessorConfig(), |
| 28 | + indexer_config=PostgresIndexerConfig( |
| 29 | + table_name="elements", |
| 30 | + id_column="id" |
| 31 | + ), |
| 32 | + downloader_config=PostgresDownloaderConfig(download_dir=os.getenv("LOCAL_FILE_DOWNLOAD_DIR")), |
| 33 | + source_connection_config=PostgresConnectionConfig( |
| 34 | + access_config=PostgresAccessConfig(password=os.getenv("PGPASSWORD")), |
| 35 | + host=os.getenv("PGHOST"), |
| 36 | + port=os.getenv("PGPORT"), |
| 37 | + username=os.getenv("PGUSER"), |
| 38 | + database=os.getenv("PGDATABASE") |
| 39 | + ), |
| 40 | + partitioner_config=PartitionerConfig( |
| 41 | + partition_by_api=True, |
| 42 | + api_key=os.getenv("UNSTRUCTURED_API_KEY"), |
| 43 | + partition_endpoint=os.getenv("UNSTRUCTURED_API_URL"), |
| 44 | + additional_partition_args={ |
| 45 | + "split_pdf_page": True, |
| 46 | + "split_pdf_allow_failed": True, |
| 47 | + "split_pdf_concurrency_level": 15 |
| 48 | + } |
| 49 | + ), |
| 50 | + chunker_config=ChunkerConfig(chunking_strategy="by_title"), |
| 51 | + embedder_config=EmbedderConfig(embedding_provider="huggingface"), |
| 52 | + destination_connection_config=LocalConnectionConfig(), |
| 53 | + uploader_config=LocalUploaderConfig(output_dir=os.getenv("LOCAL_FILE_OUTPUT_DIR")) |
| 54 | + ).run() |
| 55 | +``` |
0 commit comments