rara-tools 0.0.11__py3-none-any.whl → 0.0.12__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 rara-tools might be problematic. Click here for more details.
- rara_tools/elastic.py +44 -1
- {rara_tools-0.0.11.dist-info → rara_tools-0.0.12.dist-info}/METADATA +1 -1
- {rara_tools-0.0.11.dist-info → rara_tools-0.0.12.dist-info}/RECORD +6 -6
- {rara_tools-0.0.11.dist-info → rara_tools-0.0.12.dist-info}/LICENSE.md +0 -0
- {rara_tools-0.0.11.dist-info → rara_tools-0.0.12.dist-info}/WHEEL +0 -0
- {rara_tools-0.0.11.dist-info → rara_tools-0.0.12.dist-info}/top_level.txt +0 -0
rara_tools/elastic.py
CHANGED
|
@@ -263,7 +263,7 @@ class KataElastic:
|
|
|
263
263
|
response = s.execute()
|
|
264
264
|
return response
|
|
265
265
|
|
|
266
|
-
def
|
|
266
|
+
def execute_ann_vector_search(
|
|
267
267
|
self,
|
|
268
268
|
index: str,
|
|
269
269
|
field: str,
|
|
@@ -281,6 +281,7 @@ class KataElastic:
|
|
|
281
281
|
:param: query vector List[float]: Vector to search matches for.
|
|
282
282
|
:param: k int: Number of nearest neighbors to return.
|
|
283
283
|
:param: num_candidates int: Number of candidates considered before selecting k results.
|
|
284
|
+
:param: n_docs: int: Number of documents to return.
|
|
284
285
|
:param: elastic_ids: List[str]: Elastic ID-s for restricting the search.
|
|
285
286
|
"""
|
|
286
287
|
|
|
@@ -308,6 +309,48 @@ class KataElastic:
|
|
|
308
309
|
# Execute the search
|
|
309
310
|
response = s.execute()
|
|
310
311
|
return response
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def execute_script_score_vector_search(
|
|
315
|
+
self,
|
|
316
|
+
index: str,
|
|
317
|
+
field: str,
|
|
318
|
+
query_vector: List[float],
|
|
319
|
+
n_docs: int = 10,
|
|
320
|
+
elastic_ids: List[str] = []
|
|
321
|
+
) -> Response:
|
|
322
|
+
""" Execute a vector search.
|
|
323
|
+
NB! Requires different mapping than ANN!
|
|
324
|
+
|
|
325
|
+
:param: index str: Index to search from.
|
|
326
|
+
:param: field str: Field containing vectorized data.
|
|
327
|
+
:param: query vector List[float]: Vector to search matches for.
|
|
328
|
+
:param: n_docs: int: Number of documents to return.
|
|
329
|
+
:param: elastic_ids: List[str]: Elastic ID-s for restricting the search.
|
|
330
|
+
"""
|
|
331
|
+
s = elasticsearch_dsl.Search(using=self.elasticsearch, index=index)
|
|
332
|
+
|
|
333
|
+
if elastic_ids:
|
|
334
|
+
query = elasticsearch_dsl.Q("terms", _id=elastic_ids)
|
|
335
|
+
else:
|
|
336
|
+
query = elasticsearch_dsl.Q("match_all")
|
|
337
|
+
# Apply script_score query
|
|
338
|
+
s = s.query(
|
|
339
|
+
"script_score",
|
|
340
|
+
query=query,
|
|
341
|
+
script={
|
|
342
|
+
"source": f"1.0 + cosineSimilarity(params.query_vector, '{field}')",
|
|
343
|
+
"params": {
|
|
344
|
+
"query_vector": query_vector
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
# Set min_score and limit number of documents
|
|
349
|
+
s = s.extra(size=n_docs)
|
|
350
|
+
|
|
351
|
+
# Execute search
|
|
352
|
+
response = s.execute()
|
|
353
|
+
return response
|
|
311
354
|
|
|
312
355
|
|
|
313
356
|
def __str__(self) -> str:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
rara_tools/converters.py,sha256=JcS74VzV6jm12l3C6aqMJBY9nuVW_aevQeCe32KmfrE,1576
|
|
2
2
|
rara_tools/decorators.py,sha256=MjOyvZ5nTkwxwx2JLFEGpKKBysvecFw6EN6UDrSvZLU,2187
|
|
3
3
|
rara_tools/digar_schema_converter.py,sha256=k95U2iRlEA3sh772-v6snhHW6fju6qSTMnvWJ6DpzZk,14254
|
|
4
|
-
rara_tools/elastic.py,sha256=
|
|
4
|
+
rara_tools/elastic.py,sha256=MgPHxZ3UbSTIL8_sT9gU5V4PLKJjo3aQ8CGyhXjRz6M,13065
|
|
5
5
|
rara_tools/exceptions.py,sha256=BwNh4qWxau_ylr9RqZoYwd1KnExI6oWWWDno3jkh8q4,474
|
|
6
6
|
rara_tools/s3.py,sha256=uNDu2HzMYHAWh33RcHeyPFK7gdQfQPxsdfohyIKezEY,4467
|
|
7
7
|
rara_tools/task_reporter.py,sha256=WCcZts9dAUokPc4vbrG3-lNAFLnWaMgE3b3iaUB7mr8,3256
|
|
@@ -9,8 +9,8 @@ rara_tools/utils.py,sha256=9vSbmuWYU5ydr4lXBKlUKa0xzDccFsaJv4T-XwgUfuY,2578
|
|
|
9
9
|
rara_tools/constants/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
rara_tools/constants/digitizer.py,sha256=gJ3jOMwuZfKcLqgOAxTyB266VYsskLabJiMUiSz3xX4,297
|
|
11
11
|
rara_tools/constants/general.py,sha256=E9Jaw-YxocS_tOZw9QBoxO3e9KK5EMbLoM0R7D4Iflw,171
|
|
12
|
-
rara_tools-0.0.
|
|
13
|
-
rara_tools-0.0.
|
|
14
|
-
rara_tools-0.0.
|
|
15
|
-
rara_tools-0.0.
|
|
16
|
-
rara_tools-0.0.
|
|
12
|
+
rara_tools-0.0.12.dist-info/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
|
|
13
|
+
rara_tools-0.0.12.dist-info/METADATA,sha256=Sz4qM5x__70ANb98HsgCjNjwEsKSumaUcbpGSk5Tfcw,3895
|
|
14
|
+
rara_tools-0.0.12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
15
|
+
rara_tools-0.0.12.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
|
|
16
|
+
rara_tools-0.0.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|