nucliadb-models 6.3.1.post3584__py3-none-any.whl → 6.3.1.post3590__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 nucliadb-models might be problematic. Click here for more details.

@@ -0,0 +1,24 @@
1
+ # Copyright (C) 2021 Bosutech XXI S.L.
2
+ #
3
+ # nucliadb is offered under the AGPL v3.0 and as commercial software.
4
+ # For commercial licensing, contact us at info@nuclia.com.
5
+ #
6
+ # AGPL:
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as
9
+ # published by the Free Software Foundation, either version 3 of the
10
+ # License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ from . import ( # noqa: F401
22
+ requests,
23
+ responses,
24
+ )
@@ -0,0 +1,160 @@
1
+ # Copyright (C) 2021 Bosutech XXI S.L.
2
+ #
3
+ # nucliadb is offered under the AGPL v3.0 and as commercial software.
4
+ # For commercial licensing, contact us at info@nuclia.com.
5
+ #
6
+ # AGPL:
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as
9
+ # published by the Free Software Foundation, either version 3 of the
10
+ # License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ from enum import Enum
21
+ from typing import Annotated, Literal, Optional, Union
22
+
23
+ from pydantic import BaseModel, Discriminator, Field, Tag, model_validator
24
+ from typing_extensions import Self
25
+
26
+ from nucliadb_models.filters import And, Not, Or, filter_discriminator
27
+ from nucliadb_models.metadata import RelationNodeType
28
+
29
+ ## Models for graph nodes and relations
30
+
31
+
32
+ class NodeMatchKind(str, Enum):
33
+ EXACT = "exact"
34
+ FUZZY = "fuzzy"
35
+
36
+
37
+ class GraphNode(BaseModel):
38
+ value: Optional[str] = None
39
+ match: NodeMatchKind = NodeMatchKind.EXACT
40
+ type: Optional[RelationNodeType] = RelationNodeType.ENTITY
41
+ group: Optional[str] = None
42
+
43
+ @model_validator(mode="after")
44
+ def validate_fuzzy_usage(self) -> Self:
45
+ if self.match == NodeMatchKind.FUZZY:
46
+ if self.value is None:
47
+ raise ValueError("Fuzzy match can only be used if a node value is provided")
48
+ else:
49
+ if len(self.value) < 3:
50
+ raise ValueError(
51
+ "Fuzzy match must be used with values containing at least 3 characters"
52
+ )
53
+ return self
54
+
55
+
56
+ class GraphRelation(BaseModel):
57
+ label: Optional[str] = None
58
+
59
+
60
+ ## Models for query expressions
61
+
62
+
63
+ class AnyNode(GraphNode):
64
+ prop: Literal["node"]
65
+
66
+
67
+ class SourceNode(GraphNode):
68
+ prop: Literal["source_node"]
69
+
70
+
71
+ class DestinationNode(GraphNode):
72
+ prop: Literal["destination_node"]
73
+
74
+
75
+ class Relation(GraphRelation):
76
+ prop: Literal["relation"]
77
+
78
+
79
+ class GraphPath(BaseModel, extra="forbid"):
80
+ prop: Literal["path"] = "path"
81
+ source: Optional[GraphNode] = None
82
+ relation: Optional[GraphRelation] = None
83
+ destination: Optional[GraphNode] = None
84
+ undirected: bool = False
85
+
86
+
87
+ ## Requests models
88
+
89
+
90
+ class BaseGraphSearchRequest(BaseModel):
91
+ top_k: int = Field(default=50, title="Number of results to retrieve")
92
+
93
+
94
+ graph_query_discriminator = filter_discriminator
95
+
96
+
97
+ # Paths search
98
+
99
+ GraphPathQuery = Annotated[
100
+ Union[
101
+ # bool expressions
102
+ Annotated[And["GraphPathQuery"], Tag("and")],
103
+ Annotated[Or["GraphPathQuery"], Tag("or")],
104
+ Annotated[Not["GraphPathQuery"], Tag("not")],
105
+ # paths
106
+ Annotated[GraphPath, Tag("path")],
107
+ # nodes
108
+ Annotated[SourceNode, Tag("source_node")],
109
+ Annotated[DestinationNode, Tag("destination_node")],
110
+ Annotated[AnyNode, Tag("node")],
111
+ # relations
112
+ Annotated[Relation, Tag("relation")],
113
+ ],
114
+ Discriminator(graph_query_discriminator),
115
+ ]
116
+
117
+
118
+ class GraphSearchRequest(BaseGraphSearchRequest):
119
+ query: GraphPathQuery
120
+
121
+
122
+ # Nodes search
123
+
124
+ GraphNodesQuery = Annotated[
125
+ Union[
126
+ Annotated[And["GraphNodesQuery"], Tag("and")],
127
+ Annotated[Or["GraphNodesQuery"], Tag("or")],
128
+ Annotated[Not["GraphNodesQuery"], Tag("not")],
129
+ Annotated[SourceNode, Tag("source_node")],
130
+ Annotated[DestinationNode, Tag("destination_node")],
131
+ Annotated[AnyNode, Tag("node")],
132
+ ],
133
+ Discriminator(graph_query_discriminator),
134
+ ]
135
+
136
+
137
+ class GraphNodesSearchRequest(BaseGraphSearchRequest):
138
+ query: GraphNodesQuery
139
+
140
+
141
+ # Relations search
142
+
143
+ GraphRelationsQuery = Annotated[
144
+ Union[
145
+ Annotated[Or["GraphRelationsQuery"], Tag("or")],
146
+ Annotated[Not["GraphRelationsQuery"], Tag("not")],
147
+ Annotated[Relation, Tag("relation")],
148
+ ],
149
+ Discriminator(graph_query_discriminator),
150
+ ]
151
+
152
+
153
+ class GraphRelationsSearchRequest(BaseGraphSearchRequest):
154
+ query: GraphRelationsQuery
155
+
156
+
157
+ # We need this to avoid issues with pydantic and generic types defined in another module
158
+ GraphSearchRequest.model_rebuild()
159
+ GraphNodesSearchRequest.model_rebuild()
160
+ GraphRelationsSearchRequest.model_rebuild()
@@ -0,0 +1,62 @@
1
+ # Copyright (C) 2021 Bosutech XXI S.L.
2
+ #
3
+ # nucliadb is offered under the AGPL v3.0 and as commercial software.
4
+ # For commercial licensing, contact us at info@nuclia.com.
5
+ #
6
+ # AGPL:
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as
9
+ # published by the Free Software Foundation, either version 3 of the
10
+ # License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ from enum import Enum
21
+
22
+ from pydantic import BaseModel
23
+
24
+ from nucliadb_models.metadata import RelationNodeType
25
+
26
+
27
+ class GraphNode(BaseModel):
28
+ value: str
29
+ type: RelationNodeType
30
+ group: str
31
+
32
+
33
+ class GraphNodePosition(str, Enum):
34
+ ANY = "any"
35
+ SOURCE = "source"
36
+ DESTINATION = "destination"
37
+
38
+
39
+ class PositionedGraphNode(GraphNode):
40
+ position: GraphNodePosition = GraphNodePosition.ANY
41
+
42
+
43
+ class GraphRelation(BaseModel):
44
+ label: str
45
+
46
+
47
+ class GraphPath(BaseModel):
48
+ source: GraphNode
49
+ relation: GraphRelation
50
+ destination: GraphNode
51
+
52
+
53
+ class GraphSearchResponse(BaseModel):
54
+ paths: list[GraphPath]
55
+
56
+
57
+ class GraphNodesSearchResponse(BaseModel):
58
+ nodes: list[GraphNode]
59
+
60
+
61
+ class GraphRelationsSearchResponse(BaseModel):
62
+ relations: list[GraphRelation]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nucliadb_models
3
- Version: 6.3.1.post3584
3
+ Version: 6.3.1.post3590
4
4
  Author-email: Nuclia <nucliadb@nuclia.com>
5
5
  License: AGPL
6
6
  Project-URL: Homepage, https://nuclia.com
@@ -26,10 +26,13 @@ nucliadb_models/vectors.py,sha256=hDrvUag4WpmQkM8rN5v868IlKSNpVc9OEddJxaxuYws,74
26
26
  nucliadb_models/vectorsets.py,sha256=avxwO9JPX2k5sCniuNhh2MSsP7aRNvf1eB1-h3-Ju1o,1040
27
27
  nucliadb_models/writer.py,sha256=OLtCGmicpVf56pXi2_myTAvStpnaBKKOVNtZzHkKKtw,8472
28
28
  nucliadb_models/agents/ingestion.py,sha256=mV7gV6VpYg4VNpc59K3275TMUJZbUzeUnp3SZzO5uxY,3137
29
+ nucliadb_models/graph/__init__.py,sha256=eu_1UK7GlBQRg5IRUqJkxVMcBxkXeqX4SZL6fuvwjDg,897
30
+ nucliadb_models/graph/requests.py,sha256=fQUoF89Y8IKFkDVQB0Lhxnv7bw0YSDec0NZ9-6-y-5Q,4507
31
+ nucliadb_models/graph/responses.py,sha256=UXDwFY4va6p6T3kgNJSA4iZ7PrLBR5ibyXw_moQixj0,1614
29
32
  nucliadb_models/internal/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
30
33
  nucliadb_models/internal/predict.py,sha256=5rgUPrH_98gerySOZ-TR2PX_qzCGF1_8VxyOu3bGhis,2281
31
34
  nucliadb_models/internal/shards.py,sha256=uZLsMkYWrJDHq3xy_w7snSeV2X3aDBuht9GC_MG3sKc,1976
32
- nucliadb_models-6.3.1.post3584.dist-info/METADATA,sha256=nxf1IcoRQGHcuNxU6anr7m-WqIB5YtbYl5O0JFgozYY,759
33
- nucliadb_models-6.3.1.post3584.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
34
- nucliadb_models-6.3.1.post3584.dist-info/top_level.txt,sha256=UrY1I8oeovIRwkXLYplssTrxQdUjhSEFDFbnwaIV3tA,16
35
- nucliadb_models-6.3.1.post3584.dist-info/RECORD,,
35
+ nucliadb_models-6.3.1.post3590.dist-info/METADATA,sha256=M88eVauScltV6u9fQOQbYB_A1X_6k-c9LwT1ymU0yJA,759
36
+ nucliadb_models-6.3.1.post3590.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
37
+ nucliadb_models-6.3.1.post3590.dist-info/top_level.txt,sha256=UrY1I8oeovIRwkXLYplssTrxQdUjhSEFDFbnwaIV3tA,16
38
+ nucliadb_models-6.3.1.post3590.dist-info/RECORD,,