unstructured-ingest 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of unstructured-ingest might be problematic. Click here for more details.
- test/integration/connectors/test_confluence.py +113 -0
- test/integration/connectors/test_kafka.py +67 -0
- test/integration/connectors/test_onedrive.py +112 -0
- test/integration/connectors/test_qdrant.py +137 -0
- test/integration/connectors/utils/docker.py +2 -1
- test/integration/connectors/utils/validation.py +73 -22
- unstructured_ingest/__version__.py +1 -1
- unstructured_ingest/connector/kafka.py +0 -1
- unstructured_ingest/interfaces.py +7 -7
- unstructured_ingest/v2/processes/chunker.py +2 -2
- unstructured_ingest/v2/processes/connectors/__init__.py +12 -1
- unstructured_ingest/v2/processes/connectors/confluence.py +195 -0
- unstructured_ingest/v2/processes/connectors/databricks/volumes.py +2 -4
- unstructured_ingest/v2/processes/connectors/fsspec/fsspec.py +1 -10
- unstructured_ingest/v2/processes/connectors/gitlab.py +267 -0
- unstructured_ingest/v2/processes/connectors/kafka/__init__.py +13 -0
- unstructured_ingest/v2/processes/connectors/kafka/cloud.py +82 -0
- unstructured_ingest/v2/processes/connectors/kafka/kafka.py +196 -0
- unstructured_ingest/v2/processes/connectors/kafka/local.py +75 -0
- unstructured_ingest/v2/processes/connectors/onedrive.py +163 -2
- unstructured_ingest/v2/processes/connectors/qdrant/__init__.py +16 -0
- unstructured_ingest/v2/processes/connectors/qdrant/cloud.py +59 -0
- unstructured_ingest/v2/processes/connectors/qdrant/local.py +58 -0
- unstructured_ingest/v2/processes/connectors/qdrant/qdrant.py +168 -0
- unstructured_ingest/v2/processes/connectors/qdrant/server.py +60 -0
- unstructured_ingest/v2/processes/connectors/sql/snowflake.py +3 -1
- unstructured_ingest/v2/processes/connectors/sql/sql.py +2 -4
- unstructured_ingest/v2/processes/partitioner.py +14 -3
- unstructured_ingest/v2/unstructured_api.py +24 -10
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/METADATA +22 -22
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/RECORD +35 -20
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/LICENSE.md +0 -0
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/WHEEL +0 -0
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/entry_points.txt +0 -0
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from contextlib import contextmanager
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from time import time
|
|
6
|
+
from typing import TYPE_CHECKING, Any, ContextManager, Generator, Optional
|
|
7
|
+
|
|
8
|
+
from pydantic import Secret
|
|
9
|
+
|
|
10
|
+
from unstructured_ingest.error import (
|
|
11
|
+
SourceConnectionError,
|
|
12
|
+
SourceConnectionNetworkError,
|
|
13
|
+
)
|
|
14
|
+
from unstructured_ingest.utils.dep_check import requires_dependencies
|
|
15
|
+
from unstructured_ingest.v2.interfaces import (
|
|
16
|
+
AccessConfig,
|
|
17
|
+
ConnectionConfig,
|
|
18
|
+
Downloader,
|
|
19
|
+
DownloaderConfig,
|
|
20
|
+
FileData,
|
|
21
|
+
FileDataSourceMetadata,
|
|
22
|
+
Indexer,
|
|
23
|
+
IndexerConfig,
|
|
24
|
+
SourceIdentifiers,
|
|
25
|
+
download_responses,
|
|
26
|
+
)
|
|
27
|
+
from unstructured_ingest.v2.logger import logger
|
|
28
|
+
from unstructured_ingest.v2.processes.connector_registry import SourceRegistryEntry
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
from confluent_kafka import Consumer
|
|
32
|
+
|
|
33
|
+
CONNECTOR_TYPE = "kafka"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class KafkaAccessConfig(AccessConfig, ABC):
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class KafkaConnectionConfig(ConnectionConfig, ABC):
|
|
41
|
+
access_config: Secret[KafkaAccessConfig]
|
|
42
|
+
timeout: Optional[float] = 1.0
|
|
43
|
+
bootstrap_server: str
|
|
44
|
+
port: int
|
|
45
|
+
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def get_consumer_configuration(self) -> dict:
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
@contextmanager
|
|
51
|
+
@requires_dependencies(["confluent_kafka"], extras="kafka")
|
|
52
|
+
def get_consumer(self) -> ContextManager["Consumer"]:
|
|
53
|
+
from confluent_kafka import Consumer
|
|
54
|
+
|
|
55
|
+
consumer = Consumer(self.get_consumer_configuration())
|
|
56
|
+
try:
|
|
57
|
+
logger.debug("kafka consumer connected")
|
|
58
|
+
yield consumer
|
|
59
|
+
finally:
|
|
60
|
+
consumer.close()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class KafkaIndexerConfig(IndexerConfig):
|
|
64
|
+
topic: str
|
|
65
|
+
num_messages_to_consume: Optional[int] = 100
|
|
66
|
+
|
|
67
|
+
def update_consumer(self, consumer: "Consumer") -> None:
|
|
68
|
+
consumer.subscribe([self.topic])
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class KafkaIndexer(Indexer):
|
|
73
|
+
connection_config: KafkaConnectionConfig
|
|
74
|
+
index_config: KafkaIndexerConfig
|
|
75
|
+
connector_type: str = CONNECTOR_TYPE
|
|
76
|
+
|
|
77
|
+
@contextmanager
|
|
78
|
+
def get_consumer(self) -> ContextManager["Consumer"]:
|
|
79
|
+
with self.connection_config.get_consumer() as consumer:
|
|
80
|
+
self.index_config.update_consumer(consumer=consumer)
|
|
81
|
+
yield consumer
|
|
82
|
+
|
|
83
|
+
@requires_dependencies(["confluent_kafka"], extras="kafka")
|
|
84
|
+
def generate_messages(self) -> Generator[Any, None, None]:
|
|
85
|
+
from confluent_kafka import KafkaError, KafkaException
|
|
86
|
+
|
|
87
|
+
messages_consumed = 0
|
|
88
|
+
max_empty_polls = 10
|
|
89
|
+
empty_polls = 0
|
|
90
|
+
num_messages_to_consume = self.index_config.num_messages_to_consume
|
|
91
|
+
with self.get_consumer() as consumer:
|
|
92
|
+
while messages_consumed < num_messages_to_consume and empty_polls < max_empty_polls:
|
|
93
|
+
msg = consumer.poll(timeout=self.connection_config.timeout)
|
|
94
|
+
if msg is None:
|
|
95
|
+
logger.debug("No Kafka messages found")
|
|
96
|
+
empty_polls += 1
|
|
97
|
+
continue
|
|
98
|
+
if msg.error():
|
|
99
|
+
if msg.error().code() == KafkaError._PARTITION_EOF:
|
|
100
|
+
logger.info(
|
|
101
|
+
"Reached end of partition for topic %s [%d] at offset %d"
|
|
102
|
+
% (msg.topic(), msg.partition(), msg.offset())
|
|
103
|
+
)
|
|
104
|
+
break
|
|
105
|
+
else:
|
|
106
|
+
raise KafkaException(msg.error())
|
|
107
|
+
try:
|
|
108
|
+
empty_polls = 0
|
|
109
|
+
messages_consumed += 1
|
|
110
|
+
yield msg
|
|
111
|
+
finally:
|
|
112
|
+
consumer.commit(asynchronous=False)
|
|
113
|
+
|
|
114
|
+
def generate_file_data(self, msg) -> FileData:
|
|
115
|
+
msg_content = msg.value().decode("utf8")
|
|
116
|
+
identifier = f"{msg.topic()}_{msg.partition()}_{msg.offset()}"
|
|
117
|
+
additional_metadata = {
|
|
118
|
+
"topic": msg.topic(),
|
|
119
|
+
"partition": msg.partition(),
|
|
120
|
+
"offset": msg.offset(),
|
|
121
|
+
"content": msg_content,
|
|
122
|
+
}
|
|
123
|
+
filename = f"{identifier}.txt"
|
|
124
|
+
return FileData(
|
|
125
|
+
identifier=identifier,
|
|
126
|
+
connector_type=self.connector_type,
|
|
127
|
+
source_identifiers=SourceIdentifiers(
|
|
128
|
+
filename=filename,
|
|
129
|
+
fullpath=filename,
|
|
130
|
+
),
|
|
131
|
+
metadata=FileDataSourceMetadata(
|
|
132
|
+
date_processed=str(time()),
|
|
133
|
+
),
|
|
134
|
+
additional_metadata=additional_metadata,
|
|
135
|
+
display_name=filename,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
def run(self) -> Generator[FileData, None, None]:
|
|
139
|
+
for message in self.generate_messages():
|
|
140
|
+
yield self.generate_file_data(message)
|
|
141
|
+
|
|
142
|
+
async def run_async(self, file_data: FileData, **kwargs: Any) -> download_responses:
|
|
143
|
+
raise NotImplementedError()
|
|
144
|
+
|
|
145
|
+
def precheck(self):
|
|
146
|
+
try:
|
|
147
|
+
with self.get_consumer() as consumer:
|
|
148
|
+
cluster_meta = consumer.list_topics(timeout=self.connection_config.timeout)
|
|
149
|
+
current_topics = [
|
|
150
|
+
topic for topic in cluster_meta.topics if topic != "__consumer_offsets"
|
|
151
|
+
]
|
|
152
|
+
logger.info(f"successfully checked available topics: {current_topics}")
|
|
153
|
+
except Exception as e:
|
|
154
|
+
logger.error(f"failed to validate connection: {e}", exc_info=True)
|
|
155
|
+
raise SourceConnectionError(f"failed to validate connection: {e}")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class KafkaDownloaderConfig(DownloaderConfig):
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@dataclass
|
|
163
|
+
class KafkaDownloader(Downloader):
|
|
164
|
+
connection_config: KafkaConnectionConfig
|
|
165
|
+
download_config: KafkaDownloaderConfig = field(default_factory=KafkaDownloaderConfig)
|
|
166
|
+
connector_type: str = CONNECTOR_TYPE
|
|
167
|
+
version: Optional[str] = None
|
|
168
|
+
source_url: Optional[str] = None
|
|
169
|
+
|
|
170
|
+
def run(self, file_data: FileData, **kwargs: Any) -> download_responses:
|
|
171
|
+
source_identifiers = file_data.source_identifiers
|
|
172
|
+
if source_identifiers is None:
|
|
173
|
+
raise ValueError("FileData is missing source_identifiers")
|
|
174
|
+
|
|
175
|
+
# Build the download path using source_identifiers
|
|
176
|
+
download_path = Path(self.download_dir) / source_identifiers.relative_path
|
|
177
|
+
download_path.parent.mkdir(parents=True, exist_ok=True)
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
content = file_data.additional_metadata["content"]
|
|
181
|
+
with open(download_path, "w") as file:
|
|
182
|
+
file.write(content)
|
|
183
|
+
except Exception as e:
|
|
184
|
+
logger.error(f"Failed to download file {file_data.identifier}: {e}")
|
|
185
|
+
raise SourceConnectionNetworkError(f"failed to download file {file_data.identifier}")
|
|
186
|
+
|
|
187
|
+
return self.generate_download_response(file_data=file_data, download_path=download_path)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
kafka_source_entry = SourceRegistryEntry(
|
|
191
|
+
connection_config=KafkaConnectionConfig,
|
|
192
|
+
indexer=KafkaIndexer,
|
|
193
|
+
indexer_config=KafkaIndexerConfig,
|
|
194
|
+
downloader=KafkaDownloader,
|
|
195
|
+
downloader_config=KafkaDownloaderConfig,
|
|
196
|
+
)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import socket
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from pydantic import Field, Secret
|
|
6
|
+
|
|
7
|
+
from unstructured_ingest.v2.processes.connector_registry import SourceRegistryEntry
|
|
8
|
+
from unstructured_ingest.v2.processes.connectors.kafka.kafka import (
|
|
9
|
+
KafkaAccessConfig,
|
|
10
|
+
KafkaConnectionConfig,
|
|
11
|
+
KafkaDownloader,
|
|
12
|
+
KafkaDownloaderConfig,
|
|
13
|
+
KafkaIndexer,
|
|
14
|
+
KafkaIndexerConfig,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
CONNECTOR_TYPE = "kafka-local"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class LocalKafkaAccessConfig(KafkaAccessConfig):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class LocalKafkaConnectionConfig(KafkaConnectionConfig):
|
|
28
|
+
access_config: Secret[LocalKafkaAccessConfig] = Field(
|
|
29
|
+
default=LocalKafkaAccessConfig(), validate_default=True
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
def get_consumer_configuration(self) -> dict:
|
|
33
|
+
bootstrap = self.bootstrap_server
|
|
34
|
+
port = self.port
|
|
35
|
+
|
|
36
|
+
conf = {
|
|
37
|
+
"bootstrap.servers": f"{bootstrap}:{port}",
|
|
38
|
+
"client.id": socket.gethostname(),
|
|
39
|
+
"group.id": "default_group_id",
|
|
40
|
+
"enable.auto.commit": "false",
|
|
41
|
+
"auto.offset.reset": "earliest",
|
|
42
|
+
"message.max.bytes": 10485760,
|
|
43
|
+
}
|
|
44
|
+
return conf
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class LocalKafkaIndexerConfig(KafkaIndexerConfig):
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass
|
|
52
|
+
class LocalKafkaIndexer(KafkaIndexer):
|
|
53
|
+
connection_config: LocalKafkaConnectionConfig
|
|
54
|
+
index_config: LocalKafkaIndexerConfig
|
|
55
|
+
connector_type: str = CONNECTOR_TYPE
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class LocalKafkaDownloaderConfig(KafkaDownloaderConfig):
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass
|
|
63
|
+
class LocalKafkaDownloader(KafkaDownloader):
|
|
64
|
+
connection_config: LocalKafkaConnectionConfig
|
|
65
|
+
download_config: LocalKafkaDownloaderConfig
|
|
66
|
+
connector_type: str = CONNECTOR_TYPE
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
kafka_local_source_entry = SourceRegistryEntry(
|
|
70
|
+
connection_config=LocalKafkaConnectionConfig,
|
|
71
|
+
indexer=LocalKafkaIndexer,
|
|
72
|
+
indexer_config=LocalKafkaIndexerConfig,
|
|
73
|
+
downloader=LocalKafkaDownloader,
|
|
74
|
+
downloader_config=LocalKafkaDownloaderConfig,
|
|
75
|
+
)
|
|
@@ -9,7 +9,11 @@ from typing import TYPE_CHECKING, Any, Generator, Optional
|
|
|
9
9
|
from dateutil import parser
|
|
10
10
|
from pydantic import Field, Secret
|
|
11
11
|
|
|
12
|
-
from unstructured_ingest.error import
|
|
12
|
+
from unstructured_ingest.error import (
|
|
13
|
+
DestinationConnectionError,
|
|
14
|
+
SourceConnectionError,
|
|
15
|
+
SourceConnectionNetworkError,
|
|
16
|
+
)
|
|
13
17
|
from unstructured_ingest.utils.dep_check import requires_dependencies
|
|
14
18
|
from unstructured_ingest.v2.interfaces import (
|
|
15
19
|
AccessConfig,
|
|
@@ -22,16 +26,20 @@ from unstructured_ingest.v2.interfaces import (
|
|
|
22
26
|
Indexer,
|
|
23
27
|
IndexerConfig,
|
|
24
28
|
SourceIdentifiers,
|
|
29
|
+
Uploader,
|
|
30
|
+
UploaderConfig,
|
|
25
31
|
download_responses,
|
|
26
32
|
)
|
|
27
33
|
from unstructured_ingest.v2.logger import logger
|
|
28
34
|
from unstructured_ingest.v2.processes.connector_registry import (
|
|
35
|
+
DestinationRegistryEntry,
|
|
29
36
|
SourceRegistryEntry,
|
|
30
37
|
)
|
|
31
38
|
|
|
32
39
|
if TYPE_CHECKING:
|
|
33
40
|
from office365.graph_client import GraphClient
|
|
34
41
|
from office365.onedrive.driveitems.driveItem import DriveItem
|
|
42
|
+
from office365.onedrive.drives.drive import Drive
|
|
35
43
|
|
|
36
44
|
CONNECTOR_TYPE = "onedrive"
|
|
37
45
|
MAX_MB_SIZE = 512_000_000
|
|
@@ -55,6 +63,11 @@ class OnedriveConnectionConfig(ConnectionConfig):
|
|
|
55
63
|
)
|
|
56
64
|
access_config: Secret[OnedriveAccessConfig]
|
|
57
65
|
|
|
66
|
+
def get_drive(self) -> "Drive":
|
|
67
|
+
client = self.get_client()
|
|
68
|
+
drive = client.users[self.user_pname].drive
|
|
69
|
+
return drive
|
|
70
|
+
|
|
58
71
|
@requires_dependencies(["msal"], extras="onedrive")
|
|
59
72
|
def get_token(self):
|
|
60
73
|
from msal import ConfidentialClientApplication
|
|
@@ -100,7 +113,6 @@ class OnedriveIndexer(Indexer):
|
|
|
100
113
|
raise SourceConnectionError(
|
|
101
114
|
"{} ({})".format(error, token_resp.get("error_description"))
|
|
102
115
|
)
|
|
103
|
-
self.connection_config.get_client()
|
|
104
116
|
except Exception as e:
|
|
105
117
|
logger.error(f"failed to validate connection: {e}", exc_info=True)
|
|
106
118
|
raise SourceConnectionError(f"failed to validate connection: {e}")
|
|
@@ -224,6 +236,149 @@ class OnedriveDownloader(Downloader):
|
|
|
224
236
|
return DownloadResponse(file_data=file_data, path=download_path)
|
|
225
237
|
|
|
226
238
|
|
|
239
|
+
class OnedriveUploaderConfig(UploaderConfig):
|
|
240
|
+
remote_url: str = Field(
|
|
241
|
+
description="URL of the destination in OneDrive, e.g., 'onedrive://Documents/Folder'"
|
|
242
|
+
)
|
|
243
|
+
prefix: str = "onedrive://"
|
|
244
|
+
|
|
245
|
+
@property
|
|
246
|
+
def root_folder(self) -> str:
|
|
247
|
+
url = (
|
|
248
|
+
self.remote_url.replace(self.prefix, "", 1)
|
|
249
|
+
if self.remote_url.startswith(self.prefix)
|
|
250
|
+
else self.remote_url
|
|
251
|
+
)
|
|
252
|
+
return url.split("/")[0]
|
|
253
|
+
|
|
254
|
+
@property
|
|
255
|
+
def url(self) -> str:
|
|
256
|
+
url = (
|
|
257
|
+
self.remote_url.replace(self.prefix, "", 1)
|
|
258
|
+
if self.remote_url.startswith(self.prefix)
|
|
259
|
+
else self.remote_url
|
|
260
|
+
)
|
|
261
|
+
return url
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
@dataclass
|
|
265
|
+
class OnedriveUploader(Uploader):
|
|
266
|
+
connection_config: OnedriveConnectionConfig
|
|
267
|
+
upload_config: OnedriveUploaderConfig
|
|
268
|
+
connector_type: str = CONNECTOR_TYPE
|
|
269
|
+
|
|
270
|
+
@requires_dependencies(["office365"], extras="onedrive")
|
|
271
|
+
def precheck(self) -> None:
|
|
272
|
+
from office365.runtime.client_request_exception import ClientRequestException
|
|
273
|
+
|
|
274
|
+
try:
|
|
275
|
+
token_resp: dict = self.connection_config.get_token()
|
|
276
|
+
if error := token_resp.get("error"):
|
|
277
|
+
raise SourceConnectionError(
|
|
278
|
+
"{} ({})".format(error, token_resp.get("error_description"))
|
|
279
|
+
)
|
|
280
|
+
drive = self.connection_config.get_drive()
|
|
281
|
+
root = drive.root
|
|
282
|
+
root_folder = self.upload_config.root_folder
|
|
283
|
+
folder = root.get_by_path(root_folder)
|
|
284
|
+
try:
|
|
285
|
+
folder.get().execute_query()
|
|
286
|
+
except ClientRequestException as e:
|
|
287
|
+
if e.message != "The resource could not be found.":
|
|
288
|
+
raise e
|
|
289
|
+
folder = root.create_folder(root_folder).execute_query()
|
|
290
|
+
logger.info(f"successfully created folder: {folder.name}")
|
|
291
|
+
except Exception as e:
|
|
292
|
+
logger.error(f"failed to validate connection: {e}", exc_info=True)
|
|
293
|
+
raise SourceConnectionError(f"failed to validate connection: {e}")
|
|
294
|
+
|
|
295
|
+
def run(self, path: Path, file_data: FileData, **kwargs: Any) -> None:
|
|
296
|
+
drive = self.connection_config.get_drive()
|
|
297
|
+
|
|
298
|
+
# Use the remote_url from upload_config as the base destination folder
|
|
299
|
+
base_destination_folder = self.upload_config.url
|
|
300
|
+
|
|
301
|
+
# Use the file's relative path to maintain directory structure, if needed
|
|
302
|
+
if file_data.source_identifiers and file_data.source_identifiers.rel_path:
|
|
303
|
+
# Combine the base destination folder with the file's relative path
|
|
304
|
+
destination_path = Path(base_destination_folder) / Path(
|
|
305
|
+
file_data.source_identifiers.rel_path
|
|
306
|
+
)
|
|
307
|
+
else:
|
|
308
|
+
# If no relative path is provided, upload directly to the base destination folder
|
|
309
|
+
destination_path = Path(base_destination_folder) / path.name
|
|
310
|
+
|
|
311
|
+
destination_folder = destination_path.parent
|
|
312
|
+
file_name = destination_path.name
|
|
313
|
+
|
|
314
|
+
# Convert destination folder to a string suitable for OneDrive API
|
|
315
|
+
destination_folder_str = str(destination_folder).replace("\\", "/")
|
|
316
|
+
|
|
317
|
+
# Resolve the destination folder in OneDrive, creating it if necessary
|
|
318
|
+
try:
|
|
319
|
+
# Attempt to get the folder
|
|
320
|
+
folder = drive.root.get_by_path(destination_folder_str)
|
|
321
|
+
folder.get().execute_query()
|
|
322
|
+
except Exception:
|
|
323
|
+
# Folder doesn't exist, create it recursively
|
|
324
|
+
current_folder = drive.root
|
|
325
|
+
for part in destination_folder.parts:
|
|
326
|
+
# Use filter to find the folder by name
|
|
327
|
+
folders = (
|
|
328
|
+
current_folder.children.filter(f"name eq '{part}' and folder ne null")
|
|
329
|
+
.get()
|
|
330
|
+
.execute_query()
|
|
331
|
+
)
|
|
332
|
+
if folders:
|
|
333
|
+
current_folder = folders[0]
|
|
334
|
+
else:
|
|
335
|
+
# Folder doesn't exist, create it
|
|
336
|
+
current_folder = current_folder.create_folder(part).execute_query()
|
|
337
|
+
folder = current_folder
|
|
338
|
+
|
|
339
|
+
# Check the size of the file
|
|
340
|
+
file_size = path.stat().st_size
|
|
341
|
+
|
|
342
|
+
if file_size < MAX_MB_SIZE:
|
|
343
|
+
# Use simple upload for small files
|
|
344
|
+
with path.open("rb") as local_file:
|
|
345
|
+
content = local_file.read()
|
|
346
|
+
logger.info(f"Uploading {path} to {destination_path} using simple upload")
|
|
347
|
+
try:
|
|
348
|
+
uploaded_file = folder.upload(file_name, content).execute_query()
|
|
349
|
+
if not uploaded_file or uploaded_file.name != file_name:
|
|
350
|
+
raise DestinationConnectionError(f"Upload failed for file '{file_name}'")
|
|
351
|
+
# Log details about the uploaded file
|
|
352
|
+
logger.info(
|
|
353
|
+
f"Uploaded file '{uploaded_file.name}' with ID '{uploaded_file.id}'"
|
|
354
|
+
)
|
|
355
|
+
except Exception as e:
|
|
356
|
+
logger.error(f"Failed to upload file '{file_name}': {e}", exc_info=True)
|
|
357
|
+
raise DestinationConnectionError(
|
|
358
|
+
f"Failed to upload file '{file_name}': {e}"
|
|
359
|
+
) from e
|
|
360
|
+
else:
|
|
361
|
+
# Use resumable upload for large files
|
|
362
|
+
destination_fullpath = f"{destination_folder_str}/{file_name}"
|
|
363
|
+
destination_drive_item = drive.root.item_with_path(destination_fullpath)
|
|
364
|
+
|
|
365
|
+
logger.info(f"Uploading {path} to {destination_fullpath} using resumable upload")
|
|
366
|
+
try:
|
|
367
|
+
uploaded_file = destination_drive_item.resumable_upload(
|
|
368
|
+
source_path=str(path)
|
|
369
|
+
).execute_query()
|
|
370
|
+
# Validate the upload
|
|
371
|
+
if not uploaded_file or uploaded_file.name != file_name:
|
|
372
|
+
raise DestinationConnectionError(f"Upload failed for file '{file_name}'")
|
|
373
|
+
# Log details about the uploaded file
|
|
374
|
+
logger.info(f"Uploaded file {uploaded_file.name} with ID {uploaded_file.id}")
|
|
375
|
+
except Exception as e:
|
|
376
|
+
logger.error(f"Failed to upload file '{file_name}' using resumable upload: {e}")
|
|
377
|
+
raise DestinationConnectionError(
|
|
378
|
+
f"Failed to upload file '{file_name}' using resumable upload: {e}"
|
|
379
|
+
) from e
|
|
380
|
+
|
|
381
|
+
|
|
227
382
|
onedrive_source_entry = SourceRegistryEntry(
|
|
228
383
|
connection_config=OnedriveConnectionConfig,
|
|
229
384
|
indexer_config=OnedriveIndexerConfig,
|
|
@@ -231,3 +386,9 @@ onedrive_source_entry = SourceRegistryEntry(
|
|
|
231
386
|
downloader_config=OnedriveDownloaderConfig,
|
|
232
387
|
downloader=OnedriveDownloader,
|
|
233
388
|
)
|
|
389
|
+
|
|
390
|
+
onedrive_destination_entry = DestinationRegistryEntry(
|
|
391
|
+
connection_config=OnedriveConnectionConfig,
|
|
392
|
+
uploader=OnedriveUploader,
|
|
393
|
+
uploader_config=OnedriveUploaderConfig,
|
|
394
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from unstructured_ingest.v2.processes.connector_registry import (
|
|
4
|
+
add_destination_entry,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
from .cloud import CONNECTOR_TYPE as CLOUD_CONNECTOR_TYPE
|
|
8
|
+
from .cloud import qdrant_cloud_destination_entry
|
|
9
|
+
from .local import CONNECTOR_TYPE as LOCAL_CONNECTOR_TYPE
|
|
10
|
+
from .local import qdrant_local_destination_entry
|
|
11
|
+
from .server import CONNECTOR_TYPE as SERVER_CONNECTOR_TYPE
|
|
12
|
+
from .server import qdrant_server_destination_entry
|
|
13
|
+
|
|
14
|
+
add_destination_entry(destination_type=CLOUD_CONNECTOR_TYPE, entry=qdrant_cloud_destination_entry)
|
|
15
|
+
add_destination_entry(destination_type=SERVER_CONNECTOR_TYPE, entry=qdrant_server_destination_entry)
|
|
16
|
+
add_destination_entry(destination_type=LOCAL_CONNECTOR_TYPE, entry=qdrant_local_destination_entry)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from pydantic import Field, Secret
|
|
4
|
+
|
|
5
|
+
from unstructured_ingest.v2.processes.connector_registry import DestinationRegistryEntry
|
|
6
|
+
from unstructured_ingest.v2.processes.connectors.qdrant.qdrant import (
|
|
7
|
+
QdrantAccessConfig,
|
|
8
|
+
QdrantConnectionConfig,
|
|
9
|
+
QdrantUploader,
|
|
10
|
+
QdrantUploaderConfig,
|
|
11
|
+
QdrantUploadStager,
|
|
12
|
+
QdrantUploadStagerConfig,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
CONNECTOR_TYPE = "qdrant-cloud"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CloudQdrantAccessConfig(QdrantAccessConfig):
|
|
19
|
+
api_key: str = Field(description="Qdrant API key")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class CloudQdrantConnectionConfig(QdrantConnectionConfig):
|
|
23
|
+
url: str = Field(default=None, description="url of Qdrant Cloud")
|
|
24
|
+
access_config: Secret[CloudQdrantAccessConfig]
|
|
25
|
+
|
|
26
|
+
def get_client_kwargs(self) -> dict:
|
|
27
|
+
return {
|
|
28
|
+
"api_key": self.access_config.get_secret_value().api_key,
|
|
29
|
+
"url": self.url,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CloudQdrantUploadStagerConfig(QdrantUploadStagerConfig):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class CloudQdrantUploadStager(QdrantUploadStager):
|
|
39
|
+
upload_stager_config: CloudQdrantUploadStagerConfig
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class CloudQdrantUploaderConfig(QdrantUploaderConfig):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class CloudQdrantUploader(QdrantUploader):
|
|
48
|
+
connection_config: CloudQdrantConnectionConfig
|
|
49
|
+
upload_config: CloudQdrantUploaderConfig
|
|
50
|
+
connector_type: str = CONNECTOR_TYPE
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
qdrant_cloud_destination_entry = DestinationRegistryEntry(
|
|
54
|
+
connection_config=CloudQdrantConnectionConfig,
|
|
55
|
+
uploader=CloudQdrantUploader,
|
|
56
|
+
uploader_config=CloudQdrantUploaderConfig,
|
|
57
|
+
upload_stager=CloudQdrantUploadStager,
|
|
58
|
+
upload_stager_config=CloudQdrantUploadStagerConfig,
|
|
59
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from pydantic import Field, Secret
|
|
4
|
+
|
|
5
|
+
from unstructured_ingest.v2.processes.connector_registry import DestinationRegistryEntry
|
|
6
|
+
from unstructured_ingest.v2.processes.connectors.qdrant.qdrant import (
|
|
7
|
+
QdrantAccessConfig,
|
|
8
|
+
QdrantConnectionConfig,
|
|
9
|
+
QdrantUploader,
|
|
10
|
+
QdrantUploaderConfig,
|
|
11
|
+
QdrantUploadStager,
|
|
12
|
+
QdrantUploadStagerConfig,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
CONNECTOR_TYPE = "qdrant-local"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class LocalQdrantAccessConfig(QdrantAccessConfig):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class LocalQdrantConnectionConfig(QdrantConnectionConfig):
|
|
23
|
+
path: str = Field(default=None, description="Persistence path for QdrantLocal.")
|
|
24
|
+
access_config: Secret[LocalQdrantAccessConfig] = Field(
|
|
25
|
+
default_factory=LocalQdrantAccessConfig, validate_default=True
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def get_client_kwargs(self) -> dict:
|
|
29
|
+
return {"path": self.path}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class LocalQdrantUploadStagerConfig(QdrantUploadStagerConfig):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class LocalQdrantUploadStager(QdrantUploadStager):
|
|
38
|
+
upload_stager_config: LocalQdrantUploadStagerConfig
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class LocalQdrantUploaderConfig(QdrantUploaderConfig):
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class LocalQdrantUploader(QdrantUploader):
|
|
47
|
+
connection_config: LocalQdrantConnectionConfig
|
|
48
|
+
upload_config: LocalQdrantUploaderConfig
|
|
49
|
+
connector_type: str = CONNECTOR_TYPE
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
qdrant_local_destination_entry = DestinationRegistryEntry(
|
|
53
|
+
connection_config=LocalQdrantConnectionConfig,
|
|
54
|
+
uploader=LocalQdrantUploader,
|
|
55
|
+
uploader_config=LocalQdrantUploaderConfig,
|
|
56
|
+
upload_stager=LocalQdrantUploadStager,
|
|
57
|
+
upload_stager_config=LocalQdrantUploadStagerConfig,
|
|
58
|
+
)
|