Skip to content

Commit 030c22e

Browse files
committed
📝 update docs for RAG search
1 parent 68ceaa0 commit 030c22e

8 files changed

Lines changed: 71 additions & 51 deletions

File tree

docs/client_mixin.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

mindee/client_mixin.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

mindee/client_options/polling_options.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from mindee.error import MindeeClientError
2+
3+
14
class PollingOptions:
25
"""Options for asynchronous polling."""
36

@@ -17,3 +20,20 @@ def __init__(
1720
self.initial_delay_sec = initial_delay_sec
1821
self.delay_sec = delay_sec
1922
self.max_retries = max_retries
23+
24+
def validate_settings(self) -> None:
25+
"""Validates polling options against minimum accepted values."""
26+
27+
min_delay = 1
28+
min_initial_delay = 1
29+
min_retries = 1
30+
if self.delay_sec < min_delay:
31+
raise MindeeClientError(
32+
f"Cannot set auto-parsing delay to less than {min_delay} second(s)."
33+
)
34+
if self.initial_delay_sec < min_initial_delay:
35+
raise MindeeClientError(
36+
f"Cannot set initial parsing delay to less than {min_initial_delay} second(s)."
37+
)
38+
if self.max_retries < min_retries:
39+
raise MindeeClientError(f"Cannot set retries to less than {min_retries}.")

mindee/v1/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import httpx
44

5-
from mindee.client_mixin import ClientMixin
5+
from mindee.client_options.polling_options import PollingOptions
66
from mindee.error.mindee_error import MindeeClientError, MindeeError
77
from mindee.error.mindee_http_error import handle_error
88
from mindee.input.local_input_source import LocalInputSource
@@ -53,7 +53,7 @@ def _clean_account_name(account_name: str) -> str:
5353
return account_name
5454

5555

56-
class Client(ClientMixin):
56+
class Client:
5757
"""
5858
Mindee API Client.
5959
@@ -353,7 +353,11 @@ def enqueue_and_parse( # pylint: disable=too-many-locals
353353
:param rag: If set, will enable Retrieval-Augmented Generation.
354354
Only works if a valid ``workflow_id`` is set.
355355
"""
356-
self._validate_async_params(initial_delay_sec, delay_sec, max_retries)
356+
PollingOptions(
357+
initial_delay_sec=initial_delay_sec,
358+
delay_sec=delay_sec,
359+
max_retries=max_retries,
360+
).validate_settings()
357361
if not endpoint:
358362
endpoint = self._initialize_ots_endpoint(product_class=product_class)
359363
queue_result = self.enqueue(

mindee/v2/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import httpx
66

7-
from mindee.client_mixin import ClientMixin
87
from mindee.client_options.polling_options import PollingOptions
98
from mindee.error.mindee_error import MindeeError
109
from mindee.input import URLInputSource
@@ -27,7 +26,7 @@
2726
)
2827

2928

30-
class Client(ClientMixin):
29+
class Client:
3130
"""
3231
Mindee API Client.
3332
@@ -127,11 +126,7 @@ def enqueue_and_get_result(
127126
"""
128127
if not params.polling_options:
129128
params.polling_options = PollingOptions()
130-
self._validate_async_params(
131-
params.polling_options.initial_delay_sec,
132-
params.polling_options.delay_sec,
133-
params.polling_options.max_retries,
134-
)
129+
params.polling_options.validate_settings()
135130
enqueue_response = self.enqueue(input_source, params)
136131
logger.debug(
137132
"Successfully enqueued document with job ID: %s", enqueue_response.job.id

mindee/v2/search/rag_documents/rag_document_search_parameters.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99

1010
@dataclass(kw_only=True)
1111
class RagDocumentSearchParameters(BaseSearchParameters[RagDocumentSearchResponse]):
12-
"""Search parameters for RAG Documents."""
12+
"""
13+
Search for RAG documents within the organization linked to the API key.
14+
15+
The model ID is required, search filters are optional.
16+
If no search filters are given, all documents linked to the model are returned.
17+
18+
Results are paginated.
19+
"""
1320

1421
model_id: str
15-
"""Model identifier to search in."""
22+
"""The exact Model UUID the document is linked to."""
1623

1724
filename: str | None = None
18-
"""Case-insensitive substring search on filename."""
25+
"""Filter documents by partial filename match, case-insensitive."""
1926

2027
_slug: ClassVar[str] = "rag-documents"
2128
_response_class: type[RagDocumentSearchResponse] = RagDocumentSearchResponse

tests/v2/search/test_model_search_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def v2_client() -> Client:
1111

1212
@pytest.mark.integration
1313
@pytest.mark.v2
14-
def test_must_have_results(v2_client: Client):
14+
def test_search_must_have_results(v2_client: Client):
1515
response = v2_client.search(ModelSearchParameters())
1616

1717
assert response is not None
@@ -27,7 +27,7 @@ def test_must_have_results(v2_client: Client):
2727

2828
@pytest.mark.integration
2929
@pytest.mark.v2
30-
def test_must_return_empty(v2_client: Client):
30+
def test_search_must_return_empty(v2_client: Client):
3131
response = v2_client.search(ModelSearchParameters(name="je n'existe pas tralala"))
3232

3333
assert response is not None

tests/v2/search/test_rag_document_search_integration.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,49 @@
33
import pytest
44

55
from mindee.v2.client import Client
6-
from mindee.v2.search.rag_documents.rag_document_search_parameters import (
7-
RagDocumentSearchParameters,
8-
)
6+
from mindee.v2.search.rag_documents import RagDocumentSearchParameters
97

108

119
@pytest.fixture(scope="session")
1210
def v2_client() -> Client:
1311
return Client()
1412

1513

16-
@pytest.mark.integration
17-
@pytest.mark.v2
18-
def test_must_have_results(v2_client: Client):
14+
@pytest.fixture(scope="session")
15+
def findoc_model_id() -> str:
1916
findoc_model_id = os.getenv("MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID")
2017
assert findoc_model_id, "MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID must be set"
18+
return findoc_model_id
19+
20+
21+
@pytest.mark.integration
22+
@pytest.mark.v2
23+
def test_search_must_have_results(v2_client: Client, findoc_model_id: str):
2124
response = v2_client.search(RagDocumentSearchParameters(model_id=findoc_model_id))
2225

2326
assert response is not None
2427
assert len(response.rag_documents) > 0
28+
for rag_doc in response.rag_documents:
29+
assert rag_doc.id
30+
assert rag_doc.created_at
31+
assert rag_doc.filename
32+
assert rag_doc.total_matches >= 0
2533
assert response.pagination is not None
2634
assert response.pagination.total_items >= 1
2735
assert response.pagination.page == 1
36+
37+
38+
@pytest.mark.integration
39+
@pytest.mark.v2
40+
def test_search_must_return_empty(v2_client: Client, findoc_model_id: str):
41+
response = v2_client.search(
42+
RagDocumentSearchParameters(
43+
model_id=findoc_model_id, filename="invoice_32GB-RAM_450k-USD.pdf"
44+
)
45+
)
46+
47+
assert response is not None
48+
assert len(response.rag_documents) == 0
49+
assert response.pagination is not None
50+
assert response.pagination.total_items == 0
51+
assert response.pagination.page == 1

0 commit comments

Comments
 (0)