microsoft-sharepoint-haystack 1.0.0__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.
- haystack_integrations/components/retrievers/microsoft_sharepoint/__init__.py +12 -0
- haystack_integrations/components/retrievers/microsoft_sharepoint/errors.py +19 -0
- haystack_integrations/components/retrievers/microsoft_sharepoint/retriever.py +405 -0
- haystack_integrations/components/retrievers/py.typed +0 -0
- microsoft_sharepoint_haystack-1.0.0.dist-info/METADATA +33 -0
- microsoft_sharepoint_haystack-1.0.0.dist-info/RECORD +8 -0
- microsoft_sharepoint_haystack-1.0.0.dist-info/WHEEL +4 -0
- microsoft_sharepoint_haystack-1.0.0.dist-info/licenses/LICENSE.txt +201 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from .errors import SharePointConfigError, SharePointError, SharePointRequestError
|
|
5
|
+
from .retriever import MSSharePointRetriever
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"MSSharePointRetriever",
|
|
9
|
+
"SharePointConfigError",
|
|
10
|
+
"SharePointError",
|
|
11
|
+
"SharePointRequestError",
|
|
12
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SharePointError(Exception):
|
|
7
|
+
"""Base class for errors raised by the Microsoft SharePoint integration."""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SharePointConfigError(SharePointError):
|
|
11
|
+
"""Raised when the SharePoint retriever is misconfigured."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SharePointRequestError(SharePointError):
|
|
15
|
+
"""Raised when a Microsoft Graph search request fails."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, message: str, status_code: int | None = None) -> None:
|
|
18
|
+
super().__init__(message)
|
|
19
|
+
self.status_code = status_code
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import html
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
from haystack import Document, component, default_from_dict, default_to_dict, logging
|
|
12
|
+
from haystack.utils import Secret
|
|
13
|
+
from tenacity import AsyncRetrying, RetryCallState, Retrying, retry_if_result, stop_after_attempt, wait_exponential
|
|
14
|
+
|
|
15
|
+
from .errors import SharePointConfigError, SharePointRequestError
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
_DEFAULT_GRAPH_URL = "https://graph.microsoft.com/v1.0"
|
|
20
|
+
_DEFAULT_ENTITY_TYPES = ("driveItem", "listItem")
|
|
21
|
+
# Microsoft Graph caps a single search page at 500 results; larger `top_k` values are paginated.
|
|
22
|
+
_MAX_PAGE_SIZE = 500
|
|
23
|
+
_RETRYABLE_STATUS = frozenset({429, 500, 502, 503, 504})
|
|
24
|
+
# Fallback backoff when a throttled response carries no `Retry-After` header: 1s, 2s, 4s, ...
|
|
25
|
+
_EXPONENTIAL_BACKOFF = wait_exponential()
|
|
26
|
+
|
|
27
|
+
# Search summaries come back as snippets with hit-highlight markup, e.g.
|
|
28
|
+
# "<c0>Contoso</c0> Detailed Design <ddd/>". These patterns turn that into plain text.
|
|
29
|
+
_HIGHLIGHT_PATTERN = re.compile(r"</?c\d+>")
|
|
30
|
+
_ELLIPSIS_PATTERN = re.compile(r"<ddd\s*/>")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _retry_response(retry_state: RetryCallState) -> httpx.Response | None:
|
|
34
|
+
"""Return the `httpx.Response` recorded for a retry attempt, or `None` if the attempt raised."""
|
|
35
|
+
outcome = retry_state.outcome
|
|
36
|
+
if outcome is None or outcome.failed:
|
|
37
|
+
return None
|
|
38
|
+
return outcome.result()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _is_retryable_response(response: httpx.Response) -> bool:
|
|
42
|
+
"""Return whether a Microsoft Graph response should trigger a retry."""
|
|
43
|
+
return response.status_code in _RETRYABLE_STATUS
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _wait_with_retry_after(retry_state: RetryCallState) -> float:
|
|
47
|
+
"""Wait strategy honoring a numeric `Retry-After` header, falling back to exponential backoff."""
|
|
48
|
+
response = _retry_response(retry_state)
|
|
49
|
+
if response is not None:
|
|
50
|
+
retry_after = response.headers.get("Retry-After")
|
|
51
|
+
if retry_after:
|
|
52
|
+
try:
|
|
53
|
+
return float(retry_after)
|
|
54
|
+
except ValueError:
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
return _EXPONENTIAL_BACKOFF(retry_state)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _last_response(retry_state: RetryCallState) -> httpx.Response:
|
|
61
|
+
"""Return the final response once retries are exhausted, so the caller can raise a typed error."""
|
|
62
|
+
response = _retry_response(retry_state)
|
|
63
|
+
if response is None:
|
|
64
|
+
msg = "Microsoft Graph retries were exhausted without a recorded response."
|
|
65
|
+
raise SharePointRequestError(msg)
|
|
66
|
+
return response
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _log_retry(retry_state: RetryCallState) -> None:
|
|
70
|
+
"""Log a warning before sleeping between Microsoft Graph retries."""
|
|
71
|
+
response = _retry_response(retry_state)
|
|
72
|
+
next_action = retry_state.next_action
|
|
73
|
+
if response is None or next_action is None:
|
|
74
|
+
return
|
|
75
|
+
logger.warning(
|
|
76
|
+
"Microsoft Graph returned status {status}; retrying in {delay}s (attempt {attempt}).",
|
|
77
|
+
status=response.status_code,
|
|
78
|
+
delay=next_action.sleep,
|
|
79
|
+
attempt=retry_state.attempt_number,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@component
|
|
84
|
+
class MSSharePointRetriever:
|
|
85
|
+
"""
|
|
86
|
+
Retrieves content from Microsoft SharePoint and OneDrive via the Microsoft Search (Graph) API.
|
|
87
|
+
|
|
88
|
+
Given a query, the retriever calls `POST /search/query` and maps each hit to a Haystack `Document`
|
|
89
|
+
whose `content` is the search snippet and whose `meta` carries the resource metadata (`file_name`,
|
|
90
|
+
`web_url`, `entity_type`, `created_date_time`, `last_modified_date_time`, `created_by`, `last_modified_by`,
|
|
91
|
+
`mime_type`, and `file_extension`). It does not download or convert the underlying files. Compose a
|
|
92
|
+
downstream fetcher/converter on the returned `web_url` when full file content is needed.
|
|
93
|
+
|
|
94
|
+
The retriever takes a per-user `access_token` as a run input, typically wired
|
|
95
|
+
from an upstream `OAuthResolver`. The token must carry delegated Microsoft Graph permissions
|
|
96
|
+
(for example `Files.Read.All` and, for site/list scoping, `Sites.Read.All`). The Search API supports
|
|
97
|
+
delegated permissions only.
|
|
98
|
+
|
|
99
|
+
### Usage example
|
|
100
|
+
```python
|
|
101
|
+
from haystack_integrations.components.retrievers.microsoft_sharepoint import (
|
|
102
|
+
MSSharePointRetriever,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
retriever = MSSharePointRetriever(top_k=5)
|
|
106
|
+
|
|
107
|
+
# `access_token` is a per-user delegated Microsoft Graph bearer token.
|
|
108
|
+
result = retriever.run(
|
|
109
|
+
query="quarterly roadmap", access_token="my-delegated-graph-token"
|
|
110
|
+
)
|
|
111
|
+
documents = result["documents"]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
In a pipeline, connect an upstream component that emits a per-user `access_token` to the retriever's
|
|
115
|
+
`access_token` input. See the integration documentation for a full example that obtains the token from
|
|
116
|
+
an OAuth provider.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
def __init__(
|
|
120
|
+
self,
|
|
121
|
+
*,
|
|
122
|
+
entity_types: list[str] | None = None,
|
|
123
|
+
top_k: int = 10,
|
|
124
|
+
fields: list[str] | None = None,
|
|
125
|
+
query_template: str | None = None,
|
|
126
|
+
graph_url: str = _DEFAULT_GRAPH_URL,
|
|
127
|
+
timeout: float = 30.0,
|
|
128
|
+
max_retries: int = 3,
|
|
129
|
+
) -> None:
|
|
130
|
+
"""
|
|
131
|
+
Initialize the retriever.
|
|
132
|
+
|
|
133
|
+
:param entity_types: The Microsoft Search entity types to query. Defaults to `["driveItem", "listItem"]`,
|
|
134
|
+
which covers files, folders, SharePoint pages and news, and list items. Other valid values are
|
|
135
|
+
`"list"` and `"site"`. See the supported values and combinations in the
|
|
136
|
+
[Microsoft docs](https://learn.microsoft.com/en-us/graph/api/resources/searchrequest).
|
|
137
|
+
:param top_k: The maximum number of documents to return. Maps to the Search API `size` and is paginated
|
|
138
|
+
when it exceeds a single page.
|
|
139
|
+
:param fields: Optional list of resource properties to request via the Search API `fields` selection
|
|
140
|
+
(only honored for `listItem` and `driveItem` entity types). See
|
|
141
|
+
[Get selected properties](https://learn.microsoft.com/en-us/graph/api/resources/search-api-overview#get-selected-properties).
|
|
142
|
+
:param query_template: Optional query template used to scope the search, for example
|
|
143
|
+
`'{searchTerms} path:"https://contoso.sharepoint.com/sites/Team"'`. The literal `{searchTerms}`
|
|
144
|
+
placeholder is replaced by the run-time query. The template uses
|
|
145
|
+
[Keyword Query Language (KQL)](https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference).
|
|
146
|
+
:param graph_url: The Microsoft Graph base URL. Defaults to `https://graph.microsoft.com/v1.0`.
|
|
147
|
+
Override for sovereign clouds.
|
|
148
|
+
:param timeout: The HTTP timeout in seconds for each request to Microsoft Graph.
|
|
149
|
+
:param max_retries: The maximum number of retries for throttled (HTTP 429) or transient server errors.
|
|
150
|
+
:raises SharePointConfigError: If `entity_types` is empty, `top_k` is not positive, or `max_retries` is
|
|
151
|
+
negative.
|
|
152
|
+
"""
|
|
153
|
+
if entity_types is None:
|
|
154
|
+
entity_types = list(_DEFAULT_ENTITY_TYPES)
|
|
155
|
+
else:
|
|
156
|
+
entity_types = list(entity_types)
|
|
157
|
+
if not entity_types:
|
|
158
|
+
msg = "entity_types must contain at least one Microsoft Search entity type."
|
|
159
|
+
raise SharePointConfigError(msg)
|
|
160
|
+
if top_k <= 0:
|
|
161
|
+
msg = "top_k must be a positive integer."
|
|
162
|
+
raise SharePointConfigError(msg)
|
|
163
|
+
if max_retries < 0:
|
|
164
|
+
msg = "max_retries must be zero or a positive integer."
|
|
165
|
+
raise SharePointConfigError(msg)
|
|
166
|
+
|
|
167
|
+
self.entity_types = entity_types
|
|
168
|
+
self.top_k = top_k
|
|
169
|
+
self.fields = fields
|
|
170
|
+
self.query_template = query_template
|
|
171
|
+
self.graph_url = graph_url.rstrip("/")
|
|
172
|
+
self.timeout = timeout
|
|
173
|
+
self.max_retries = max_retries
|
|
174
|
+
|
|
175
|
+
@component.output_types(documents=list[Document])
|
|
176
|
+
def run(self, query: str, access_token: str | Secret, top_k: int | None = None) -> dict[str, list[Document]]:
|
|
177
|
+
"""
|
|
178
|
+
Search SharePoint and OneDrive and return the matching documents.
|
|
179
|
+
|
|
180
|
+
:param query: The search query string. Filter results by embedding Keyword Query Language (KQL)
|
|
181
|
+
operators directly in the query, for example `filetype:docx`, `author:"Jane Doe"`, or
|
|
182
|
+
`path:"https://contoso.sharepoint.com/sites/Team"`. See the
|
|
183
|
+
[KQL syntax reference](https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference).
|
|
184
|
+
:param access_token: A delegated Microsoft Graph bearer token for the user whose content is searched,
|
|
185
|
+
typically wired from an upstream `OAuthResolver` (which emits a plain `str`). A `Secret` is also
|
|
186
|
+
accepted and resolved internally.
|
|
187
|
+
:param top_k: Overrides the `top_k` configured at initialization for this run.
|
|
188
|
+
:returns: A dictionary with a `documents` key holding the list of retrieved `Document` objects.
|
|
189
|
+
:raises SharePointConfigError: If `access_token` is a `Secret` that does not resolve to a string.
|
|
190
|
+
:raises SharePointRequestError: If Microsoft Graph returns an error response.
|
|
191
|
+
"""
|
|
192
|
+
token = self._resolve_access_token(access_token)
|
|
193
|
+
limit = top_k or self.top_k
|
|
194
|
+
documents: list[Document] = []
|
|
195
|
+
offset = 0
|
|
196
|
+
with httpx.Client(timeout=self.timeout) as client:
|
|
197
|
+
while len(documents) < limit:
|
|
198
|
+
size = min(_MAX_PAGE_SIZE, limit - len(documents))
|
|
199
|
+
request_body = self._build_request_body(query, offset, size)
|
|
200
|
+
payload = self._post(client, token, request_body)
|
|
201
|
+
container = self._first_container(payload)
|
|
202
|
+
hits = container.get("hits") or []
|
|
203
|
+
documents.extend(self._hit_to_document(hit) for hit in hits)
|
|
204
|
+
if not hits or not container.get("moreResultsAvailable"):
|
|
205
|
+
break
|
|
206
|
+
offset += len(hits)
|
|
207
|
+
|
|
208
|
+
return {"documents": documents[:limit]}
|
|
209
|
+
|
|
210
|
+
@component.output_types(documents=list[Document])
|
|
211
|
+
async def run_async(
|
|
212
|
+
self, query: str, access_token: str | Secret, top_k: int | None = None
|
|
213
|
+
) -> dict[str, list[Document]]:
|
|
214
|
+
"""
|
|
215
|
+
Asynchronously search SharePoint and OneDrive and return the matching documents.
|
|
216
|
+
|
|
217
|
+
:param query: The search query string. Filter results by embedding Keyword Query Language (KQL)
|
|
218
|
+
operators directly in the query, for example `filetype:docx`, `author:"Jane Doe"`, or
|
|
219
|
+
`path:"https://contoso.sharepoint.com/sites/Team"`. See the
|
|
220
|
+
[KQL syntax reference](https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference).
|
|
221
|
+
:param access_token: A delegated Microsoft Graph bearer token for the user whose content is searched,
|
|
222
|
+
typically wired from an upstream `OAuthResolver` (which emits a plain `str`). A `Secret` is also
|
|
223
|
+
accepted and resolved internally.
|
|
224
|
+
:param top_k: Overrides the `top_k` configured at initialization for this run.
|
|
225
|
+
:returns: A dictionary with a `documents` key holding the list of retrieved `Document` objects.
|
|
226
|
+
:raises SharePointConfigError: If `access_token` is a `Secret` that does not resolve to a string.
|
|
227
|
+
:raises SharePointRequestError: If Microsoft Graph returns an error response.
|
|
228
|
+
"""
|
|
229
|
+
token = self._resolve_access_token(access_token)
|
|
230
|
+
limit = top_k or self.top_k
|
|
231
|
+
documents: list[Document] = []
|
|
232
|
+
offset = 0
|
|
233
|
+
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
|
234
|
+
while len(documents) < limit:
|
|
235
|
+
size = min(_MAX_PAGE_SIZE, limit - len(documents))
|
|
236
|
+
request_body = self._build_request_body(query, offset, size)
|
|
237
|
+
payload = await self._post_async(client, token, request_body)
|
|
238
|
+
container = self._first_container(payload)
|
|
239
|
+
hits = container.get("hits") or []
|
|
240
|
+
documents.extend(self._hit_to_document(hit) for hit in hits)
|
|
241
|
+
if not hits or not container.get("moreResultsAvailable"):
|
|
242
|
+
break
|
|
243
|
+
offset += len(hits)
|
|
244
|
+
|
|
245
|
+
return {"documents": documents[:limit]}
|
|
246
|
+
|
|
247
|
+
@staticmethod
|
|
248
|
+
def _resolve_access_token(access_token: str | Secret) -> str:
|
|
249
|
+
"""Return the bearer token string, resolving it if a `Secret` was passed."""
|
|
250
|
+
if not isinstance(access_token, Secret):
|
|
251
|
+
return access_token
|
|
252
|
+
resolved = access_token.resolve_value()
|
|
253
|
+
if not isinstance(resolved, str):
|
|
254
|
+
msg = "The access_token Secret did not resolve to a string value."
|
|
255
|
+
raise SharePointConfigError(msg)
|
|
256
|
+
return resolved
|
|
257
|
+
|
|
258
|
+
def _build_request_body(self, query: str, offset: int, size: int) -> dict[str, Any]:
|
|
259
|
+
"""
|
|
260
|
+
Build the Microsoft Search `POST /search/query` request body for one page.
|
|
261
|
+
|
|
262
|
+
See the searchRequest resource for the full set of supported properties:
|
|
263
|
+
https://learn.microsoft.com/en-us/graph/api/resources/searchrequest
|
|
264
|
+
"""
|
|
265
|
+
query_obj: dict[str, Any] = {"queryString": query}
|
|
266
|
+
if self.query_template:
|
|
267
|
+
query_obj["queryTemplate"] = self.query_template
|
|
268
|
+
request: dict[str, Any] = {
|
|
269
|
+
"entityTypes": self.entity_types,
|
|
270
|
+
"query": query_obj,
|
|
271
|
+
"from": offset,
|
|
272
|
+
"size": size,
|
|
273
|
+
}
|
|
274
|
+
if self.fields:
|
|
275
|
+
request["fields"] = self.fields
|
|
276
|
+
|
|
277
|
+
return {"requests": [request]}
|
|
278
|
+
|
|
279
|
+
@staticmethod
|
|
280
|
+
def _first_container(payload: dict[str, Any]) -> dict[str, Any]:
|
|
281
|
+
"""Return the first hitsContainer from a Microsoft Search response, or an empty dict."""
|
|
282
|
+
value = payload.get("value") or []
|
|
283
|
+
if not value:
|
|
284
|
+
return {}
|
|
285
|
+
containers = value[0].get("hitsContainers") or []
|
|
286
|
+
|
|
287
|
+
return containers[0] if containers else {}
|
|
288
|
+
|
|
289
|
+
def _post(self, client: httpx.Client, access_token: str, body: dict[str, Any]) -> dict[str, Any]:
|
|
290
|
+
"""Send a search request, retrying on throttling/transient errors, and return the parsed JSON."""
|
|
291
|
+
url = f"{self.graph_url}/search/query"
|
|
292
|
+
headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"}
|
|
293
|
+
retrying = Retrying(
|
|
294
|
+
stop=stop_after_attempt(self.max_retries + 1),
|
|
295
|
+
wait=_wait_with_retry_after,
|
|
296
|
+
retry=retry_if_result(_is_retryable_response),
|
|
297
|
+
before_sleep=_log_retry,
|
|
298
|
+
retry_error_callback=_last_response,
|
|
299
|
+
)
|
|
300
|
+
response: httpx.Response = retrying(client.post, url, headers=headers, json=body)
|
|
301
|
+
|
|
302
|
+
return self._parse_response(response)
|
|
303
|
+
|
|
304
|
+
async def _post_async(self, client: httpx.AsyncClient, access_token: str, body: dict[str, Any]) -> dict[str, Any]:
|
|
305
|
+
"""Async variant of `_post`."""
|
|
306
|
+
url = f"{self.graph_url}/search/query"
|
|
307
|
+
headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"}
|
|
308
|
+
retrying = AsyncRetrying(
|
|
309
|
+
stop=stop_after_attempt(self.max_retries + 1),
|
|
310
|
+
wait=_wait_with_retry_after,
|
|
311
|
+
retry=retry_if_result(_is_retryable_response),
|
|
312
|
+
before_sleep=_log_retry,
|
|
313
|
+
retry_error_callback=_last_response,
|
|
314
|
+
)
|
|
315
|
+
response: httpx.Response = await retrying(client.post, url, headers=headers, json=body)
|
|
316
|
+
|
|
317
|
+
return self._parse_response(response)
|
|
318
|
+
|
|
319
|
+
@staticmethod
|
|
320
|
+
def _parse_response(response: httpx.Response) -> dict[str, Any]:
|
|
321
|
+
"""Return the parsed JSON for a successful response, or raise a descriptive error."""
|
|
322
|
+
if not response.is_error:
|
|
323
|
+
return response.json()
|
|
324
|
+
|
|
325
|
+
status = response.status_code
|
|
326
|
+
if status == httpx.codes.UNAUTHORIZED:
|
|
327
|
+
msg = (
|
|
328
|
+
"Microsoft Graph rejected the access token (401 Unauthorized). The token may be expired, invalid, "
|
|
329
|
+
"or missing the required delegated scopes (for example Files.Read.All / Sites.Read.All)."
|
|
330
|
+
)
|
|
331
|
+
elif status == httpx.codes.FORBIDDEN:
|
|
332
|
+
msg = f"Microsoft Graph denied the search request (403 Forbidden): {response.text}"
|
|
333
|
+
else:
|
|
334
|
+
msg = f"Microsoft Graph search request failed with status {status}: {response.text}"
|
|
335
|
+
|
|
336
|
+
raise SharePointRequestError(msg, status_code=status)
|
|
337
|
+
|
|
338
|
+
@staticmethod
|
|
339
|
+
def _clean_summary(summary: str) -> str:
|
|
340
|
+
"""Strip Microsoft Search hit-highlight markup from a result summary and unescape entities."""
|
|
341
|
+
if not summary:
|
|
342
|
+
return ""
|
|
343
|
+
text = _ELLIPSIS_PATTERN.sub("…", summary)
|
|
344
|
+
text = _HIGHLIGHT_PATTERN.sub("", text)
|
|
345
|
+
return html.unescape(text).strip()
|
|
346
|
+
|
|
347
|
+
@staticmethod
|
|
348
|
+
def _display_name(identity: dict[str, Any] | None) -> str | None:
|
|
349
|
+
"""Extract the user display name from a Microsoft Graph identitySet, if present."""
|
|
350
|
+
if not identity:
|
|
351
|
+
return None
|
|
352
|
+
user = identity.get("user") or {}
|
|
353
|
+
return user.get("displayName")
|
|
354
|
+
|
|
355
|
+
@staticmethod
|
|
356
|
+
def _hit_to_document(hit: dict[str, Any]) -> Document:
|
|
357
|
+
"""Map a single Microsoft Search hit to a Haystack Document (snippet content + resource metadata)."""
|
|
358
|
+
resource = hit.get("resource") or {}
|
|
359
|
+
|
|
360
|
+
name = resource.get("name") or resource.get("displayName")
|
|
361
|
+
content = MSSharePointRetriever._clean_summary(hit.get("summary", "")) or name or ""
|
|
362
|
+
|
|
363
|
+
file_facet = resource.get("file") or {}
|
|
364
|
+
# Microsoft Graph has no dedicated file-extension field, so derive it from the name.
|
|
365
|
+
extension = os.path.splitext(name or "")[1].lstrip(".").lower()
|
|
366
|
+
|
|
367
|
+
meta = {
|
|
368
|
+
"file_name": name,
|
|
369
|
+
"web_url": resource.get("webUrl"),
|
|
370
|
+
"entity_type": resource.get("@odata.type"),
|
|
371
|
+
"created_date_time": resource.get("createdDateTime"),
|
|
372
|
+
"last_modified_date_time": resource.get("lastModifiedDateTime"),
|
|
373
|
+
"created_by": MSSharePointRetriever._display_name(resource.get("createdBy")),
|
|
374
|
+
"last_modified_by": MSSharePointRetriever._display_name(resource.get("lastModifiedBy")),
|
|
375
|
+
"mime_type": file_facet.get("mimeType"),
|
|
376
|
+
"file_extension": extension or None,
|
|
377
|
+
}
|
|
378
|
+
return Document(content=content, meta={key: value for key, value in meta.items() if value is not None})
|
|
379
|
+
|
|
380
|
+
def to_dict(self) -> dict[str, Any]:
|
|
381
|
+
"""
|
|
382
|
+
Serialize this component to a dictionary.
|
|
383
|
+
|
|
384
|
+
:returns: The serialized component as a dictionary.
|
|
385
|
+
"""
|
|
386
|
+
return default_to_dict(
|
|
387
|
+
self,
|
|
388
|
+
entity_types=self.entity_types,
|
|
389
|
+
top_k=self.top_k,
|
|
390
|
+
fields=self.fields,
|
|
391
|
+
query_template=self.query_template,
|
|
392
|
+
graph_url=self.graph_url,
|
|
393
|
+
timeout=self.timeout,
|
|
394
|
+
max_retries=self.max_retries,
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
@classmethod
|
|
398
|
+
def from_dict(cls, data: dict[str, Any]) -> "MSSharePointRetriever":
|
|
399
|
+
"""
|
|
400
|
+
Deserialize this component from a dictionary.
|
|
401
|
+
|
|
402
|
+
:param data: The dictionary representation of this component.
|
|
403
|
+
:returns: The deserialized component instance.
|
|
404
|
+
"""
|
|
405
|
+
return default_from_dict(cls, data)
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microsoft-sharepoint-haystack
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Haystack integration for microsoft_sharepoint
|
|
5
|
+
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/microsoft_sharepoint#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
7
|
+
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/microsoft_sharepoint
|
|
8
|
+
Author-email: deepset GmbH <info@deepset.ai>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Keywords: haystack,microsoft,retriever,sharepoint
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: haystack-ai
|
|
24
|
+
Requires-Dist: httpx>=0.28.0
|
|
25
|
+
Requires-Dist: tenacity>=8.2.3
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# microsoft-sharepoint-haystack
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/microsoft-sharepoint-haystack)
|
|
31
|
+
[](https://pypi.org/project/microsoft-sharepoint-haystack)
|
|
32
|
+
|
|
33
|
+
- [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/microsoft_sharepoint/CHANGELOG.md)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
haystack_integrations/components/retrievers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
haystack_integrations/components/retrievers/microsoft_sharepoint/__init__.py,sha256=QinvTCH4Z6ehajQTzxfX-DQUfjPAR-9dEXe7F9teNvA,364
|
|
3
|
+
haystack_integrations/components/retrievers/microsoft_sharepoint/errors.py,sha256=9dyJqHug8DhtwCPqTc2ICyq0Xt3rx0et1h8MtAAy3vk,602
|
|
4
|
+
haystack_integrations/components/retrievers/microsoft_sharepoint/retriever.py,sha256=f4PfWkcM2NkL7CWd7uchvDgzP0fe6Ps7KpwCyamzvcw,19078
|
|
5
|
+
microsoft_sharepoint_haystack-1.0.0.dist-info/METADATA,sha256=jLDyrBG6a1y-GQ4dv2Bb-wCKHNPAu6bOXbP_TaNMyzE,1781
|
|
6
|
+
microsoft_sharepoint_haystack-1.0.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
7
|
+
microsoft_sharepoint_haystack-1.0.0.dist-info/licenses/LICENSE.txt,sha256=OrAtTu4aPmrTjKDSTzkSPgo_ji6NOMWO2N9JOTFyAzM,11350
|
|
8
|
+
microsoft_sharepoint_haystack-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023-present deepset GmbH
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|