|
| 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.redisdb import ( |
| 8 | + RedisAccessConfig, |
| 9 | + RedisConnectionConfig, |
| 10 | + RedisUploaderConfig |
| 11 | +) |
| 12 | +from unstructured_ingest.v2.processes.connectors.local import ( |
| 13 | + LocalIndexerConfig, |
| 14 | + LocalConnectionConfig, |
| 15 | + LocalDownloaderConfig |
| 16 | +) |
| 17 | +from unstructured_ingest.v2.processes.partitioner import PartitionerConfig |
| 18 | +from unstructured_ingest.v2.processes.chunker import ChunkerConfig |
| 19 | +from unstructured_ingest.v2.processes.embedder import EmbedderConfig |
| 20 | + |
| 21 | +# Chunking and embedding are optional. |
| 22 | + |
| 23 | +if __name__ == "__main__": |
| 24 | + Pipeline.from_configs( |
| 25 | + context=ProcessorConfig(), |
| 26 | + indexer_config=LocalIndexerConfig(input_path=os.getenv("LOCAL_FILE_INPUT_DIR")), |
| 27 | + downloader_config=LocalDownloaderConfig(), |
| 28 | + source_connection_config=LocalConnectionConfig(), |
| 29 | + partitioner_config=PartitionerConfig( |
| 30 | + partition_by_api=True, |
| 31 | + api_key=os.getenv("UNSTRUCTURED_API_KEY"), |
| 32 | + partition_endpoint=os.getenv("UNSTRUCTURED_API_URL"), |
| 33 | + additional_partition_args={ |
| 34 | + "split_pdf_page": True, |
| 35 | + "split_pdf_allow_failed": True, |
| 36 | + "split_pdf_concurrency_level": 15 |
| 37 | + } |
| 38 | + ), |
| 39 | + chunker_config=ChunkerConfig(chunking_strategy="by_title"), |
| 40 | + embedder_config=EmbedderConfig(embedding_provider="huggingface"), |
| 41 | + |
| 42 | + # Use a Redis connection string. |
| 43 | + # destination_connection_config=RedisConnectionConfig( |
| 44 | + # access_config=RedisAccessConfig( |
| 45 | + # uri = os.getenv("REDIS_URI") |
| 46 | + # ) |
| 47 | + # ), |
| 48 | + |
| 49 | + # Use Redis connection properties. |
| 50 | + destination_connection_config=RedisConnectionConfig( |
| 51 | + access_config=RedisAccessConfig( |
| 52 | + password=os.getenv("REDIS_PASSWORD") |
| 53 | + ), |
| 54 | + host=os.getenv("REDIS_HOST"), |
| 55 | + database=int(os.getenv("REDIS_DATABASE")), |
| 56 | + port=int(os.getenv("REDIS_PORT")), |
| 57 | + username=os.getenv("REDIS_USERNAME"), |
| 58 | + ssl=False |
| 59 | + ), |
| 60 | + uploader_config=RedisUploaderConfig(batch_size=100) |
| 61 | + ).run() |
0 commit comments