|
| 1 | +import random |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from unstructured.ingest.v2.interfaces import ProcessorConfig |
| 5 | +from unstructured.ingest.v2.logger import logger |
| 6 | +from unstructured.ingest.v2.pipeline.pipeline import Pipeline |
| 7 | +from unstructured.ingest.v2.processes.chunker import ChunkerConfig |
| 8 | +from unstructured.ingest.v2.processes.connectors.chroma import ( |
| 9 | + ChromaAccessConfig, |
| 10 | + ChromaConnectionConfig, |
| 11 | + ChromaUploaderConfig, |
| 12 | + ChromaUploadStagerConfig, |
| 13 | +) |
| 14 | +from unstructured.ingest.v2.processes.connectors.local import ( |
| 15 | + LocalConnectionConfig, |
| 16 | + LocalDownloaderConfig, |
| 17 | + LocalIndexerConfig, |
| 18 | +) |
| 19 | +from unstructured.ingest.v2.processes.embedder import EmbedderConfig |
| 20 | +from unstructured.ingest.v2.processes.partitioner import PartitionerConfig |
| 21 | + |
| 22 | +base_path = Path(__file__).parent.parent.parent.parent.parent |
| 23 | +docs_path = base_path / "example-docs" |
| 24 | +work_dir = base_path / "tmp_ingest" |
| 25 | +output_path = work_dir / "output" |
| 26 | +download_path = work_dir / "download" |
| 27 | + |
| 28 | +if __name__ == "__main__": |
| 29 | + logger.info(f"Writing all content in: {work_dir.resolve()}") |
| 30 | + Pipeline.from_configs( |
| 31 | + context=ProcessorConfig(work_dir=str(work_dir.resolve())), |
| 32 | + indexer_config=LocalIndexerConfig(input_path=str(docs_path.resolve()) + "/multisimple/"), |
| 33 | + downloader_config=LocalDownloaderConfig(download_dir=download_path), |
| 34 | + source_connection_config=LocalConnectionConfig(), |
| 35 | + partitioner_config=PartitionerConfig(strategy="fast"), |
| 36 | + chunker_config=ChunkerConfig( |
| 37 | + chunking_strategy="by_title", |
| 38 | + chunk_include_orig_elements=False, |
| 39 | + chunk_max_characters=1500, |
| 40 | + chunk_multipage_sections=True, |
| 41 | + ), |
| 42 | + embedder_config=EmbedderConfig(embedding_provider="langchain-huggingface"), |
| 43 | + destination_connection_config=ChromaConnectionConfig( |
| 44 | + access_config=ChromaAccessConfig(settings=None, headers=None), |
| 45 | + host="localhost", |
| 46 | + port=8047, |
| 47 | + collection_name=f"test-collection-{random.randint(1000,9999)}", |
| 48 | + tenant="default_tenant", |
| 49 | + database="default_database", |
| 50 | + ), |
| 51 | + stager_config=ChromaUploadStagerConfig(), |
| 52 | + uploader_config=ChromaUploaderConfig(batch_size=10), |
| 53 | + ).run() |
0 commit comments