nucliadb 6.3.4.post3705__py3-none-any.whl → 6.3.4.post3721__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.
@@ -20,6 +20,7 @@
20
20
  import functools
21
21
  from typing import AsyncGenerator, AsyncIterator, Callable, Optional
22
22
 
23
+ import backoff
23
24
  from google.protobuf.message import DecodeError as ProtobufDecodeError
24
25
 
25
26
  from nucliadb import learning_proxy
@@ -38,6 +39,7 @@ from nucliadb_models.configuration import SearchConfiguration
38
39
  from nucliadb_models.export_import import Status
39
40
  from nucliadb_protos import knowledgebox_pb2 as kb_pb2
40
41
  from nucliadb_protos import resources_pb2, writer_pb2
42
+ from nucliadb_protos.writer_pb2_grpc import WriterStub
41
43
  from nucliadb_utils.const import Streams
42
44
  from nucliadb_utils.transaction import MaxTransactionSizeExceededError
43
45
  from nucliadb_utils.utilities import get_ingest
@@ -114,18 +116,24 @@ async def import_broker_message(
114
116
  async def restore_broker_message(
115
117
  context: ApplicationContext, kbid: str, bm: writer_pb2.BrokerMessage
116
118
  ) -> None:
117
- bm.kbid = kbid
119
+ await send_writer_bm(context, bm)
120
+ await send_processor_bm(context, bm)
121
+
118
122
 
119
- # First, ingest the broker message writer part synchronously
120
- async def ingest_request_stream() -> AsyncIterator[writer_pb2.BrokerMessage]:
123
+ @backoff.on_exception(backoff.expo, (Exception,), jitter=backoff.random_jitter, max_tries=8)
124
+ async def send_writer_bm(context: ApplicationContext, bm: writer_pb2.BrokerMessage) -> None:
125
+ async def _iterator() -> AsyncIterator[writer_pb2.BrokerMessage]:
121
126
  yield get_writer_bm(bm)
122
127
 
123
- response = await get_ingest().ProcessMessage(ingest_request_stream()) # type: ignore
128
+ ingest_grpc: WriterStub = get_ingest()
129
+ response: writer_pb2.OpStatusWriter = await ingest_grpc.ProcessMessage(_iterator()) # type: ignore
124
130
  assert response.status == writer_pb2.OpStatusWriter.Status.OK, "Failed to process broker message"
125
131
 
132
+
133
+ async def send_processor_bm(context: ApplicationContext, bm: writer_pb2.BrokerMessage) -> None:
126
134
  # Then enqueue the processor part asynchronously
127
135
  processor_bm = get_processor_bm(bm)
128
- partition = context.partitioning.generate_partition(kbid, bm.uuid)
136
+ partition = context.partitioning.generate_partition(bm.kbid, bm.uuid)
129
137
  await transaction_commit(context, processor_bm, partition)
130
138
 
131
139
 
@@ -69,7 +69,7 @@ async def graph_search_knowledgebox(
69
69
  x_nucliadb_user: str = Header(""),
70
70
  x_forwarded_for: str = Header(""),
71
71
  ) -> GraphSearchResponse:
72
- pb_query = parse_graph_search(item)
72
+ pb_query = await parse_graph_search(kbid, item)
73
73
 
74
74
  results, _, _ = await node_query(kbid, Method.GRAPH, pb_query)
75
75
 
@@ -96,7 +96,7 @@ async def graph_nodes_search_knowledgebox(
96
96
  x_nucliadb_user: str = Header(""),
97
97
  x_forwarded_for: str = Header(""),
98
98
  ) -> GraphNodesSearchResponse:
99
- pb_query = parse_graph_node_search(item)
99
+ pb_query = await parse_graph_node_search(kbid, item)
100
100
 
101
101
  results, _, _ = await node_query(kbid, Method.GRAPH, pb_query)
102
102
 
@@ -123,7 +123,7 @@ async def graph_relations_search_knowledgebox(
123
123
  x_nucliadb_user: str = Header(""),
124
124
  x_forwarded_for: str = Header(""),
125
125
  ) -> GraphRelationsSearchResponse:
126
- pb_query = parse_graph_relation_search(item)
126
+ pb_query = await parse_graph_relation_search(kbid, item)
127
127
 
128
128
  results, _, _ = await node_query(kbid, Method.GRAPH, pb_query)
129
129
 
@@ -18,37 +18,97 @@
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  #
20
20
 
21
+ from typing import Optional, Union
21
22
 
22
23
  from nucliadb.common.models_utils.from_proto import RelationNodeTypeMap, RelationTypeMap
24
+ from nucliadb.search.search.query_parser.filter_expression import add_and_expression, parse_expression
23
25
  from nucliadb.search.search.query_parser.models import GraphRetrieval
26
+ from nucliadb.search.search.utils import filter_hidden_resources
24
27
  from nucliadb_models.graph import requests as graph_requests
25
- from nucliadb_protos import nodereader_pb2
28
+ from nucliadb_models.labels import LABEL_HIDDEN
29
+ from nucliadb_protos import nodereader_pb2, utils_pb2
26
30
 
27
31
 
28
- def parse_graph_search(item: graph_requests.GraphSearchRequest) -> GraphRetrieval:
29
- pb = nodereader_pb2.GraphSearchRequest()
32
+ async def parse_graph_search(kbid: str, item: graph_requests.GraphSearchRequest) -> GraphRetrieval:
33
+ pb = await _parse_common(kbid, item)
30
34
  pb.query.path.CopyFrom(_parse_path_query(item.query))
31
- pb.top_k = item.top_k
32
35
  pb.kind = nodereader_pb2.GraphSearchRequest.QueryKind.PATH
33
36
  return pb
34
37
 
35
38
 
36
- def parse_graph_node_search(item: graph_requests.GraphNodesSearchRequest) -> GraphRetrieval:
37
- pb = nodereader_pb2.GraphSearchRequest()
39
+ async def parse_graph_node_search(
40
+ kbid: str, item: graph_requests.GraphNodesSearchRequest
41
+ ) -> GraphRetrieval:
42
+ pb = await _parse_common(kbid, item)
38
43
  pb.query.path.CopyFrom(_parse_node_query(item.query))
39
- pb.top_k = item.top_k
40
44
  pb.kind = nodereader_pb2.GraphSearchRequest.QueryKind.NODES
41
45
  return pb
42
46
 
43
47
 
44
- def parse_graph_relation_search(item: graph_requests.GraphRelationsSearchRequest) -> GraphRetrieval:
45
- pb = nodereader_pb2.GraphSearchRequest()
48
+ async def parse_graph_relation_search(
49
+ kbid: str, item: graph_requests.GraphRelationsSearchRequest
50
+ ) -> GraphRetrieval:
51
+ pb = await _parse_common(kbid, item)
46
52
  pb.query.path.CopyFrom(_parse_relation_query(item.query))
47
- pb.top_k = item.top_k
48
53
  pb.kind = nodereader_pb2.GraphSearchRequest.QueryKind.RELATIONS
49
54
  return pb
50
55
 
51
56
 
57
+ AnyGraphRequest = Union[
58
+ graph_requests.GraphSearchRequest,
59
+ graph_requests.GraphNodesSearchRequest,
60
+ graph_requests.GraphRelationsSearchRequest,
61
+ ]
62
+
63
+
64
+ async def _parse_common(kbid: str, item: AnyGraphRequest) -> nodereader_pb2.GraphSearchRequest:
65
+ pb = nodereader_pb2.GraphSearchRequest()
66
+ pb.top_k = item.top_k
67
+
68
+ filter_expr = await _parse_filters(kbid, item)
69
+ if filter_expr is not None:
70
+ pb.field_filter.CopyFrom(filter_expr)
71
+
72
+ security = _parse_security(kbid, item)
73
+ if security is not None:
74
+ pb.security.CopyFrom(security)
75
+
76
+ return pb
77
+
78
+
79
+ async def _parse_filters(kbid: str, item: AnyGraphRequest) -> Optional[nodereader_pb2.FilterExpression]:
80
+ filter_expr = nodereader_pb2.FilterExpression()
81
+ if item.filter_expression:
82
+ if item.filter_expression.field:
83
+ filter_expr = await parse_expression(item.filter_expression.field, kbid)
84
+
85
+ hidden = await filter_hidden_resources(kbid, item.show_hidden)
86
+ if hidden is not None:
87
+ expr = nodereader_pb2.FilterExpression()
88
+ if hidden:
89
+ expr.facet.facet = LABEL_HIDDEN
90
+ else:
91
+ expr.bool_not.facet.facet = LABEL_HIDDEN
92
+
93
+ add_and_expression(filter_expr, expr)
94
+
95
+ if filter_expr.HasField("expr"):
96
+ return filter_expr
97
+ else:
98
+ return None
99
+
100
+
101
+ def _parse_security(kbid: str, item: AnyGraphRequest) -> Optional[utils_pb2.Security]:
102
+ if item.security is not None and len(item.security.groups) > 0:
103
+ security_pb = utils_pb2.Security()
104
+ for group_id in item.security.groups:
105
+ if group_id not in security_pb.access_groups:
106
+ security_pb.access_groups.append(group_id)
107
+ return security_pb
108
+ else:
109
+ return None
110
+
111
+
52
112
  def _parse_path_query(expr: graph_requests.GraphPathQuery) -> nodereader_pb2.GraphQuery.PathQuery:
53
113
  pb = nodereader_pb2.GraphQuery.PathQuery()
54
114
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: nucliadb
3
- Version: 6.3.4.post3705
3
+ Version: 6.3.4.post3721
4
4
  Summary: NucliaDB
5
5
  Author-email: Nuclia <nucliadb@nuclia.com>
6
6
  License: AGPL
@@ -20,11 +20,11 @@ Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3 :: Only
21
21
  Requires-Python: <4,>=3.9
22
22
  Description-Content-Type: text/markdown
23
- Requires-Dist: nucliadb-telemetry[all]>=6.3.4.post3705
24
- Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.3.4.post3705
25
- Requires-Dist: nucliadb-protos>=6.3.4.post3705
26
- Requires-Dist: nucliadb-models>=6.3.4.post3705
27
- Requires-Dist: nidx-protos>=6.3.4.post3705
23
+ Requires-Dist: nucliadb-telemetry[all]>=6.3.4.post3721
24
+ Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.3.4.post3721
25
+ Requires-Dist: nucliadb-protos>=6.3.4.post3721
26
+ Requires-Dist: nucliadb-models>=6.3.4.post3721
27
+ Requires-Dist: nidx-protos>=6.3.4.post3721
28
28
  Requires-Dist: nucliadb-admin-assets>=1.0.0.post1224
29
29
  Requires-Dist: nuclia-models>=0.24.2
30
30
  Requires-Dist: uvicorn
@@ -111,7 +111,7 @@ nucliadb/export_import/exporter.py,sha256=k2QVx1EjqFlDYiggriWiEJzwtMXzHbldsqWdpG
111
111
  nucliadb/export_import/importer.py,sha256=v5cq9Nn8c2zrY_K_00mydR52f8mdFxR7tLdtNLQ0qvk,4229
112
112
  nucliadb/export_import/models.py,sha256=dbjScNkiMRv4X3Ktudy1JRliD25bfoDTy3JmEZgQSCc,2121
113
113
  nucliadb/export_import/tasks.py,sha256=DWbdqY97ffoyfipelGXz3Jqz1iam6JCjQSh367Fc3NA,2947
114
- nucliadb/export_import/utils.py,sha256=9M81mrFV7FyBcWjsq4KrqfLIXFYbt9_vD1mkY31z4gs,22819
114
+ nucliadb/export_import/utils.py,sha256=8XOVMYXXw8b4ikojG7RjQ4tKN3Xu7nfu2yCUOqD50sk,23216
115
115
  nucliadb/ingest/__init__.py,sha256=fsw3C38VP50km3R-nHL775LNGPpJ4JxqXJ2Ib1f5SqE,1011
116
116
  nucliadb/ingest/app.py,sha256=TaVgh5B2riFVmcsrbPb7a5YCzmnybjx-NK0BXgTwGAY,7535
117
117
  nucliadb/ingest/partitions.py,sha256=2NIhMYbNT0TNBL6bX1UMSi7vxFGICstCKEqsB0TXHOE,2410
@@ -204,7 +204,7 @@ nucliadb/search/api/v1/ask.py,sha256=SFNjvhY3xAVniMChitILdtzwn7HmgV_k_ecn71egca0
204
204
  nucliadb/search/api/v1/catalog.py,sha256=Nw4wIj4AjGp-p64FFVQFN4v2LFcV3A0UJIxfo3_XGmY,7670
205
205
  nucliadb/search/api/v1/feedback.py,sha256=kNLc4dHz2SXHzV0PwC1WiRAwY88fDptPcP-kO0q-FrQ,2620
206
206
  nucliadb/search/api/v1/find.py,sha256=OOeqCVE88o4t1XzWgcknTWR0e3WcwzLDcnUhCeA1Pcc,10495
207
- nucliadb/search/api/v1/graph.py,sha256=5APs0-W-jNQfH-mRLrdRkk6B_mnsJxLb68t0NE_KZUk,4238
207
+ nucliadb/search/api/v1/graph.py,sha256=ItVpzJbqfDLjoIo2fTb2mKGCM1Z34sx7CBb3gNmj6IQ,4274
208
208
  nucliadb/search/api/v1/knowledgebox.py,sha256=rWhx3PYWryingu19qwwFDbVvVYynq5Ky23FSlzmTutQ,8721
209
209
  nucliadb/search/api/v1/predict_proxy.py,sha256=QrGzo0hKjtmyGZ6pjlJHYAh4hxwVUIOTcVcerRCw7eE,3047
210
210
  nucliadb/search/api/v1/router.py,sha256=mtT07rBZcVfpa49doaw9b1tj3sdi3qLH0gn9Io6NYM0,988
@@ -257,7 +257,7 @@ nucliadb/search/search/query_parser/old_filters.py,sha256=-zbfN-RsXoj_DRjh3Lfp-w
257
257
  nucliadb/search/search/query_parser/parsers/__init__.py,sha256=ySCNSdbesLXGZyR88919njulA6UE10_3PhqMG_Yj1o4,1034
258
258
  nucliadb/search/search/query_parser/parsers/catalog.py,sha256=XdBiTweGTQkj8m_V_i2xbwp7P5pPO8K1Tud692XKhMw,7149
259
259
  nucliadb/search/search/query_parser/parsers/find.py,sha256=q3wH_i0DGceeKckYEH3c5MqM5EvRiMCL7r-6nCAId9Q,4666
260
- nucliadb/search/search/query_parser/parsers/graph.py,sha256=fdzKzwnwhSkMXgt8bKXsvBFR8zWjb12lKAgtPzGr37c,6396
260
+ nucliadb/search/search/query_parser/parsers/graph.py,sha256=SfbMV-H-oCqZraQIwD8n5Hqi9dwOlvqzh_I3aZAKatg,8369
261
261
  nucliadb/standalone/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
262
262
  nucliadb/standalone/api_router.py,sha256=hgq9FXpihzgjHkwcVGfGCSwyXy67fqXTfLFHuINzIi0,5567
263
263
  nucliadb/standalone/app.py,sha256=mAApNK_iVsQgJyd-mtwCeZq5csSimwnXmlQGH9a70pE,5586
@@ -353,8 +353,8 @@ nucliadb/writer/tus/local.py,sha256=7jYa_w9b-N90jWgN2sQKkNcomqn6JMVBOVeDOVYJHto,
353
353
  nucliadb/writer/tus/s3.py,sha256=vF0NkFTXiXhXq3bCVXXVV-ED38ECVoUeeYViP8uMqcU,8357
354
354
  nucliadb/writer/tus/storage.py,sha256=ToqwjoYnjI4oIcwzkhha_MPxi-k4Jk3Lt55zRwaC1SM,2903
355
355
  nucliadb/writer/tus/utils.py,sha256=MSdVbRsRSZVdkaum69_0wku7X3p5wlZf4nr6E0GMKbw,2556
356
- nucliadb-6.3.4.post3705.dist-info/METADATA,sha256=BUOECm6cOmDYEdufJ2_6TfQX3ib7DgUIltnFx2y6X9k,4291
357
- nucliadb-6.3.4.post3705.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
358
- nucliadb-6.3.4.post3705.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
359
- nucliadb-6.3.4.post3705.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
360
- nucliadb-6.3.4.post3705.dist-info/RECORD,,
356
+ nucliadb-6.3.4.post3721.dist-info/METADATA,sha256=dRb4oW-OP03oqZIpufFKnLhTusmOZtwCdgvZTTLq_NQ,4291
357
+ nucliadb-6.3.4.post3721.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
358
+ nucliadb-6.3.4.post3721.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
359
+ nucliadb-6.3.4.post3721.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
360
+ nucliadb-6.3.4.post3721.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.1.0)
2
+ Generator: setuptools (77.0.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5