semantic-context-engine 0.3.0a1__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. semantic_context_engine/__init__.py +136 -0
  2. semantic_context_engine/artifacts.py +98 -0
  3. semantic_context_engine/cli.py +197 -0
  4. semantic_context_engine/compiler.py +316 -0
  5. semantic_context_engine/composition.py +31 -0
  6. semantic_context_engine/config.py +199 -0
  7. semantic_context_engine/diff.py +93 -0
  8. semantic_context_engine/domain_contracts.py +386 -0
  9. semantic_context_engine/engine.py +250 -0
  10. semantic_context_engine/enrichment.py +1416 -0
  11. semantic_context_engine/errors.py +291 -0
  12. semantic_context_engine/evaluation.py +88 -0
  13. semantic_context_engine/hierarchies.py +185 -0
  14. semantic_context_engine/instructions/semantic_catalog.md +2 -0
  15. semantic_context_engine/integration.py +22 -0
  16. semantic_context_engine/integrations/__init__.py +11 -0
  17. semantic_context_engine/integrations/langchain.py +275 -0
  18. semantic_context_engine/models.py +282 -0
  19. semantic_context_engine/normalization.py +351 -0
  20. semantic_context_engine/pipeline.py +1685 -0
  21. semantic_context_engine/prompts/v1/column_classification.md +15 -0
  22. semantic_context_engine/prompts/v1/grain_correction.md +4 -0
  23. semantic_context_engine/prompts/v1/relationship_proposal.md +10 -0
  24. semantic_context_engine/prompts/v1/synthesis.md +5 -0
  25. semantic_context_engine/prompts/v1/taxonomy.md +5 -0
  26. semantic_context_engine/publication.py +98 -0
  27. semantic_context_engine/registry.py +764 -0
  28. semantic_context_engine/relations.py +1114 -0
  29. semantic_context_engine/runtime.py +1193 -0
  30. semantic_context_engine/sources/base.py +130 -0
  31. semantic_context_engine/sources/duckdb.py +1172 -0
  32. semantic_context_engine/sources/fake.py +107 -0
  33. semantic_context_engine/storage.py +248 -0
  34. semantic_context_engine-0.3.0a1.dist-info/METADATA +263 -0
  35. semantic_context_engine-0.3.0a1.dist-info/RECORD +39 -0
  36. semantic_context_engine-0.3.0a1.dist-info/WHEEL +5 -0
  37. semantic_context_engine-0.3.0a1.dist-info/entry_points.txt +2 -0
  38. semantic_context_engine-0.3.0a1.dist-info/licenses/LICENSE +202 -0
  39. semantic_context_engine-0.3.0a1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,130 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Dict, List, Optional, Protocol, Tuple, runtime_checkable
4
+
5
+ from semantic_context_engine.domain_contracts import SourceCapabilitiesContract
6
+
7
+
8
+ SourceCapabilities = SourceCapabilitiesContract
9
+
10
+
11
+ @runtime_checkable
12
+ class GrainAggregateSource(Protocol):
13
+ def count_rows_and_distinct(self, structural, columns: list[str]) -> tuple[int, int]: ...
14
+
15
+
16
+ @runtime_checkable
17
+ class RelationshipAggregateSource(Protocol):
18
+ """Legacy relationship adapter; each call must execute at most one aggregate statement."""
19
+
20
+ def relationship_metrics(
21
+ self,
22
+ left,
23
+ right,
24
+ left_keys: list[str],
25
+ right_keys: list[str],
26
+ *,
27
+ conditions: list[dict] | None = None,
28
+ ) -> dict: ...
29
+
30
+
31
+ @runtime_checkable
32
+ class MeteredRelationshipAggregateSource(Protocol):
33
+ """Optional extension for adapters that need multiple statements per relation.
34
+
35
+ The implementation must reject insufficient budgets before executing and
36
+ return the exact number of aggregate SQL statements it executed. If it
37
+ raises after starting SQL, raise AggregateQueryExecutionError with the
38
+ exact number already executed; generic failures are conservatively charged
39
+ the full remaining budget by the caller.
40
+ """
41
+
42
+ def relationship_metrics_counted(
43
+ self,
44
+ left,
45
+ right,
46
+ left_keys: list[str],
47
+ right_keys: list[str],
48
+ *,
49
+ max_aggregate_queries: int,
50
+ conditions: list[dict] | None = None,
51
+ key_transforms: list[dict] | None = None,
52
+ ) -> tuple[dict, int]: ...
53
+
54
+
55
+ @runtime_checkable
56
+ class SemistructuredProfileSource(Protocol):
57
+ def profile_json_keys(self, key: str) -> dict: ...
58
+
59
+
60
+ @runtime_checkable
61
+ class BoundedSamplingSource(Protocol):
62
+ def sample_values(
63
+ self,
64
+ structural,
65
+ columns: list[str],
66
+ *,
67
+ mode: str,
68
+ max_rows: int,
69
+ max_values: int,
70
+ max_queries: int,
71
+ ) -> dict: ...
72
+
73
+
74
+ @runtime_checkable
75
+ class ColumnStatisticsSource(Protocol):
76
+ def profile_column_statistics(self, structural, columns: list[str]) -> dict: ...
77
+
78
+
79
+ @runtime_checkable
80
+ class Source(Protocol):
81
+ """Protocolo para conectores de fonte de metadados.
82
+
83
+ Obs.: RawObjectMetadata usa dicts puros em vez de pydantic BaseModel
84
+ para evitar dependência externa não instalável.
85
+ """
86
+
87
+ def describe(self, key: str) -> dict:
88
+ """Descreve um objeto identificado pela key canônica.
89
+
90
+ Args:
91
+ key: key canônica do objeto (ex.: 'vendas_diarias').
92
+
93
+ Returns a dict with keys: key, fqn, object_type, description, hint,
94
+ table_comment, columns (name->data_type strings), ddl_raw,
95
+ dependencies (list), variant_discriminators (dict column->expr).
96
+ Subclasses should raise KeyError if the key is not in the allowlist.
97
+ """
98
+
99
+ def allowlist(self) -> Tuple[str, ...]:
100
+ """Retorna a allowlist de keys (chaves) que esta source conhece."""
101
+
102
+ def all_fqns(self) -> Tuple[str, ...]:
103
+ """Retorna todos os fqns conhecidos por esta source.
104
+
105
+ Apenas metadados auxiliares; o engine opera pelas keys canônicas.
106
+ """
107
+
108
+ def describe_many(self, keys: Optional[List[str]] = None) -> Dict[str, dict]:
109
+ """Descreve múltiplos objetos pelas keys canônicas.
110
+
111
+ Se keys for None, descreve todas da allowlist.
112
+ Keys fora da allowlist falham; não são silenciosamente descartadas.
113
+ """
114
+ if keys is None:
115
+ keys = list(self.allowlist())
116
+ allowed = set(self.allowlist())
117
+ unexpected = set(keys) - allowed
118
+ if unexpected:
119
+ raise KeyError(f"Keys outside source allowlist: {', '.join(sorted(unexpected))}")
120
+ return {k: self.describe(k) for k in keys}
121
+
122
+ @property
123
+ def dialect(self) -> str:
124
+ """SQLGlot dialect name used by source-specific parsing and rendering."""
125
+ return "generic"
126
+
127
+ @property
128
+ def capabilities(self) -> SourceCapabilities:
129
+ """Conservative default for custom sources without optional operations."""
130
+ return SourceCapabilities()