Skip to content

Commit bf8a8b5

Browse files
committed
✨ add RAG search API
1 parent 1a05ec1 commit bf8a8b5

35 files changed

Lines changed: 645 additions & 368 deletions

mindee/v2/client.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
from mindee.mindee_http.cancellation_token import CancellationToken
1313
from mindee.parsing.common.common_response import CommonStatus
1414
from mindee.v2.client_options.base_product_parameters import BaseProductParameters
15+
from mindee.v2.client_options.base_search_parameters import (
16+
BaseSearchParameters,
17+
TypeSearchResponse,
18+
)
1519
from mindee.v2.mindee_http.mindee_api_v2 import MindeeAPIV2
1620
from mindee.v2.parsing.inference.base_inference_response import BaseInferenceResponse
1721
from mindee.v2.parsing.job.job_response import JobResponse
@@ -57,7 +61,7 @@ def enqueue(
5761
:return: A valid inference response.
5862
"""
5963
logger.debug("Enqueuing inference using model: %s", params.model_id)
60-
return self.mindee_api.enqueue(input_source, params)
64+
return self.mindee_api.req_post_product_enqueue(input_source, params)
6165

6266
def get_job(self, job_id: str) -> JobResponse:
6367
"""
@@ -70,15 +74,15 @@ def get_job(self, job_id: str) -> JobResponse:
7074
"""
7175
logger.debug("Fetching job: %s", job_id)
7276

73-
return self.mindee_api.get_job(job_id)
77+
return self.mindee_api.req_get_job_by_id(job_id)
7478

7579
def get_result(
7680
self,
7781
response_type: type[TypeBaseInferenceResponse],
7882
inference_id: str,
7983
) -> TypeBaseInferenceResponse:
8084
"""
81-
Get the result of an inference that was previously enqueued.
85+
Get the result of an inference that was previously enqueued by its ID.
8286
8387
The inference will only be available after it has finished processing.
8488
@@ -88,7 +92,7 @@ def get_result(
8892
"""
8993
logger.debug("Fetching result: %s", inference_id)
9094

91-
return self.mindee_api.get_result(response_type, inference_id)
95+
return self.mindee_api.req_get_product_result_by_id(response_type, inference_id)
9296

9397
def get_result_from_url(
9498
self, response_type: type[TypeBaseInferenceResponse], url: str
@@ -100,7 +104,7 @@ def get_result_from_url(
100104
:param url: URL of the inference to retrieve.
101105
:return: The result of the inference.
102106
"""
103-
return self.mindee_api.get_result_by_url(response_type, url)
107+
return self.mindee_api.req_get_product_result_by_url(response_type, url)
104108

105109
def enqueue_and_get_result(
106110
self,
@@ -169,6 +173,16 @@ def enqueue_and_get_result(
169173

170174
raise MindeeError(f"Couldn't retrieve document after {try_counter + 1} tries.")
171175

176+
def search(
177+
self, params: BaseSearchParameters[TypeSearchResponse]
178+
) -> TypeSearchResponse:
179+
"""
180+
Search for resources matching the given criteria.
181+
:param params: Search parameters
182+
:return: A search response containing the matching resources
183+
"""
184+
return self.mindee_api.req_search(params)
185+
172186
def search_models(
173187
self, name: str | None = None, model_type: str | None = None
174188
) -> SearchResponse:
@@ -179,7 +193,7 @@ def search_models(
179193
:param model_type: Type of the model to filter by.
180194
:return: A list of models matching the provided criteria.
181195
"""
182-
return self.mindee_api.get_models(name, model_type)
196+
return self.mindee_api.req_get_search_models(name, model_type)
183197

184198
def close(self) -> None:
185199
"""Closes the underlying HTTP client."""

mindee/v2/client_options/base_product_parameters.py

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

88
@dataclass
99
class BaseProductParameters(ABC):
10-
"""Base parameters for sending a document to a product."""
10+
"""Base parameters for sending a file to a Mindee V2 product."""
1111

1212
model_id: str
1313
"""Model ID to use for the inference. Required."""
@@ -32,7 +32,7 @@ class BaseProductParameters(ABC):
3232
"""Whether to close the file after product."""
3333

3434
_slug: ClassVar[str]
35-
"""Slug of the endpoint."""
35+
"""Slug of the product."""
3636

3737
def get_request_parameters(self) -> dict[str, str | list[str]]:
3838
"""
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from abc import ABC
2+
from dataclasses import dataclass
3+
from typing import ClassVar, Generic, TypeVar
4+
5+
from mindee.v2.parsing.search.base_search_response import BaseSearchResponse
6+
7+
TypeSearchResponse = TypeVar("TypeSearchResponse", bound=BaseSearchResponse)
8+
9+
10+
@dataclass(kw_only=True)
11+
class BaseSearchParameters(ABC, Generic[TypeSearchResponse]):
12+
"""Base parameters for searches."""
13+
14+
page: int | None = None
15+
"""1-based page index."""
16+
17+
per_page: int | None = None
18+
"""Number of items per page."""
19+
20+
_slug: ClassVar[str]
21+
"""Slug of the searchable resource."""
22+
23+
_response_class: type[TypeSearchResponse]
24+
"""Response class for the search."""
25+
26+
def get_request_parameters(self) -> dict[str, str | list[str]]:
27+
"""
28+
Gets the request parameters for the search request.
29+
30+
:return: A dict of parameters.
31+
"""
32+
data: dict[str, str | list[str]] = {}
33+
34+
if self.page is not None:
35+
data["page"] = str(self.page)
36+
if self.per_page is not None:
37+
data["per_page"] = str(self.per_page)
38+
39+
return data
40+
41+
def get_slug(self) -> str:
42+
"""Gets the slug of the resource."""
43+
return self._slug
44+
45+
def get_response_class(self) -> type[TypeSearchResponse]:
46+
"""Gets the response class for the search."""
47+
return self._response_class

0 commit comments

Comments
 (0)