cortexdb-sdk 0.2.0b2__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.
- _cortexdb_client/__init__.py +73 -0
- _cortexdb_client/answering.py +59 -0
- _cortexdb_client/aql.py +106 -0
- _cortexdb_client/client.py +291 -0
- _cortexdb_client/errors.py +34 -0
- _cortexdb_client/generated/__init__.py +3 -0
- _cortexdb_client/generated/openapi_types.py +1305 -0
- _cortexdb_client/grounding.py +197 -0
- _cortexdb_client/model_types/__init__.py +66 -0
- _cortexdb_client/model_types/context.py +163 -0
- _cortexdb_client/model_types/core.py +187 -0
- _cortexdb_client/model_types/ingestion.py +63 -0
- _cortexdb_client/model_types/memory.py +20 -0
- _cortexdb_client/model_types/search.py +165 -0
- _cortexdb_client/model_types/verification.py +88 -0
- _cortexdb_client/models.py +73 -0
- _cortexdb_client/py.typed +1 -0
- _cortexdb_client/transport.py +94 -0
- cortexdb_client.py +75 -0
- cortexdb_sdk-0.2.0b2.dist-info/METADATA +58 -0
- cortexdb_sdk-0.2.0b2.dist-info/RECORD +23 -0
- cortexdb_sdk-0.2.0b2.dist-info/WHEEL +5 -0
- cortexdb_sdk-0.2.0b2.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True)
|
|
8
|
+
class AnnSearchReport:
|
|
9
|
+
path: str
|
|
10
|
+
fallback_reason: str | None
|
|
11
|
+
fallback_performed: bool
|
|
12
|
+
requested_limit: int
|
|
13
|
+
allowed_candidates: int
|
|
14
|
+
graph_nodes: int
|
|
15
|
+
returned_candidates: int
|
|
16
|
+
visited_candidates: int
|
|
17
|
+
max_visited_candidates: int | None
|
|
18
|
+
recall_q16: int | None
|
|
19
|
+
min_recall_q16: int | None
|
|
20
|
+
hnsw_max_neighbors: int
|
|
21
|
+
hnsw_ef_search: int
|
|
22
|
+
hnsw_ef_construction: int
|
|
23
|
+
hnsw_layer_count: int
|
|
24
|
+
upper_graph_edges: int
|
|
25
|
+
require_slo: bool
|
|
26
|
+
production_safe: bool
|
|
27
|
+
slo_violations: tuple[str, ...]
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def from_json(cls, value: dict[str, Any]) -> "AnnSearchReport":
|
|
31
|
+
reason = value.get("fallback_reason")
|
|
32
|
+
recall = value.get("recall_q16")
|
|
33
|
+
minimum = value.get("min_recall_q16")
|
|
34
|
+
return cls(
|
|
35
|
+
path=str(value["path"]),
|
|
36
|
+
fallback_reason=str(reason) if reason is not None else None,
|
|
37
|
+
fallback_performed=bool(value.get("fallback_performed", False)),
|
|
38
|
+
requested_limit=int(value["requested_limit"]),
|
|
39
|
+
allowed_candidates=int(value["allowed_candidates"]),
|
|
40
|
+
graph_nodes=int(value["graph_nodes"]),
|
|
41
|
+
returned_candidates=int(value["returned_candidates"]),
|
|
42
|
+
visited_candidates=int(value.get("visited_candidates", 0)),
|
|
43
|
+
max_visited_candidates=(
|
|
44
|
+
int(value["max_visited_candidates"])
|
|
45
|
+
if value.get("max_visited_candidates") is not None
|
|
46
|
+
else None
|
|
47
|
+
),
|
|
48
|
+
recall_q16=int(recall) if recall is not None else None,
|
|
49
|
+
min_recall_q16=int(minimum) if minimum is not None else None,
|
|
50
|
+
hnsw_max_neighbors=int(value.get("hnsw_max_neighbors", 0)),
|
|
51
|
+
hnsw_ef_search=int(value.get("hnsw_ef_search", 0)),
|
|
52
|
+
hnsw_ef_construction=int(value.get("hnsw_ef_construction", 0)),
|
|
53
|
+
hnsw_layer_count=int(value.get("hnsw_layer_count", 0)),
|
|
54
|
+
upper_graph_edges=int(value.get("upper_graph_edges", 0)),
|
|
55
|
+
require_slo=bool(value.get("require_slo", False)),
|
|
56
|
+
production_safe=bool(value.get("production_safe", True)),
|
|
57
|
+
slo_violations=tuple(str(item) for item in value.get("slo_violations", [])),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True)
|
|
62
|
+
class AnnNoFallbackDecision:
|
|
63
|
+
allowed: bool
|
|
64
|
+
reasons: tuple[str, ...]
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def from_json(cls, value: dict[str, Any]) -> "AnnNoFallbackDecision":
|
|
68
|
+
return cls(
|
|
69
|
+
allowed=bool(value["allowed"]),
|
|
70
|
+
reasons=tuple(str(item) for item in value.get("reasons", [])),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass(frozen=True)
|
|
75
|
+
class SearchRoutingDecision:
|
|
76
|
+
requested_mode: str
|
|
77
|
+
selected_strategy: str
|
|
78
|
+
reason: str
|
|
79
|
+
text_available: bool
|
|
80
|
+
vector_available: bool
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_json(cls, value: dict[str, Any]) -> "SearchRoutingDecision":
|
|
84
|
+
return cls(
|
|
85
|
+
requested_mode=str(value["requested_mode"]),
|
|
86
|
+
selected_strategy=str(value["selected_strategy"]),
|
|
87
|
+
reason=str(value["reason"]),
|
|
88
|
+
text_available=bool(value["text_available"]),
|
|
89
|
+
vector_available=bool(value["vector_available"]),
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@dataclass(frozen=True)
|
|
94
|
+
class SearchResult:
|
|
95
|
+
cell_id: int
|
|
96
|
+
score: int
|
|
97
|
+
lexical_score: int
|
|
98
|
+
vector_score: int
|
|
99
|
+
payload: str
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def from_json(cls, value: dict[str, Any]) -> "SearchResult":
|
|
103
|
+
return cls(
|
|
104
|
+
cell_id=int(value["cell_id"]),
|
|
105
|
+
score=int(value["score"]),
|
|
106
|
+
lexical_score=int(value["lexical_score"]),
|
|
107
|
+
vector_score=int(value["vector_score"]),
|
|
108
|
+
payload=str(value["payload"]),
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@dataclass(frozen=True)
|
|
113
|
+
class SearchResponse:
|
|
114
|
+
search_mode: str
|
|
115
|
+
routing: SearchRoutingDecision | None
|
|
116
|
+
rerank: str | None
|
|
117
|
+
ann_report: AnnSearchReport | None
|
|
118
|
+
no_fallback_decision: AnnNoFallbackDecision | None
|
|
119
|
+
results: tuple[SearchResult, ...]
|
|
120
|
+
|
|
121
|
+
@classmethod
|
|
122
|
+
def from_json(cls, value: dict[str, Any]) -> "SearchResponse":
|
|
123
|
+
report = value.get("ann_report")
|
|
124
|
+
routing = value.get("routing")
|
|
125
|
+
decision = value.get("no_fallback_decision")
|
|
126
|
+
return cls(
|
|
127
|
+
search_mode=str(value["search_mode"]),
|
|
128
|
+
routing=SearchRoutingDecision.from_json(routing) if routing else None,
|
|
129
|
+
rerank=str(value["rerank"]) if value.get("rerank") is not None else None,
|
|
130
|
+
ann_report=AnnSearchReport.from_json(report) if report else None,
|
|
131
|
+
no_fallback_decision=(
|
|
132
|
+
AnnNoFallbackDecision.from_json(decision) if decision else None
|
|
133
|
+
),
|
|
134
|
+
results=tuple(SearchResult.from_json(row) for row in value["results"]),
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@dataclass(frozen=True)
|
|
139
|
+
class AnnEvaluationResponse:
|
|
140
|
+
available: bool
|
|
141
|
+
reason: str | None
|
|
142
|
+
ann_report: AnnSearchReport | None
|
|
143
|
+
no_fallback_decision: AnnNoFallbackDecision | None
|
|
144
|
+
exact_top_k: tuple[int, ...]
|
|
145
|
+
ann_top_k: tuple[int, ...]
|
|
146
|
+
overlap_count: int
|
|
147
|
+
recall_q16: int
|
|
148
|
+
|
|
149
|
+
@classmethod
|
|
150
|
+
def from_json(cls, value: dict[str, Any]) -> "AnnEvaluationResponse":
|
|
151
|
+
report = value.get("ann_report")
|
|
152
|
+
decision = value.get("no_fallback_decision")
|
|
153
|
+
reason = value.get("reason")
|
|
154
|
+
return cls(
|
|
155
|
+
available=bool(value["available"]),
|
|
156
|
+
reason=str(reason) if reason is not None else None,
|
|
157
|
+
ann_report=AnnSearchReport.from_json(report) if report else None,
|
|
158
|
+
no_fallback_decision=(
|
|
159
|
+
AnnNoFallbackDecision.from_json(decision) if decision else None
|
|
160
|
+
),
|
|
161
|
+
exact_top_k=tuple(int(row) for row in value["exact_top_k"]),
|
|
162
|
+
ann_top_k=tuple(int(row) for row in value["ann_top_k"]),
|
|
163
|
+
overlap_count=int(value["overlap_count"]),
|
|
164
|
+
recall_q16=int(value["recall_q16"]),
|
|
165
|
+
)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True)
|
|
8
|
+
class EvidenceResponse:
|
|
9
|
+
cell_id: int
|
|
10
|
+
matched_terms: int
|
|
11
|
+
match_score_q16: int
|
|
12
|
+
match_kind: str
|
|
13
|
+
source_trust_q16: int
|
|
14
|
+
source_trust_category: str
|
|
15
|
+
citation: str | None
|
|
16
|
+
payload_text: str
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def from_json(cls, value: dict[str, Any]) -> "EvidenceResponse":
|
|
20
|
+
return cls(
|
|
21
|
+
cell_id=int(value["cell_id"]),
|
|
22
|
+
matched_terms=int(value["matched_terms"]),
|
|
23
|
+
match_score_q16=int(value.get("match_score_q16", 0)),
|
|
24
|
+
match_kind=str(value.get("match_kind", "")),
|
|
25
|
+
source_trust_q16=int(value["source_trust_q16"]),
|
|
26
|
+
source_trust_category=str(value.get("source_trust_category", "")),
|
|
27
|
+
citation=str(value["citation"]) if value.get("citation") is not None else None,
|
|
28
|
+
payload_text=str(value["payload_text"]),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True)
|
|
33
|
+
class GuardResponse:
|
|
34
|
+
cell_id: int | None
|
|
35
|
+
code: str
|
|
36
|
+
message: str
|
|
37
|
+
|
|
38
|
+
@classmethod
|
|
39
|
+
def from_json(cls, value: dict[str, Any]) -> "GuardResponse":
|
|
40
|
+
return cls(
|
|
41
|
+
cell_id=int(value["cell_id"]) if value.get("cell_id") is not None else None,
|
|
42
|
+
code=str(value["code"]),
|
|
43
|
+
message=str(value["message"]),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True)
|
|
48
|
+
class NumericConflictResponse:
|
|
49
|
+
metric: str
|
|
50
|
+
left: str
|
|
51
|
+
right: str
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_json(cls, value: dict[str, Any]) -> "NumericConflictResponse":
|
|
55
|
+
return cls(
|
|
56
|
+
metric=str(value["metric"]),
|
|
57
|
+
left=str(value["left"]),
|
|
58
|
+
right=str(value["right"]),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class VerificationReportResponse:
|
|
64
|
+
fact: str
|
|
65
|
+
status: str
|
|
66
|
+
verdict: str
|
|
67
|
+
confidence_q16: int
|
|
68
|
+
evidence: tuple[EvidenceResponse, ...]
|
|
69
|
+
contradicting_evidence: tuple[EvidenceResponse, ...]
|
|
70
|
+
guards: tuple[GuardResponse, ...]
|
|
71
|
+
supporting: tuple[EvidenceResponse, ...]
|
|
72
|
+
contradicting: tuple[EvidenceResponse, ...]
|
|
73
|
+
numeric_conflicts: tuple[NumericConflictResponse, ...]
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_json(cls, value: dict[str, Any]) -> "VerificationReportResponse":
|
|
77
|
+
return cls(
|
|
78
|
+
fact=str(value["fact"]),
|
|
79
|
+
status=str(value["status"]),
|
|
80
|
+
verdict=str(value["verdict"]),
|
|
81
|
+
confidence_q16=int(value.get("confidence_q16", 0)),
|
|
82
|
+
evidence=tuple(EvidenceResponse.from_json(row) for row in value["evidence"]),
|
|
83
|
+
contradicting_evidence=tuple(EvidenceResponse.from_json(row) for row in value["contradicting_evidence"]),
|
|
84
|
+
guards=tuple(GuardResponse.from_json(row) for row in value["guards"]),
|
|
85
|
+
supporting=tuple(EvidenceResponse.from_json(row) for row in value["supporting"]),
|
|
86
|
+
contradicting=tuple(EvidenceResponse.from_json(row) for row in value["contradicting"]),
|
|
87
|
+
numeric_conflicts=tuple(NumericConflictResponse.from_json(row) for row in value["numeric_conflicts"]),
|
|
88
|
+
)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Public response models for the Python client.
|
|
2
|
+
|
|
3
|
+
This module remains the stable import surface and re-exports the domain-split
|
|
4
|
+
model implementations from ``_cortexdb_client.model_types``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .model_types import (
|
|
8
|
+
AnnEvaluationResponse,
|
|
9
|
+
AnnNoFallbackDecision,
|
|
10
|
+
AnnSearchReport,
|
|
11
|
+
AnswerGroundingReportResponse,
|
|
12
|
+
AnswerGroundingSpanResponse,
|
|
13
|
+
AqlCellResponse,
|
|
14
|
+
AqlQueryCacheStatsResponse,
|
|
15
|
+
AqlResponse,
|
|
16
|
+
CellLookupResponse,
|
|
17
|
+
CellResponse,
|
|
18
|
+
ContextPackAnomalyResponse,
|
|
19
|
+
ContextPackCellResponse,
|
|
20
|
+
ContextPackResponse,
|
|
21
|
+
DeleteJobResponse,
|
|
22
|
+
EvidenceResponse,
|
|
23
|
+
ExplainResponse,
|
|
24
|
+
GroundedAnswerResponse,
|
|
25
|
+
GuardResponse,
|
|
26
|
+
HealthResponse,
|
|
27
|
+
IngestResponse,
|
|
28
|
+
IngestionJobResponse,
|
|
29
|
+
NumericConflictResponse,
|
|
30
|
+
PutCellResponse,
|
|
31
|
+
RememberResponse,
|
|
32
|
+
SearchResponse,
|
|
33
|
+
SearchResult,
|
|
34
|
+
SearchRoutingDecision,
|
|
35
|
+
SourceRefResponse,
|
|
36
|
+
StatsResponse,
|
|
37
|
+
ValidationResponse,
|
|
38
|
+
VerificationReportResponse,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"AnnEvaluationResponse",
|
|
43
|
+
"AnnNoFallbackDecision",
|
|
44
|
+
"AnnSearchReport",
|
|
45
|
+
"AnswerGroundingReportResponse",
|
|
46
|
+
"AnswerGroundingSpanResponse",
|
|
47
|
+
"AqlCellResponse",
|
|
48
|
+
"AqlQueryCacheStatsResponse",
|
|
49
|
+
"AqlResponse",
|
|
50
|
+
"CellLookupResponse",
|
|
51
|
+
"CellResponse",
|
|
52
|
+
"ContextPackAnomalyResponse",
|
|
53
|
+
"ContextPackCellResponse",
|
|
54
|
+
"ContextPackResponse",
|
|
55
|
+
"DeleteJobResponse",
|
|
56
|
+
"EvidenceResponse",
|
|
57
|
+
"ExplainResponse",
|
|
58
|
+
"GroundedAnswerResponse",
|
|
59
|
+
"GuardResponse",
|
|
60
|
+
"HealthResponse",
|
|
61
|
+
"IngestResponse",
|
|
62
|
+
"IngestionJobResponse",
|
|
63
|
+
"NumericConflictResponse",
|
|
64
|
+
"PutCellResponse",
|
|
65
|
+
"RememberResponse",
|
|
66
|
+
"SearchResponse",
|
|
67
|
+
"SearchResult",
|
|
68
|
+
"SearchRoutingDecision",
|
|
69
|
+
"SourceRefResponse",
|
|
70
|
+
"StatsResponse",
|
|
71
|
+
"ValidationResponse",
|
|
72
|
+
"VerificationReportResponse",
|
|
73
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import time
|
|
5
|
+
import urllib.error
|
|
6
|
+
import urllib.parse
|
|
7
|
+
import urllib.request
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from .errors import CortexDBError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def request_json(
|
|
14
|
+
*,
|
|
15
|
+
base_url: str,
|
|
16
|
+
tenant: str | None,
|
|
17
|
+
token: str | None,
|
|
18
|
+
timeout_seconds: float,
|
|
19
|
+
max_retries: int,
|
|
20
|
+
retry_delay_seconds: float,
|
|
21
|
+
opener: Any | None,
|
|
22
|
+
method: str,
|
|
23
|
+
path: str,
|
|
24
|
+
body: bytes,
|
|
25
|
+
) -> dict[str, Any]:
|
|
26
|
+
headers = {"content-type": "application/json"}
|
|
27
|
+
if token:
|
|
28
|
+
headers["authorization"] = f"Bearer {token}"
|
|
29
|
+
url = f"{base_url}{scoped_path(path, tenant)}"
|
|
30
|
+
attempt = 0
|
|
31
|
+
while True:
|
|
32
|
+
request = urllib.request.Request(url, data=body or None, headers=headers, method=method)
|
|
33
|
+
try:
|
|
34
|
+
with open_request(opener, request, timeout_seconds) as response:
|
|
35
|
+
return json.loads(response.read().decode())
|
|
36
|
+
except urllib.error.HTTPError as error:
|
|
37
|
+
body_text = error.read().decode()
|
|
38
|
+
if attempt < max_retries and is_retryable(error.code, body_text):
|
|
39
|
+
attempt += 1
|
|
40
|
+
sleep_before_retry(retry_delay_seconds, attempt)
|
|
41
|
+
continue
|
|
42
|
+
raise CortexDBError.from_response(error.code, body_text) from None
|
|
43
|
+
except urllib.error.URLError as error:
|
|
44
|
+
if attempt < max_retries:
|
|
45
|
+
attempt += 1
|
|
46
|
+
sleep_before_retry(retry_delay_seconds, attempt)
|
|
47
|
+
continue
|
|
48
|
+
reason = str(error.reason)
|
|
49
|
+
raise CortexDBError(reason, code=None, status=None, body=reason) from None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def build_opener() -> Any:
|
|
53
|
+
return urllib.request.build_opener()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def close_opener(opener: Any | None) -> None:
|
|
57
|
+
if opener is None:
|
|
58
|
+
return
|
|
59
|
+
for handler in getattr(opener, "handlers", ()):
|
|
60
|
+
close = getattr(handler, "close", None)
|
|
61
|
+
if callable(close):
|
|
62
|
+
close()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def open_request(opener: Any | None, request: urllib.request.Request, timeout_seconds: float) -> Any:
|
|
66
|
+
if opener is not None:
|
|
67
|
+
return opener.open(request, timeout=timeout_seconds)
|
|
68
|
+
return urllib.request.urlopen(request, timeout=timeout_seconds)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def scoped_path(path: str, tenant: str | None) -> str:
|
|
72
|
+
if not tenant or tenant == "default":
|
|
73
|
+
return path
|
|
74
|
+
separator = "&" if "?" in path else "?"
|
|
75
|
+
encoded = urllib.parse.urlencode({"tenant": tenant})
|
|
76
|
+
return f"{path}{separator}{encoded}"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def is_retryable(status: int, body_text: str) -> bool:
|
|
80
|
+
if status in (502, 504):
|
|
81
|
+
return True
|
|
82
|
+
if status != 503:
|
|
83
|
+
return False
|
|
84
|
+
try:
|
|
85
|
+
code = json.loads(body_text).get("code")
|
|
86
|
+
except json.JSONDecodeError:
|
|
87
|
+
return True
|
|
88
|
+
return code in ("database_busy", "service_unavailable")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def sleep_before_retry(delay_seconds: float, attempt: int) -> None:
|
|
92
|
+
if delay_seconds <= 0:
|
|
93
|
+
return
|
|
94
|
+
time.sleep(delay_seconds * attempt)
|
cortexdb_client.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from _cortexdb_client import (
|
|
4
|
+
AnnEvaluationResponse,
|
|
5
|
+
AnnSearchReport,
|
|
6
|
+
AnswerGroundingReportResponse,
|
|
7
|
+
AnswerGroundingSpanResponse,
|
|
8
|
+
AqlCellResponse,
|
|
9
|
+
AqlResponse,
|
|
10
|
+
CellLookupResponse,
|
|
11
|
+
CellResponse,
|
|
12
|
+
ContextPackAnomalyResponse,
|
|
13
|
+
ContextPackCellResponse,
|
|
14
|
+
ContextPackResponse,
|
|
15
|
+
CortexDBClient,
|
|
16
|
+
CortexDBError,
|
|
17
|
+
DeleteJobResponse,
|
|
18
|
+
EvidenceResponse,
|
|
19
|
+
ExplainResponse,
|
|
20
|
+
GroundedAnswerResponse,
|
|
21
|
+
GuardResponse,
|
|
22
|
+
HealthResponse,
|
|
23
|
+
IngestResponse,
|
|
24
|
+
IngestionJobResponse,
|
|
25
|
+
NumericConflictResponse,
|
|
26
|
+
PutCellResponse,
|
|
27
|
+
RememberResponse,
|
|
28
|
+
SearchResponse,
|
|
29
|
+
SearchResult,
|
|
30
|
+
SourceRefResponse,
|
|
31
|
+
StatsResponse,
|
|
32
|
+
ValidationResponse,
|
|
33
|
+
VerificationReportResponse,
|
|
34
|
+
build_remember_aql,
|
|
35
|
+
build_retrieve_context_aql,
|
|
36
|
+
build_verify_fact_aql,
|
|
37
|
+
openapi_types,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"AnnEvaluationResponse",
|
|
42
|
+
"AnnSearchReport",
|
|
43
|
+
"AnswerGroundingReportResponse",
|
|
44
|
+
"AnswerGroundingSpanResponse",
|
|
45
|
+
"AqlCellResponse",
|
|
46
|
+
"AqlResponse",
|
|
47
|
+
"CellLookupResponse",
|
|
48
|
+
"CellResponse",
|
|
49
|
+
"ContextPackAnomalyResponse",
|
|
50
|
+
"ContextPackCellResponse",
|
|
51
|
+
"ContextPackResponse",
|
|
52
|
+
"CortexDBClient",
|
|
53
|
+
"CortexDBError",
|
|
54
|
+
"DeleteJobResponse",
|
|
55
|
+
"EvidenceResponse",
|
|
56
|
+
"ExplainResponse",
|
|
57
|
+
"GroundedAnswerResponse",
|
|
58
|
+
"GuardResponse",
|
|
59
|
+
"HealthResponse",
|
|
60
|
+
"IngestResponse",
|
|
61
|
+
"IngestionJobResponse",
|
|
62
|
+
"NumericConflictResponse",
|
|
63
|
+
"PutCellResponse",
|
|
64
|
+
"RememberResponse",
|
|
65
|
+
"SearchResponse",
|
|
66
|
+
"SearchResult",
|
|
67
|
+
"SourceRefResponse",
|
|
68
|
+
"StatsResponse",
|
|
69
|
+
"ValidationResponse",
|
|
70
|
+
"VerificationReportResponse",
|
|
71
|
+
"build_remember_aql",
|
|
72
|
+
"build_retrieve_context_aql",
|
|
73
|
+
"build_verify_fact_aql",
|
|
74
|
+
"openapi_types",
|
|
75
|
+
]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexdb-sdk
|
|
3
|
+
Version: 0.2.0b2
|
|
4
|
+
Summary: Beta CortexDB HTTP client
|
|
5
|
+
Author: CortexDB
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AubakirovArman/CortexDB
|
|
8
|
+
Project-URL: Repository, https://github.com/AubakirovArman/CortexDB
|
|
9
|
+
Project-URL: Issues, https://github.com/AubakirovArman/CortexDB/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# cortexdb-sdk
|
|
20
|
+
|
|
21
|
+
Stdlib Python client for the Core Alpha CortexDB HTTP API.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from cortexdb_client import ContextPackResponse, CortexDBClient
|
|
25
|
+
|
|
26
|
+
client = CortexDBClient("http://127.0.0.1:8181").with_retries(3, retry_delay_seconds=0.1).with_timeout(5.0)
|
|
27
|
+
with client.with_session() as session:
|
|
28
|
+
tenant_client = session.with_tenant("tenant:alpha")
|
|
29
|
+
session.put_cell(1, "scope=default\nstatus=ready\nhello")
|
|
30
|
+
print(session.get_cell(1))
|
|
31
|
+
print(tenant_client.stats())
|
|
32
|
+
results = session.search_response("default", "hello")
|
|
33
|
+
print(results.search_mode, results.ann_report, results.results)
|
|
34
|
+
ann_eval = session.evaluate_ann_response("default", [1, 2, 3])
|
|
35
|
+
print(ann_eval.available, ann_eval.recall_q16)
|
|
36
|
+
retrieve = session.build_retrieve_context_aql("hello", "default", limit_candidates=10)
|
|
37
|
+
context: ContextPackResponse = session.context_response("default", retrieve)
|
|
38
|
+
verify = session.verify_response("default", session.build_verify_fact_aql("hello", "default"))
|
|
39
|
+
remember = session.remember_response("default", session.build_remember_aql("hello", "default", "decision", ttl_seconds=3600))
|
|
40
|
+
print(context.token_budget_tokens, verify.status, remember.cell_id)
|
|
41
|
+
print(session.ingest_text("default", "hello from sdk"))
|
|
42
|
+
|
|
43
|
+
grounded = client.answer_with_grounded_context(
|
|
44
|
+
"default",
|
|
45
|
+
"default",
|
|
46
|
+
"What does the context say about hello?",
|
|
47
|
+
lambda pack: pack.cells[0].payload_text if pack.cells else "Not enough information.",
|
|
48
|
+
mode="audit",
|
|
49
|
+
limit_candidates=10,
|
|
50
|
+
)
|
|
51
|
+
print(grounded.citations, grounded.grounding.answer_supported)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The package metadata is prepared for PyPI as `cortexdb-sdk`. Publication is
|
|
55
|
+
not automatic; run `../publish/check.sh` before cutting a package release.
|
|
56
|
+
Run `make sdk-contract-check` from the repository root to validate this client
|
|
57
|
+
against a freshly built local `cortex-server` together with the TypeScript and
|
|
58
|
+
Rust SDKs.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
cortexdb_client.py,sha256=ki5o-JIO1hv4J6y2ZsznuMkzqO-fPQfOl8VgzwjeaVo,1772
|
|
2
|
+
_cortexdb_client/__init__.py,sha256=GG0k-qtx-jhYK3HNAf2xODO7x6WhsXdmOT49QvJbwaI,1845
|
|
3
|
+
_cortexdb_client/answering.py,sha256=e03Y6QwrU1eAKtF6R2eAF_g3sdqyaIsxj28ak0DXBKM,1936
|
|
4
|
+
_cortexdb_client/aql.py,sha256=ZUrSAha0ESPqzKuP7UCGem84dl6mlnvHA9dLc35mUTM,3624
|
|
5
|
+
_cortexdb_client/client.py,sha256=Upp3Xo7LumXgLwIIi-SG7kEGPDrZ-2D3jlAdqtb2Ly4,10719
|
|
6
|
+
_cortexdb_client/errors.py,sha256=pACgB9tQTBfCibJ4laxF1hSmhSqbgd422_7ucXMkNHI,895
|
|
7
|
+
_cortexdb_client/grounding.py,sha256=7BCLgTy7VfXVinrIA0O9cWng_uSFuZs5CLM2H0RLocQ,6063
|
|
8
|
+
_cortexdb_client/models.py,sha256=c5uWummL6Y9o1ERNKA4kspvEbbJba9DZ9XoydctEYG0,1810
|
|
9
|
+
_cortexdb_client/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
10
|
+
_cortexdb_client/transport.py,sha256=fKVsFDjN-ExqkBXEK9TCbuUmrrhbP1Ik9l7UiDKhlIw,2894
|
|
11
|
+
_cortexdb_client/generated/__init__.py,sha256=UkMUyscgcpuoy1UM-IYz8_zGxQBSx1ahM6X6-yf1mdg,94
|
|
12
|
+
_cortexdb_client/generated/openapi_types.py,sha256=fyGDcN2bgQkzcCVhGydqe9F5fndBDPqSx5KNRIR9ZO0,36881
|
|
13
|
+
_cortexdb_client/model_types/__init__.py,sha256=1K8y1sXZYaX3sBvB9shfz6B3t4sYQsteOc5Yop2q6nw,1692
|
|
14
|
+
_cortexdb_client/model_types/context.py,sha256=gvm7ucTiAuXEzZFrVbo6ns_830avhv5YXxSG3Pbk3LA,5138
|
|
15
|
+
_cortexdb_client/model_types/core.py,sha256=rOZvJlWROY3XXpMowJIp1pl8Dc2UlUPMbBbFIlV-90g,6558
|
|
16
|
+
_cortexdb_client/model_types/ingestion.py,sha256=8Br2MSjuCuMbHtKtLPF2WbzVNgi2bDoHxsllEZn1PR8,2106
|
|
17
|
+
_cortexdb_client/model_types/memory.py,sha256=tLfkvH89Xc50VCELAoEA0XUb271xMtVWDyUDR2atPNI,498
|
|
18
|
+
_cortexdb_client/model_types/search.py,sha256=t3VVl321qXCrsGSOQbuPoAEZV3fIKf0ftATq8J4eKYY,5876
|
|
19
|
+
_cortexdb_client/model_types/verification.py,sha256=3nZm8CDO5VJnqCWZwwTiTYGkK3TWXv9a_HfqSrcFyFc,3016
|
|
20
|
+
cortexdb_sdk-0.2.0b2.dist-info/METADATA,sha256=XcDiU8cqarbT__My75JXyF5mALm9u8oRFXxbIeUOaPc,2598
|
|
21
|
+
cortexdb_sdk-0.2.0b2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
22
|
+
cortexdb_sdk-0.2.0b2.dist-info/top_level.txt,sha256=KdcueE7PysJz00zDkan_K1om9hWVzWMeMohEdrrRi-8,33
|
|
23
|
+
cortexdb_sdk-0.2.0b2.dist-info/RECORD,,
|