odin-engine 0.1.0__py3-none-any.whl → 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 (63) hide show
  1. benchmarks/__init__.py +17 -17
  2. benchmarks/datasets.py +284 -284
  3. benchmarks/metrics.py +275 -275
  4. benchmarks/run_ablation.py +279 -279
  5. benchmarks/run_npll_benchmark.py +270 -270
  6. npll/__init__.py +10 -10
  7. npll/bootstrap.py +474 -474
  8. npll/core/__init__.py +33 -33
  9. npll/core/knowledge_graph.py +308 -308
  10. npll/core/logical_rules.py +496 -496
  11. npll/core/mln.py +474 -474
  12. npll/inference/__init__.py +40 -40
  13. npll/inference/e_step.py +419 -419
  14. npll/inference/elbo.py +434 -434
  15. npll/inference/m_step.py +576 -576
  16. npll/npll_model.py +631 -631
  17. npll/scoring/__init__.py +42 -42
  18. npll/scoring/embeddings.py +441 -441
  19. npll/scoring/probability.py +402 -402
  20. npll/scoring/scoring_module.py +369 -369
  21. npll/training/__init__.py +24 -24
  22. npll/training/evaluation.py +496 -496
  23. npll/training/npll_trainer.py +520 -520
  24. npll/utils/__init__.py +47 -47
  25. npll/utils/batch_utils.py +492 -492
  26. npll/utils/config.py +144 -144
  27. npll/utils/math_utils.py +338 -338
  28. odin/__init__.py +21 -20
  29. odin/engine.py +264 -264
  30. odin/schema.py +210 -0
  31. {odin_engine-0.1.0.dist-info → odin_engine-0.2.0.dist-info}/METADATA +503 -456
  32. odin_engine-0.2.0.dist-info/RECORD +63 -0
  33. {odin_engine-0.1.0.dist-info → odin_engine-0.2.0.dist-info}/licenses/LICENSE +21 -21
  34. retrieval/__init__.py +50 -50
  35. retrieval/adapters.py +140 -140
  36. retrieval/adapters_arango.py +1418 -1418
  37. retrieval/aggregators.py +707 -707
  38. retrieval/beam.py +127 -127
  39. retrieval/budget.py +60 -60
  40. retrieval/cache.py +159 -159
  41. retrieval/confidence.py +88 -88
  42. retrieval/eval.py +49 -49
  43. retrieval/linker.py +87 -87
  44. retrieval/metrics.py +105 -105
  45. retrieval/metrics_motifs.py +36 -36
  46. retrieval/orchestrator.py +571 -571
  47. retrieval/ppr/__init__.py +12 -12
  48. retrieval/ppr/anchors.py +41 -41
  49. retrieval/ppr/bippr.py +61 -61
  50. retrieval/ppr/engines.py +257 -257
  51. retrieval/ppr/global_pr.py +76 -76
  52. retrieval/ppr/indexes.py +78 -78
  53. retrieval/ppr.py +156 -156
  54. retrieval/ppr_cache.py +25 -25
  55. retrieval/scoring.py +294 -294
  56. retrieval/utils/pii_redaction.py +36 -36
  57. retrieval/writers/__init__.py +9 -9
  58. retrieval/writers/arango_writer.py +28 -28
  59. retrieval/writers/base.py +21 -21
  60. retrieval/writers/janus_writer.py +36 -36
  61. odin_engine-0.1.0.dist-info/RECORD +0 -62
  62. {odin_engine-0.1.0.dist-info → odin_engine-0.2.0.dist-info}/WHEEL +0 -0
  63. {odin_engine-0.1.0.dist-info → odin_engine-0.2.0.dist-info}/top_level.txt +0 -0
@@ -1,9 +1,9 @@
1
- from .base import PersistenceWriter
2
- from .arango_writer import ArangoWriter
3
- from .janus_writer import JanusGraphWriter
4
-
5
- __all__ = [
6
- 'PersistenceWriter',
7
- 'ArangoWriter',
8
- 'JanusGraphWriter',
9
- ]
1
+ from .base import PersistenceWriter
2
+ from .arango_writer import ArangoWriter
3
+ from .janus_writer import JanusGraphWriter
4
+
5
+ __all__ = [
6
+ 'PersistenceWriter',
7
+ 'ArangoWriter',
8
+ 'JanusGraphWriter',
9
+ ]
@@ -1,28 +1,28 @@
1
- from __future__ import annotations
2
- from typing import Dict, Any, Optional
3
-
4
- from .base import PersistenceWriter
5
-
6
- class ArangoWriter(PersistenceWriter):
7
- """
8
- Implementation of the PersistenceWriter protocol for ArangoDB.
9
- """
10
- def __init__(self, arango_client, database: str, persist_threshold: float = 0.8):
11
- self.client = arango_client
12
- self.db = self.client.db(database)
13
- self.persist_threshold = persist_threshold
14
-
15
- def maybe_write_link(self, src_entity: str, rel: str, dst_entity: str, confidence: float, metadata: Optional[Dict[str, Any]] = None) -> bool:
16
- if confidence < self.persist_threshold:
17
- return False
18
-
19
- edges = self.db.collection('kg_edges')
20
- doc = {
21
- '_from': f'entities/{src_entity}',
22
- '_to': f'entities/{dst_entity}',
23
- 'relation': rel,
24
- 'confidence': float(confidence),
25
- 'metadata': metadata or {},
26
- }
27
- edges.insert(doc)
28
- return True
1
+ from __future__ import annotations
2
+ from typing import Dict, Any, Optional
3
+
4
+ from .base import PersistenceWriter
5
+
6
+ class ArangoWriter(PersistenceWriter):
7
+ """
8
+ Implementation of the PersistenceWriter protocol for ArangoDB.
9
+ """
10
+ def __init__(self, arango_client, database: str, persist_threshold: float = 0.8):
11
+ self.client = arango_client
12
+ self.db = self.client.db(database)
13
+ self.persist_threshold = persist_threshold
14
+
15
+ def maybe_write_link(self, src_entity: str, rel: str, dst_entity: str, confidence: float, metadata: Optional[Dict[str, Any]] = None) -> bool:
16
+ if confidence < self.persist_threshold:
17
+ return False
18
+
19
+ edges = self.db.collection('kg_edges')
20
+ doc = {
21
+ '_from': f'entities/{src_entity}',
22
+ '_to': f'entities/{dst_entity}',
23
+ 'relation': rel,
24
+ 'confidence': float(confidence),
25
+ 'metadata': metadata or {},
26
+ }
27
+ edges.insert(doc)
28
+ return True
retrieval/writers/base.py CHANGED
@@ -1,21 +1,21 @@
1
- from __future__ import annotations
2
- from typing import Protocol, Dict, Any, Optional
3
-
4
- class PersistenceWriter(Protocol):
5
- """
6
- Protocol for a generic persistence writer.
7
- Defines the interface for writing links and relations to a database.
8
- """
9
- def maybe_write_link(
10
- self,
11
- src_entity: str,
12
- rel: str,
13
- dst_entity: str,
14
- confidence: float,
15
- metadata: Optional[Dict[str, Any]] = None
16
- ) -> bool:
17
- """
18
- Writes a link to the database if the confidence meets the threshold.
19
- Returns True if the link was written, False otherwise.
20
- """
21
- ...
1
+ from __future__ import annotations
2
+ from typing import Protocol, Dict, Any, Optional
3
+
4
+ class PersistenceWriter(Protocol):
5
+ """
6
+ Protocol for a generic persistence writer.
7
+ Defines the interface for writing links and relations to a database.
8
+ """
9
+ def maybe_write_link(
10
+ self,
11
+ src_entity: str,
12
+ rel: str,
13
+ dst_entity: str,
14
+ confidence: float,
15
+ metadata: Optional[Dict[str, Any]] = None
16
+ ) -> bool:
17
+ """
18
+ Writes a link to the database if the confidence meets the threshold.
19
+ Returns True if the link was written, False otherwise.
20
+ """
21
+ ...
@@ -1,36 +1,36 @@
1
- from __future__ import annotations
2
- from typing import Dict, Any, Optional
3
- from gremlin_python.process.graph_traversal import __
4
- from gremlin_python.structure.graph import Graph
5
-
6
- from .base import PersistenceWriter
7
-
8
- class JanusGraphWriter(PersistenceWriter):
9
- """
10
- Implementation of the PersistenceWriter protocol for JanusGraph.
11
- Assumes connection to a JanusGraph instance via a Gremlin client.
12
- """
13
- def __init__(self, graph: Graph, persist_threshold: float = 0.8):
14
- self.g = graph.traversal()
15
- self.persist_threshold = persist_threshold
16
-
17
- def maybe_write_link(self, src_entity: str, rel: str, dst_entity: str, confidence: float, metadata: Optional[Dict[str, Any]] = None) -> bool:
18
- if confidence < self.persist_threshold:
19
- return False
20
-
21
- # Conceptual Gremlin query to add an edge
22
- # Note: This is a simplified example. You may need to handle vertex existence checks,
23
- # property updates, and transaction management in a production setting.
24
- try:
25
- (self.g.V(src_entity).as_('a')
26
- .V(dst_entity).as_('b')
27
- .addE(rel)
28
- .from_('a').to('b')
29
- .property('confidence', confidence)
30
- # Add any other metadata as properties
31
- .iterate())
32
- return True
33
- except Exception as e:
34
- # In a real implementation, you would log this error
35
- print(f"Failed to write link to JanusGraph: {e}")
36
- return False
1
+ from __future__ import annotations
2
+ from typing import Dict, Any, Optional
3
+ from gremlin_python.process.graph_traversal import __
4
+ from gremlin_python.structure.graph import Graph
5
+
6
+ from .base import PersistenceWriter
7
+
8
+ class JanusGraphWriter(PersistenceWriter):
9
+ """
10
+ Implementation of the PersistenceWriter protocol for JanusGraph.
11
+ Assumes connection to a JanusGraph instance via a Gremlin client.
12
+ """
13
+ def __init__(self, graph: Graph, persist_threshold: float = 0.8):
14
+ self.g = graph.traversal()
15
+ self.persist_threshold = persist_threshold
16
+
17
+ def maybe_write_link(self, src_entity: str, rel: str, dst_entity: str, confidence: float, metadata: Optional[Dict[str, Any]] = None) -> bool:
18
+ if confidence < self.persist_threshold:
19
+ return False
20
+
21
+ # Conceptual Gremlin query to add an edge
22
+ # Note: This is a simplified example. You may need to handle vertex existence checks,
23
+ # property updates, and transaction management in a production setting.
24
+ try:
25
+ (self.g.V(src_entity).as_('a')
26
+ .V(dst_entity).as_('b')
27
+ .addE(rel)
28
+ .from_('a').to('b')
29
+ .property('confidence', confidence)
30
+ # Add any other metadata as properties
31
+ .iterate())
32
+ return True
33
+ except Exception as e:
34
+ # In a real implementation, you would log this error
35
+ print(f"Failed to write link to JanusGraph: {e}")
36
+ return False
@@ -1,62 +0,0 @@
1
- benchmarks/__init__.py,sha256=aSfiClviEKA-lk2R3A4mxJ4RExLERWbsSwOeZ07jw6I,501
2
- benchmarks/datasets.py,sha256=t-9Ci_qUdvUP_yeaOKUk0ZagsGJUDIFQhK_N-riA0b4,8455
3
- benchmarks/metrics.py,sha256=vTpudmq7wo-IWiyZ-wLOMIO8gyO2pd76V9cvUs53lxQ,8026
4
- benchmarks/run_ablation.py,sha256=DINZFBVXXbda0dM_kC7t3LmN0NWVCBnGxo8WJji4eFo,8763
5
- benchmarks/run_npll_benchmark.py,sha256=NoQo-rq0U4yp-mf-R3bSnqEPPpiYOkQHdCFUwEu34bg,8016
6
- npll/__init__.py,sha256=PR9xpeKkRiP8PDhAyW7edNm6J9xdFaUiBkWNvedHvsk,241
7
- npll/bootstrap.py,sha256=ciBBuiKPGKl0pu9gp7GNZLaAsFZJGsPYz3AYDZ-7pv0,18849
8
- npll/npll_model.py,sha256=YWW1meVusR7Kwe25NNBprTtM_L3XopekbnfDk5fBjhM,27171
9
- npll/core/__init__.py,sha256=P0V9CEKyuEhumNkBQfBG4aUlnsmzUakvPnc8ujWiCFg,865
10
- npll/core/knowledge_graph.py,sha256=MOUBvLQGLb79g-mnNJcQncEw8Nh_eH0Slt-Aj2KLllg,11491
11
- npll/core/logical_rules.py,sha256=Pc3-zNxB0q0LAhDBWV_O_ZTuT3hN11tNbJUapyz1uCM,18267
12
- npll/core/mln.py,sha256=j5_LP5pufV4fXA4Vw1M0MSejVZCXyV8nv6gUO664uWY,19059
13
- npll/inference/__init__.py,sha256=ybppVpzmMABSFjk74818TietK1qc-ps-nmmuFxSGDDI,1079
14
- npll/inference/e_step.py,sha256=nqRtL82KQbR5hQ0PzVN0Tjl9VM1rcLD_wut55v5t4Nk,17348
15
- npll/inference/elbo.py,sha256=hr-kxQho44dSNmBdoBIvNyhQ5G3Ic4YSjpliukJGBjY,17320
16
- npll/inference/m_step.py,sha256=XafLUEHhcn8B-D0pbv4ur1ITPSRHmOQ3liXGy74LPVY,23306
17
- npll/scoring/__init__.py,sha256=MqtlaCj9iJA31Zo6iGuZsbAprU6PpIcOn2ugQAjIQew,1338
18
- npll/scoring/embeddings.py,sha256=mtbvFDb4A8RhjoaAC_iFGIRP_UpBmGDxcGBecfhF4Eo,19919
19
- npll/scoring/probability.py,sha256=_k-Dpus6cZ9MgFbKQXwvJVk7z0y6suWBjwzmkLxgxD0,17201
20
- npll/scoring/scoring_module.py,sha256=NNHnV0777c3JbNb_HD8fagqqxBB6pC1lmgOOKAU6AMI,14219
21
- npll/training/__init__.py,sha256=dg9BFwlNbhENC51AKEq_Xd2W2PWEJp_DsVKHPIwmJ2k,665
22
- npll/training/evaluation.py,sha256=AKWstFidiAZgM436pkZN3ejpwZVLTs1HoGRDy3bbUVw,17651
23
- npll/training/npll_trainer.py,sha256=jVVSzfZGvvn2BPVF-Xm7Qb7-853lRKRMG8gujuQnf1Q,18400
24
- npll/utils/__init__.py,sha256=DETz3sU0Vl1M3JCtZDSyDyf4TF2-eg3Q-rxA2_9cmj4,1384
25
- npll/utils/batch_utils.py,sha256=arhPJJQMmM9LZwWOXRYz5yOjeqirMJ5_1ikod4I4FTc,18990
26
- npll/utils/config.py,sha256=uLT8f6-lW84SriQKJhAgn8XgBYX2tnu2_DwWghngEk4,5278
27
- npll/utils/math_utils.py,sha256=O126BegQUCxthlfSrwigy7PAhYi-47gtA6jQcwCI0WA,11736
28
- odin/__init__.py,sha256=zcAH0eVte4K9waL-ncShb3wCtLyg5xvAAVk-rcMnbGI,587
29
- odin/engine.py,sha256=iExs4yfkQuJ2TSXR9tgtcu2y7LE7sjD5StqHNEnSgx4,9366
30
- odin_engine-0.1.0.dist-info/licenses/LICENSE,sha256=qpoLOuIV3ib39skSw-G12n-yAz9XSZkkHqU1zwN79fs,1091
31
- retrieval/__init__.py,sha256=_R7G42rukMXgu-z-lriAB7oG5vEOCITxNKPYPR3QYEI,2334
32
- retrieval/adapters.py,sha256=Ge1iVjOSuyQCPmdxEMqbHvWFUKooTn_YCg2RF7ehSBk,5161
33
- retrieval/adapters_arango.py,sha256=96QKq-PmJMma4D2jY30mmZkRsXY3yrqpu0JzbMYFcu8,55182
34
- retrieval/aggregators.py,sha256=3_l22YMwGk_-2VPhAgnwUcBAt4EY2Nh7E4v2KnHmpdM,24641
35
- retrieval/beam.py,sha256=-bLw4icAK21zVS6ViiOh4CwunbGDwFcgYQY5_9fuvUU,4983
36
- retrieval/budget.py,sha256=hezUkGDWUBVZb3uRF71c3zzP2nK3pICGUCE3pMYb70c,1534
37
- retrieval/cache.py,sha256=2TPZ5WEM3JO5LjnGouYPvAv1amTQdda41POIOAKuQnA,6266
38
- retrieval/confidence.py,sha256=QvfX-fR1rp3AFPZEMtgT6nc_01v-L5glgdjgIHKTafo,3360
39
- retrieval/eval.py,sha256=sPxxsNRIrH0IiRlwykIw0Ltt0qLFL3WDZVRNEKWJyW8,1532
40
- retrieval/linker.py,sha256=uE7IdOglkxpEH3mWeZIpgbGvl3nz89DGpfhWKXAzduU,3297
41
- retrieval/metrics.py,sha256=97aq5EYkBVZakWqjUy0ejtlhQx1uKl_BJXyJeRRSekE,3393
42
- retrieval/metrics_motifs.py,sha256=1i7Uz44JMaCVQAWviBgh45Pb0W6qWAP5oGkp2YsPDwU,1382
43
- retrieval/orchestrator.py,sha256=TLoUFgpiOdTlrsArh-53EMBVXoX4s-_6Rd84SZIGZY4,23064
44
- retrieval/ppr.py,sha256=1pi3jVxQOT2-0EPWu45139aZHNubb8u6jAp-VIZqSpM,5532
45
- retrieval/ppr_cache.py,sha256=JXZwfNmCqLghpfhOqufKNe7WOQn4yLFkQpV3Kechf_I,785
46
- retrieval/scoring.py,sha256=KUV7-vR4uhCoWvhPpsabK6FkaIHL55Ii8orr_OyqkeU,11316
47
- retrieval/ppr/__init__.py,sha256=rHZe08Pow9K82vslLtBB-hCrrd7YsQqiA-QmeqSEh7c,465
48
- retrieval/ppr/anchors.py,sha256=N4k-E-HPGV7J5GFqbbofkz8zF7jjaXoLts5oFjbwKaQ,1262
49
- retrieval/ppr/bippr.py,sha256=iIdCXzCBqsU87uu5MZnJDWvvCs6Y1uanmT2uaNT9QMg,2236
50
- retrieval/ppr/engines.py,sha256=R9BKMIB9pvDPsSoTwNymjPPY4vO1jQW0vpSP09YwByc,10389
51
- retrieval/ppr/global_pr.py,sha256=GpaZdJnwo-XuBDX363qoKXZ6WD2dnOg_8LlJHZUpXnQ,2533
52
- retrieval/ppr/indexes.py,sha256=3sbfpOHgiyPbb3A7D4UwNS2yrYAslzQQy960sDYxDLg,2558
53
- retrieval/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
- retrieval/utils/pii_redaction.py,sha256=gfNK3Vd281P19CmMpXaiiOpFygMA_Vr2iMXxOtxerNs,1260
55
- retrieval/writers/__init__.py,sha256=Qohu0qUUSLV9scSoUS_ut98prFX1G9Xzm-vslf6wTUQ,212
56
- retrieval/writers/arango_writer.py,sha256=sv5FOc7y63eMyogXLLjKpApUVbRFjvIQhn8Vu7sx0U4,1032
57
- retrieval/writers/base.py,sha256=sE0Z6yKYtYhOWOe9XfC9KjkyJ0dfZSY-jgNvmqxgupQ,658
58
- retrieval/writers/janus_writer.py,sha256=SK4e1C9icKsRVUo_FpDF6LfnaftQU4o-pmwJf6_cBEY,1541
59
- odin_engine-0.1.0.dist-info/METADATA,sha256=x5e-9_Pxa83cPJ_lYkbE6mJLNiiUQlpwKcVFpR9JkAI,16098
60
- odin_engine-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
61
- odin_engine-0.1.0.dist-info/top_level.txt,sha256=U53RwIYgQIJ0DBf_OaThVdHosqy06lkB4Zz4crmFadQ,31
62
- odin_engine-0.1.0.dist-info/RECORD,,