deepsights-api 0.2.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.
Files changed (39) hide show
  1. deepsights/__init__.py +23 -0
  2. deepsights/answers/__init__.py +26 -0
  3. deepsights/answers/answer.py +106 -0
  4. deepsights/answers/answer_v1.py +55 -0
  5. deepsights/answers/model.py +107 -0
  6. deepsights/api/__init__.py +22 -0
  7. deepsights/api/api.py +231 -0
  8. deepsights/api/model.py +96 -0
  9. deepsights/api/quota.py +54 -0
  10. deepsights/contentstore/__init__.py +24 -0
  11. deepsights/contentstore/_search.py +229 -0
  12. deepsights/contentstore/model.py +76 -0
  13. deepsights/contentstore/news.py +139 -0
  14. deepsights/contentstore/secondary.py +139 -0
  15. deepsights/documents/__init__.py +44 -0
  16. deepsights/documents/_cache.py +39 -0
  17. deepsights/documents/_segmenter.py +113 -0
  18. deepsights/documents/delete.py +82 -0
  19. deepsights/documents/download.py +63 -0
  20. deepsights/documents/load.py +172 -0
  21. deepsights/documents/model.py +161 -0
  22. deepsights/documents/search.py +182 -0
  23. deepsights/documents/upload.py +130 -0
  24. deepsights/minions/__init__.py +0 -0
  25. deepsights/minions/_minions.py +59 -0
  26. deepsights/reports/__init__.py +24 -0
  27. deepsights/reports/model.py +141 -0
  28. deepsights/reports/report.py +95 -0
  29. deepsights/utils/__init__.py +31 -0
  30. deepsights/utils/_cache.py +63 -0
  31. deepsights/utils/_ranking.py +201 -0
  32. deepsights/utils/_utils.py +45 -0
  33. deepsights/utils/model.py +91 -0
  34. deepsights_api-0.2.0.dist-info/LICENSE +201 -0
  35. deepsights_api-0.2.0.dist-info/METADATA +92 -0
  36. deepsights_api-0.2.0.dist-info/RECORD +39 -0
  37. deepsights_api-0.2.0.dist-info/WHEEL +5 -0
  38. deepsights_api-0.2.0.dist-info/top_level.txt +1 -0
  39. src/deepsights/__init__.py +23 -0
@@ -0,0 +1,54 @@
1
+ # Copyright 2024 Market Logic Software AG. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ This module contains the functions to retrieve quota information from the DeepSights API.
17
+ """
18
+
19
+ from deepsights.api.api import DeepSights
20
+ from deepsights.api.model import APIProfile, QuotaStatus
21
+
22
+
23
+ #################################################
24
+ def api_get_profile(api: DeepSights) -> APIProfile:
25
+ """
26
+ Retrieves the API profile from the DeepSights API.
27
+
28
+ Args:
29
+
30
+ api (ds.DeepSights): The DeepSights API instance.
31
+
32
+ Returns:
33
+
34
+ APIProfile: The parsed API profile.
35
+ """
36
+ response = api.get("/static-resolver/api-key-attributes")
37
+ return APIProfile.model_validate(response)
38
+
39
+
40
+ #################################################
41
+ def quota_get_status(api: DeepSights) -> QuotaStatus:
42
+ """
43
+ Get the quota status from the DeepSights API.
44
+
45
+ Args:
46
+
47
+ api (DeepSights): The DeepSights API object.
48
+
49
+ Returns:
50
+
51
+ QuotaStatus: The validated quota status response.
52
+ """
53
+ response = api.get("/static-resolver/quota")
54
+ return QuotaStatus.model_validate(response)
@@ -0,0 +1,24 @@
1
+ # Copyright 2024 Market Logic Software AG. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ This module contains the functions to retrieve content from the DeepSights API.
17
+ """
18
+
19
+ from deepsights.contentstore.model import (
20
+ NewsSearchResult,
21
+ SecondarySearchResult,
22
+ )
23
+ from deepsights.contentstore.news import news_search
24
+ from deepsights.contentstore.secondary import secondary_search
@@ -0,0 +1,229 @@
1
+ # Copyright 2024 Market Logic Software AG. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ This module contains the base functions to search the ContentStore.
17
+ """
18
+
19
+ from typing import List
20
+ from concurrent.futures import ThreadPoolExecutor
21
+ from pydantic import BaseModel
22
+ from deepsights.api import ContentStore
23
+ from deepsights.utils import (
24
+ rrf_merge_multi,
25
+ promote_exact_matches,
26
+ rerank_by_recency,
27
+ )
28
+
29
+
30
+ #################################################
31
+ def contentstore_vector_search(
32
+ api: ContentStore,
33
+ query_embedding: List,
34
+ item_type: str,
35
+ search_result: BaseModel,
36
+ min_score: float = 0.7,
37
+ max_results: int = 50,
38
+ recency_weight: float = None,
39
+ ):
40
+ """
41
+ Perform a contentstore vector search using the provided query embedding.
42
+
43
+ Args:
44
+
45
+ api (DeepSights): The DeepSights API instance.
46
+ query_embedding (List): The query embedding vector.
47
+ item_type (str): The type of items to search for.
48
+ search_result (BaseModel): The model to use for parsing search results.
49
+ min_score (float, optional): The minimum score threshold for search results. Defaults to 0.7.
50
+ max_results (int, optional): The maximum number of search results to return. Defaults to 50.
51
+ recency_weight (float, optional): The weight to apply to recency in result ranking. Defaults to None.
52
+
53
+ Returns:
54
+
55
+ List[BaseModel]: The re-ranked search results.
56
+ """
57
+ assert query_embedding, "The 'query_embedding' argument is required."
58
+ assert len(query_embedding) == 1536, "The 'query_embedding' must be of length 1536."
59
+ assert 0 <= min_score <= 1, "Minimum score must be between 0 and 1."
60
+ assert 0 < max_results <= 100, "Maximum results must be between 1 and 100."
61
+ assert (
62
+ recency_weight is None or 0 <= recency_weight <= 1
63
+ ), "Recency weight must be between 0 and 1."
64
+
65
+ body = {
66
+ "vector": query_embedding,
67
+ "source_items_type": item_type,
68
+ "content_restrictions": "NONE",
69
+ "limit": max_results,
70
+ "score_lower_bound": min_score,
71
+ "sort": "RELEVANCY_DESC",
72
+ }
73
+ response = api.post("item-service/items/_vector-search", body=body)
74
+
75
+ # parse
76
+ results = [search_result(i) for i in response["items"]]
77
+
78
+ # re-rank
79
+ return rerank_by_recency(results, recency_weight=recency_weight)
80
+
81
+
82
+ #################################################
83
+ def contentstore_text_search(
84
+ api: ContentStore,
85
+ query: str,
86
+ item_type: str,
87
+ search_result: BaseModel,
88
+ max_results: int = 50,
89
+ recency_weight: float = None,
90
+ ):
91
+ """
92
+ Perform a contentstore text search using the specified query and item type.
93
+
94
+ Args:
95
+
96
+ api (DeepSights): The DeepSights API instance.
97
+ query (str): The search query.
98
+ item_type (str): The type of items to search for.
99
+ search_result (BaseModel): The model used to parse the search results.
100
+ max_results (int, optional): The maximum number of results to return. Defaults to 50.
101
+ recency_weight (float, optional): The weight assigned to recency in result ranking. Defaults to None.
102
+
103
+ Returns:
104
+
105
+ List[BaseModel]: The re-ranked search results.
106
+ """
107
+ assert query is not None, "Query must be provided."
108
+ assert len(query) >= 1, "Query must be at least 2 characters."
109
+ assert 0 < max_results <= 100, "Maximum results must be between 1 and 100."
110
+ assert (
111
+ recency_weight is None or 0 <= recency_weight <= 1
112
+ ), "Recency weight must be between 0 and 1."
113
+
114
+ body = {
115
+ "query": query,
116
+ "source_items_type": item_type,
117
+ "content_restrictions": "NONE",
118
+ "limit": max_results,
119
+ "offset": 0,
120
+ "sort": "RELEVANCY_DESC",
121
+ }
122
+ response = api.post("item-service/items/_text-search", body=body)
123
+
124
+ # parse
125
+ results = [search_result(i) for i in response["items"]]
126
+
127
+ # re-rank
128
+ return rerank_by_recency(results, recency_weight=recency_weight)
129
+
130
+
131
+ #################################################
132
+ def contentstore_search(
133
+ api: ContentStore,
134
+ item_type: str,
135
+ search_result: BaseModel,
136
+ query: str = None,
137
+ query_embedding: List = None,
138
+ max_results: int = 50,
139
+ recency_weight: float = None,
140
+ vector_weight: float = 0.7,
141
+ promote_exact_match: bool = False,
142
+ ) -> List[BaseModel]:
143
+ """
144
+ Perform a hybrid search combining text search and vector search.
145
+
146
+ Args:
147
+
148
+ api (ContentStore): The ContentStore API instance.
149
+ item_type (str): The type of items to search for.
150
+ search_result (BaseModel): The search result model.
151
+ query (str, optional): The text query to search for. Defaults to None.
152
+ query_embedding (List, optional): The vector query embedding. Defaults to None.
153
+ max_results (int, optional): The maximum number of results to return. Defaults to 50.
154
+ recency_weight (float, optional): The weight to assign to recency in the search ranking. Defaults to None.
155
+ vector_weight (float, optional): The weight to assign to vector search in the search ranking. Defaults to 0.7.
156
+ promote_exact_match (bool, optional): Whether to promote exact matches to the top of the results. Defaults to False.
157
+
158
+ Returns:
159
+
160
+ List[BaseModel]: The list of search results.
161
+ """
162
+ assert query or not promote_exact_match, "Promoting exact matches requires a query."
163
+
164
+ results = []
165
+
166
+ if query is None:
167
+ if query_embedding is not None:
168
+ # only vector search
169
+ results = contentstore_vector_search(
170
+ api,
171
+ query_embedding=query_embedding,
172
+ item_type=item_type,
173
+ search_result=search_result,
174
+ max_results=max_results,
175
+ recency_weight=recency_weight,
176
+ )
177
+ else:
178
+ raise ValueError("Must supply at least either text or vector.")
179
+ elif query_embedding is None:
180
+ # only text search
181
+ results = contentstore_text_search(
182
+ api,
183
+ query=query,
184
+ item_type=item_type,
185
+ search_result=search_result,
186
+ max_results=max_results,
187
+ recency_weight=recency_weight,
188
+ )
189
+ else:
190
+ # run a hybrid search in parallel threads
191
+ with ThreadPoolExecutor(max_workers=2) as executor:
192
+ text_future = executor.submit(
193
+ contentstore_text_search,
194
+ api=api,
195
+ query=query,
196
+ item_type=item_type,
197
+ search_result=search_result,
198
+ max_results=max_results,
199
+ recency_weight=recency_weight,
200
+ )
201
+ vector_future = executor.submit(
202
+ contentstore_vector_search,
203
+ api=api,
204
+ query_embedding=query_embedding,
205
+ item_type=item_type,
206
+ search_result=search_result,
207
+ max_results=max_results,
208
+ recency_weight=recency_weight,
209
+ )
210
+
211
+ text_search_results = text_future.result()
212
+ vector_search_results = vector_future.result()
213
+
214
+ # now rrf merge
215
+ results = rrf_merge_multi(
216
+ items=[text_search_results, vector_search_results],
217
+ weights=(1 - vector_weight, vector_weight),
218
+ )
219
+
220
+ # pull exact matches to the top
221
+ if promote_exact_match:
222
+ results = promote_exact_matches(query, results)
223
+
224
+ # re-record the rank
225
+ for rank, result in enumerate(results):
226
+ result.rank = rank + 1
227
+
228
+ # cut off, we might have more results than requested due to the parallel search
229
+ return results[:max_results]
@@ -0,0 +1,76 @@
1
+ # Copyright 2024 Market Logic Software AG. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ This module contains the models for the content store.
17
+ """
18
+
19
+ from typing import Optional
20
+ from datetime import datetime
21
+ from pydantic import Field
22
+ from deepsights.utils import DeepSightsIdTitleModel
23
+
24
+
25
+ #################################################
26
+ class ContentStoreSearchResult(DeepSightsIdTitleModel):
27
+ """
28
+ Represents a search result from the content store.
29
+
30
+ Attributes:
31
+
32
+ description (str): The description of the item.
33
+ image_url (str): The URL of the item's image.
34
+ url (str): The URL of the item.
35
+ timestamp (Optional[datetime], optional): The timestamp of the item's publication. Defaults to None.
36
+ source (Optional[str], optional): The source of the item. Defaults to None.
37
+ rank (Optional[int], optional): The final rank of the item in the search results. Defaults to None.
38
+ score_rank (Optional[int], optional): The rank of the item based on its score. Defaults to None.
39
+ age_rank (Optional[int], optional): The rank of the item based on its age. Defaults to None.
40
+ """
41
+
42
+ description: str = Field(description="The description of the item.")
43
+ image_url: str = Field(description="The URL of the item's thumbnail image.")
44
+ url: str = Field(description="The URL of the item.")
45
+ timestamp: Optional[datetime] = Field(
46
+ alias="published_at",
47
+ default=None,
48
+ description="The timestamp of the item's publication; may be None.",
49
+ )
50
+ source: Optional[str] = Field(
51
+ alias="source_name",
52
+ description="The name of the item's source; may be None.", default=None
53
+ )
54
+ rank: Optional[int] = Field(
55
+ default=None, description="The final rank of the item in the search results."
56
+ )
57
+ score_rank: Optional[int] = Field(
58
+ default=None, description="The rank of the item based on its score."
59
+ )
60
+ age_rank: Optional[int] = Field(
61
+ default=None, description="The rank of the item based on its age; may be None."
62
+ )
63
+
64
+
65
+ #################################################
66
+ class NewsSearchResult(ContentStoreSearchResult):
67
+ """
68
+ Represents a search result of a news article in the content store.
69
+ """
70
+
71
+
72
+ #################################################
73
+ class SecondarySearchResult(ContentStoreSearchResult):
74
+ """
75
+ Represents a search result of a secondary report in the DeepSights API.
76
+ """
@@ -0,0 +1,139 @@
1
+ # Copyright 2024 Market Logic Software AG. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ This module contains the functions to retrieve news articles from the DeepSights content store.
17
+ """
18
+
19
+ from typing import List
20
+
21
+ from deepsights.api import ContentStore
22
+ from deepsights.contentstore.model import NewsSearchResult
23
+ from deepsights.contentstore._search import (
24
+ contentstore_text_search,
25
+ contentstore_vector_search,
26
+ contentstore_search,
27
+ )
28
+
29
+
30
+ #################################################
31
+ def _news_vector_search(
32
+ api: ContentStore,
33
+ query_embedding: List,
34
+ min_score: float = 0.7,
35
+ max_results: int = 50,
36
+ recency_weight: float = None,
37
+ ):
38
+ """
39
+ Perform a vector-based search for news articles.
40
+
41
+ Args:
42
+
43
+ api (DeepSights): The DeepSights API instance.
44
+ query_embedding (List): The embedding vector representing the query.
45
+ min_score (float, optional): The minimum score threshold for search results. Defaults to 0.7.
46
+ max_results (int, optional): The maximum number of search results to return. Defaults to 50.
47
+ recency_weight (float, optional): The weight to apply to recency in the search ranking. Defaults to None.
48
+
49
+ Returns:
50
+
51
+ List[NewsArticleSearchResult]: A list of search results as NewsArticleSearchResult objects.
52
+ """
53
+
54
+ return contentstore_vector_search(
55
+ api,
56
+ item_type="NEWS",
57
+ search_result=lambda i: NewsSearchResult(
58
+ **dict(source_name=i["source"]["display_name"], **i)
59
+ ),
60
+ query_embedding=query_embedding,
61
+ min_score=min_score,
62
+ max_results=max_results,
63
+ recency_weight=recency_weight,
64
+ )
65
+
66
+
67
+ #################################################
68
+ def _news_text_search(
69
+ api: ContentStore,
70
+ query: str,
71
+ max_results: int = 50,
72
+ recency_weight: float = None,
73
+ ):
74
+ """
75
+ Perform a text search for news articles in the DeepSights content store.
76
+
77
+ Args:
78
+
79
+ api (DeepSights): The DeepSights API instance.
80
+ query (str): The search query.
81
+ max_results (int, optional): The maximum number of search results to return. Defaults to 50.
82
+ recency_weight (float, optional): The weight to assign to recency in the search ranking. Defaults to None.
83
+
84
+ Returns:
85
+
86
+ List[NewsArticleSearchResult]: A list of news article search results.
87
+ """
88
+ return contentstore_text_search(
89
+ api,
90
+ item_type="NEWS",
91
+ search_result=lambda i: NewsSearchResult(
92
+ **dict(source_name=i["source"]["display_name"], **i)
93
+ ),
94
+ query=query,
95
+ max_results=max_results,
96
+ recency_weight=recency_weight,
97
+ )
98
+
99
+
100
+ #################################################
101
+ def news_search(
102
+ api: ContentStore,
103
+ query: str = None,
104
+ query_embedding: List = None,
105
+ max_results: int = 50,
106
+ recency_weight: float = None,
107
+ vector_weight: float = 0.7,
108
+ promote_exact_match: bool = False,
109
+ ):
110
+ """
111
+ Perform a hybrid search for news articles in the content store.
112
+
113
+ Args:
114
+
115
+ api (ContentStore): The ContentStore API instance.
116
+ query (str, optional): The search query. Defaults to None.
117
+ query_embedding (List, optional): The query embedding. Defaults to None.
118
+ max_results (int, optional): The maximum number of search results to return. Defaults to 50.
119
+ recency_weight (float, optional): The weight for recency in the search ranking. Defaults to None.
120
+ vector_weight (float, optional): The weight for vector similarity in the search ranking. Defaults to 0.7.
121
+ promote_exact_match (bool, optional): Whether to promote exact matches in the search ranking. Defaults to False.
122
+
123
+ Returns:
124
+
125
+ List[NewsArticleSearchResult]: The search results as a list of NewsArticleSearchResult objects.
126
+ """
127
+ return contentstore_search(
128
+ api,
129
+ item_type="NEWS",
130
+ search_result=lambda i: NewsSearchResult(
131
+ **dict(source_name=i["source"]["display_name"], **i)
132
+ ),
133
+ query=query,
134
+ query_embedding=query_embedding,
135
+ max_results=max_results,
136
+ recency_weight=recency_weight,
137
+ vector_weight=vector_weight,
138
+ promote_exact_match=promote_exact_match,
139
+ )
@@ -0,0 +1,139 @@
1
+ # Copyright 2024 Market Logic Software AG. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ This module contains the functions to retrieve secondary reports from the DeepSights content store.
17
+ """
18
+
19
+ from typing import List
20
+
21
+ from deepsights.api import ContentStore
22
+ from deepsights.contentstore.model import SecondarySearchResult
23
+ from deepsights.contentstore._search import (
24
+ contentstore_text_search,
25
+ contentstore_vector_search,
26
+ contentstore_search,
27
+ )
28
+
29
+
30
+ #################################################
31
+ def _secondary_vector_search(
32
+ api: ContentStore,
33
+ query_embedding: List,
34
+ min_score: float = 0.7,
35
+ max_results: int = 50,
36
+ recency_weight: float = None,
37
+ ):
38
+ """
39
+ Perform a vector-based search for secondary reports.
40
+
41
+ Args:
42
+
43
+ api (DeepSights): The DeepSights API instance.
44
+ query_embedding (List): The embedding vector representing the query.
45
+ min_score (float, optional): The minimum score threshold for search results. Defaults to 0.7.
46
+ max_results (int, optional): The maximum number of search results to return. Defaults to 50.
47
+ recency_weight (float, optional): The weight to apply to recency in the search ranking. Defaults to None.
48
+
49
+ Returns:
50
+
51
+ List[SecondaryReportSearchResult]: A list of search results as SecondaryReportSearchResult objects.
52
+ """
53
+
54
+ return contentstore_vector_search(
55
+ api,
56
+ item_type="REPORTS",
57
+ search_result=lambda i: SecondarySearchResult(
58
+ **dict(source_name=i["source"]["display_name"], **i)
59
+ ),
60
+ query_embedding=query_embedding,
61
+ min_score=min_score,
62
+ max_results=max_results,
63
+ recency_weight=recency_weight,
64
+ )
65
+
66
+
67
+ #################################################
68
+ def _secondary_text_search(
69
+ api: ContentStore,
70
+ query: str,
71
+ max_results: int = 50,
72
+ recency_weight: float = None,
73
+ ):
74
+ """
75
+ Perform a text search for secondary reports in the DeepSights content store.
76
+
77
+ Args:
78
+
79
+ api (DeepSights): The DeepSights API instance.
80
+ query (str): The search query.
81
+ max_results (int, optional): The maximum number of search results to return. Defaults to 50.
82
+ recency_weight (float, optional): The weight to assign to recency in the search ranking. Defaults to None.
83
+
84
+ Returns:
85
+
86
+ List[SecondaryReportSearchResult]: A list of news article search results.
87
+ """
88
+ return contentstore_text_search(
89
+ api,
90
+ item_type="REPORTS",
91
+ search_result=lambda i: SecondarySearchResult(
92
+ **dict(source_name=i["source"]["display_name"], **i)
93
+ ),
94
+ query=query,
95
+ max_results=max_results,
96
+ recency_weight=recency_weight,
97
+ )
98
+
99
+
100
+ #################################################
101
+ def secondary_search(
102
+ api: ContentStore,
103
+ query: str = None,
104
+ query_embedding: List = None,
105
+ max_results: int = 50,
106
+ recency_weight: float = None,
107
+ vector_weight: float = 0.7,
108
+ promote_exact_match: bool = False,
109
+ ):
110
+ """
111
+ Perform a hybrid search for secondary reports in the content store.
112
+
113
+ Args:
114
+
115
+ api (ContentStore): The ContentStore API instance.
116
+ query (str, optional): The search query. Defaults to None.
117
+ query_embedding (List, optional): The query embedding. Defaults to None.
118
+ max_results (int, optional): The maximum number of search results to return. Defaults to 50.
119
+ recency_weight (float, optional): The weight for recency in the search ranking. Defaults to None.
120
+ vector_weight (float, optional): The weight for vector similarity in the search ranking. Defaults to 0.7.
121
+ promote_exact_match (bool, optional): Whether to promote exact matches in the search ranking. Defaults to False.
122
+
123
+ Returns:
124
+
125
+ List[SecondaryReportSearchResult]: The search results as a list of SecondaryReportSearchResult objects.
126
+ """
127
+ return contentstore_search(
128
+ api,
129
+ item_type="REPORTS",
130
+ search_result=lambda i: SecondarySearchResult(
131
+ **dict(source_name=i["source"]["display_name"], **i)
132
+ ),
133
+ query=query,
134
+ query_embedding=query_embedding,
135
+ max_results=max_results,
136
+ recency_weight=recency_weight,
137
+ vector_weight=vector_weight,
138
+ promote_exact_match=promote_exact_match,
139
+ )