keiro-client 0.1.0__tar.gz
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.
- keiro_client-0.1.0/LICENSE.md +21 -0
- keiro_client-0.1.0/PKG-INFO +106 -0
- keiro_client-0.1.0/README.md +72 -0
- keiro_client-0.1.0/keiro/__init__.py +31 -0
- keiro_client-0.1.0/keiro/client.py +184 -0
- keiro_client-0.1.0/keiro/exceptions.py +32 -0
- keiro_client-0.1.0/keiro/models.py +66 -0
- keiro_client-0.1.0/keiro_client.egg-info/PKG-INFO +106 -0
- keiro_client-0.1.0/keiro_client.egg-info/SOURCES.txt +12 -0
- keiro_client-0.1.0/keiro_client.egg-info/dependency_links.txt +1 -0
- keiro_client-0.1.0/keiro_client.egg-info/requires.txt +2 -0
- keiro_client-0.1.0/keiro_client.egg-info/top_level.txt +1 -0
- keiro_client-0.1.0/pyproject.toml +22 -0
- keiro_client-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Manas Ranjan Jena
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keiro-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client SDK for Keiro — self-hostable adaptive RAG infrastructure
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2025 Manas Ranjan Jena
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Project-URL: Repository, https://github.com/ManasRanjanJena253/Keiro
|
|
28
|
+
Requires-Python: >=3.11
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE.md
|
|
31
|
+
Requires-Dist: httpx>=0.27.0
|
|
32
|
+
Requires-Dist: pydantic>=2.7.0
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# keiro-client
|
|
36
|
+
|
|
37
|
+
Python client SDK for [Keiro](https://github.com/yourusername/keiro) — a self-hostable adaptive RAG infrastructure.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install keiro-client
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quickstart
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from keiro import KeiroClient
|
|
49
|
+
|
|
50
|
+
client = KeiroClient(
|
|
51
|
+
base_url="http://localhost:8080",
|
|
52
|
+
secret="your-shared-secret",
|
|
53
|
+
namespace="my-docs"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Ingest a document
|
|
57
|
+
job_id = client.ingest("document.pdf")
|
|
58
|
+
|
|
59
|
+
# Poll until complete
|
|
60
|
+
while True:
|
|
61
|
+
status = client.job_status(job_id)
|
|
62
|
+
if status.is_terminal:
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
# Query
|
|
66
|
+
response = client.query("What are the main compliance obligations?")
|
|
67
|
+
print(response.response)
|
|
68
|
+
print(f"Strategy used: {response.retrieval_details.tier_name}")
|
|
69
|
+
print(f"Cache hit: {response.cache_hit}")
|
|
70
|
+
print(f"Total tokens: {response.total_tokens}")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
| Parameter | Description |
|
|
76
|
+
|-----------|-------------|
|
|
77
|
+
| `base_url` | URL of your Keiro gateway, e.g. `http://localhost:8080` |
|
|
78
|
+
| `secret` | Shared secret set in `KEIRO_SECRET` env var |
|
|
79
|
+
| `namespace` | Namespace identifier scoping all operations |
|
|
80
|
+
| `timeout` | Request timeout in seconds (default 120) |
|
|
81
|
+
|
|
82
|
+
## Exception Handling
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from keiro import (
|
|
86
|
+
KeiroClient,
|
|
87
|
+
AuthenticationError,
|
|
88
|
+
RateLimitError,
|
|
89
|
+
IngestionError,
|
|
90
|
+
ConnectionError,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
response = client.query("What is the refund policy?")
|
|
95
|
+
except AuthenticationError:
|
|
96
|
+
print("Invalid secret")
|
|
97
|
+
except RateLimitError as e:
|
|
98
|
+
print(f"Rate limited — retry after {e.retry_after}s")
|
|
99
|
+
except ConnectionError:
|
|
100
|
+
print("Gateway unreachable")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Links
|
|
104
|
+
|
|
105
|
+
- [Keiro repository](https://github.com/ManasRanjanJena253/Keiro)
|
|
106
|
+
- [Report issues](https://github.com/ManasRanjanJena253/Keiro/issues)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# keiro-client
|
|
2
|
+
|
|
3
|
+
Python client SDK for [Keiro](https://github.com/yourusername/keiro) — a self-hostable adaptive RAG infrastructure.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install keiro-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from keiro import KeiroClient
|
|
15
|
+
|
|
16
|
+
client = KeiroClient(
|
|
17
|
+
base_url="http://localhost:8080",
|
|
18
|
+
secret="your-shared-secret",
|
|
19
|
+
namespace="my-docs"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# Ingest a document
|
|
23
|
+
job_id = client.ingest("document.pdf")
|
|
24
|
+
|
|
25
|
+
# Poll until complete
|
|
26
|
+
while True:
|
|
27
|
+
status = client.job_status(job_id)
|
|
28
|
+
if status.is_terminal:
|
|
29
|
+
break
|
|
30
|
+
|
|
31
|
+
# Query
|
|
32
|
+
response = client.query("What are the main compliance obligations?")
|
|
33
|
+
print(response.response)
|
|
34
|
+
print(f"Strategy used: {response.retrieval_details.tier_name}")
|
|
35
|
+
print(f"Cache hit: {response.cache_hit}")
|
|
36
|
+
print(f"Total tokens: {response.total_tokens}")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
| Parameter | Description |
|
|
42
|
+
|-----------|-------------|
|
|
43
|
+
| `base_url` | URL of your Keiro gateway, e.g. `http://localhost:8080` |
|
|
44
|
+
| `secret` | Shared secret set in `KEIRO_SECRET` env var |
|
|
45
|
+
| `namespace` | Namespace identifier scoping all operations |
|
|
46
|
+
| `timeout` | Request timeout in seconds (default 120) |
|
|
47
|
+
|
|
48
|
+
## Exception Handling
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from keiro import (
|
|
52
|
+
KeiroClient,
|
|
53
|
+
AuthenticationError,
|
|
54
|
+
RateLimitError,
|
|
55
|
+
IngestionError,
|
|
56
|
+
ConnectionError,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
response = client.query("What is the refund policy?")
|
|
61
|
+
except AuthenticationError:
|
|
62
|
+
print("Invalid secret")
|
|
63
|
+
except RateLimitError as e:
|
|
64
|
+
print(f"Rate limited — retry after {e.retry_after}s")
|
|
65
|
+
except ConnectionError:
|
|
66
|
+
print("Gateway unreachable")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Links
|
|
70
|
+
|
|
71
|
+
- [Keiro repository](https://github.com/ManasRanjanJena253/Keiro)
|
|
72
|
+
- [Report issues](https://github.com/ManasRanjanJena253/Keiro/issues)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from .client import KeiroClient
|
|
2
|
+
from .exceptions import (
|
|
3
|
+
AuthenticationError,
|
|
4
|
+
ConnectionError,
|
|
5
|
+
IngestionError,
|
|
6
|
+
KeiroError,
|
|
7
|
+
RateLimitError,
|
|
8
|
+
)
|
|
9
|
+
from .models import (
|
|
10
|
+
JobStatus,
|
|
11
|
+
JobStatusResponse,
|
|
12
|
+
QueryResponse,
|
|
13
|
+
RetrievalDetails,
|
|
14
|
+
RetrievalType,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"KeiroClient",
|
|
19
|
+
"KeiroError",
|
|
20
|
+
"AuthenticationError",
|
|
21
|
+
"RateLimitError",
|
|
22
|
+
"IngestionError",
|
|
23
|
+
"ConnectionError",
|
|
24
|
+
"QueryResponse",
|
|
25
|
+
"RetrievalDetails",
|
|
26
|
+
"RetrievalType",
|
|
27
|
+
"JobStatus",
|
|
28
|
+
"JobStatusResponse",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .exceptions import (
|
|
7
|
+
AuthenticationError,
|
|
8
|
+
ConnectionError,
|
|
9
|
+
IngestionError,
|
|
10
|
+
KeiroError,
|
|
11
|
+
RateLimitError,
|
|
12
|
+
)
|
|
13
|
+
from .models import IngestResponse, JobStatusResponse, QueryResponse
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class KeiroClient:
|
|
17
|
+
"""
|
|
18
|
+
Synchronous client for the Keiro adaptive RAG gateway.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
base_url: Base URL of the Go gateway, e.g. "http://localhost:8080"
|
|
23
|
+
secret: Shared secret configured in KEIRO_SECRET
|
|
24
|
+
namespace: Namespace identifier scoping all operations to an isolated
|
|
25
|
+
ChromaDB collection
|
|
26
|
+
timeout: httpx timeout in seconds (default 120 — multi-hop queries
|
|
27
|
+
can be slow)
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
base_url: str,
|
|
33
|
+
secret: str,
|
|
34
|
+
namespace: str,
|
|
35
|
+
timeout: float = 120.0,
|
|
36
|
+
) -> None:
|
|
37
|
+
self._base_url = base_url.rstrip("/")
|
|
38
|
+
self._headers = {
|
|
39
|
+
"X-Secret": secret,
|
|
40
|
+
"X-Namespace": namespace,
|
|
41
|
+
}
|
|
42
|
+
self._client = httpx.Client(
|
|
43
|
+
base_url=self._base_url,
|
|
44
|
+
headers=self._headers,
|
|
45
|
+
timeout=timeout,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# ── public interface ──────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
def query(self, query_text: str) -> QueryResponse:
|
|
51
|
+
"""
|
|
52
|
+
Submit a query to the adaptive RAG pipeline.
|
|
53
|
+
|
|
54
|
+
The gateway classifies the query, selects the appropriate retrieval
|
|
55
|
+
tier, runs retrieval and generation, and returns the response with
|
|
56
|
+
full metadata including strategy used, token counts, and cache status.
|
|
57
|
+
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
query_text: The question or instruction to answer from the ingested
|
|
61
|
+
document corpus
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
QueryResponse with fields: response, prompt_tokens, completion_tokens,
|
|
66
|
+
response_model, cache_hit, retrieval_details (tier + top_k)
|
|
67
|
+
"""
|
|
68
|
+
raw = self._post("/v1/query", json={"query": query_text})
|
|
69
|
+
return QueryResponse.model_validate(raw)
|
|
70
|
+
|
|
71
|
+
def ingest(self, file_path: str | Path) -> str:
|
|
72
|
+
"""
|
|
73
|
+
Upload a document for ingestion into the namespace.
|
|
74
|
+
|
|
75
|
+
The request returns immediately with a job ID. Ingestion runs
|
|
76
|
+
asynchronously — use job_status() to poll until complete.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
file_path: Path to a PDF or plain text file
|
|
81
|
+
|
|
82
|
+
Returns
|
|
83
|
+
-------
|
|
84
|
+
job_id string — use with job_status() to track progress
|
|
85
|
+
"""
|
|
86
|
+
path = Path(file_path)
|
|
87
|
+
if not path.exists():
|
|
88
|
+
raise FileNotFoundError(f"File not found: {path}")
|
|
89
|
+
|
|
90
|
+
with path.open("rb") as f:
|
|
91
|
+
raw = self._post_multipart(
|
|
92
|
+
"/v1/ingest",
|
|
93
|
+
files={"file": (path.name, f, _mime_type(path))},
|
|
94
|
+
)
|
|
95
|
+
return IngestResponse.model_validate(raw).job_id
|
|
96
|
+
|
|
97
|
+
def job_status(self, job_id: str) -> JobStatusResponse:
|
|
98
|
+
"""
|
|
99
|
+
Poll the status of an ingestion job.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
job_id: Job ID returned by ingest()
|
|
104
|
+
|
|
105
|
+
Returns
|
|
106
|
+
-------
|
|
107
|
+
JobStatusResponse with job_status (pending/processing/complete/failed),
|
|
108
|
+
and error string if failed. Use .is_terminal, .is_complete, .is_failed
|
|
109
|
+
properties to branch on status without comparing integers directly.
|
|
110
|
+
|
|
111
|
+
Raises
|
|
112
|
+
------
|
|
113
|
+
IngestionError if the job has reached failed status
|
|
114
|
+
"""
|
|
115
|
+
raw = self._get(f"/v1/jobs/{job_id}")
|
|
116
|
+
result = JobStatusResponse.model_validate(raw)
|
|
117
|
+
if result.is_failed:
|
|
118
|
+
raise IngestionError(job_id, result.error)
|
|
119
|
+
return result
|
|
120
|
+
|
|
121
|
+
def health(self) -> dict:
|
|
122
|
+
"""
|
|
123
|
+
Check liveness and readiness of all stack components.
|
|
124
|
+
|
|
125
|
+
Returns the raw health response dict from the gateway.
|
|
126
|
+
"""
|
|
127
|
+
return self._get("/health")
|
|
128
|
+
|
|
129
|
+
def close(self) -> None:
|
|
130
|
+
"""Close the underlying httpx client. Call when done if not using
|
|
131
|
+
the client as a context manager."""
|
|
132
|
+
self._client.close()
|
|
133
|
+
|
|
134
|
+
# ── context manager ───────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
def __enter__(self) -> KeiroClient:
|
|
137
|
+
return self
|
|
138
|
+
|
|
139
|
+
def __exit__(self, *_) -> None:
|
|
140
|
+
self.close()
|
|
141
|
+
|
|
142
|
+
# ── internal helpers ──────────────────────────────────────────────────────
|
|
143
|
+
|
|
144
|
+
def _post(self, path: str, **kwargs) -> dict:
|
|
145
|
+
return self._request("POST", path, **kwargs)
|
|
146
|
+
|
|
147
|
+
def _post_multipart(self, path: str, **kwargs) -> dict:
|
|
148
|
+
return self._request("POST", path, **kwargs)
|
|
149
|
+
|
|
150
|
+
def _get(self, path: str) -> dict:
|
|
151
|
+
return self._request("GET", path)
|
|
152
|
+
|
|
153
|
+
def _request(self, method: str, path: str, **kwargs) -> dict:
|
|
154
|
+
try:
|
|
155
|
+
response = self._client.request(method, path, **kwargs)
|
|
156
|
+
except httpx.ConnectError as e:
|
|
157
|
+
raise ConnectionError(
|
|
158
|
+
f"Cannot reach Keiro gateway at {self._base_url}: {e}"
|
|
159
|
+
) from e
|
|
160
|
+
except httpx.TimeoutException as e:
|
|
161
|
+
raise KeiroError(f"Request timed out: {e}") from e
|
|
162
|
+
|
|
163
|
+
if response.status_code == 401:
|
|
164
|
+
raise AuthenticationError("Invalid or missing X-Secret header")
|
|
165
|
+
if response.status_code == 429:
|
|
166
|
+
retry_after = float(response.headers.get("Retry-After", 0) or 0)
|
|
167
|
+
raise RateLimitError(retry_after=retry_after or None)
|
|
168
|
+
if response.status_code >= 400:
|
|
169
|
+
raise KeiroError(
|
|
170
|
+
f"Gateway returned {response.status_code}: {response.text}"
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
return response.json()
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# ── helpers ───────────────────────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
def _mime_type(path: Path) -> str:
|
|
179
|
+
suffix = path.suffix.lower()
|
|
180
|
+
return {
|
|
181
|
+
".pdf": "application/pdf",
|
|
182
|
+
".txt": "text/plain",
|
|
183
|
+
".md": "text/markdown",
|
|
184
|
+
}.get(suffix, "application/octet-stream")
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class KeiroError(Exception):
|
|
2
|
+
"""Base exception for all Keiro client errors."""
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AuthenticationError(KeiroError):
|
|
7
|
+
"""Raised when the shared secret is invalid or missing (HTTP 401)."""
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RateLimitError(KeiroError):
|
|
12
|
+
"""Raised when the namespace rate limit is exceeded (HTTP 429)."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, retry_after: float | None = None):
|
|
15
|
+
self.retry_after = retry_after
|
|
16
|
+
msg = "Rate limit exceeded"
|
|
17
|
+
if retry_after:
|
|
18
|
+
msg += f" — retry after {retry_after}s"
|
|
19
|
+
super().__init__(msg)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class IngestionError(KeiroError):
|
|
23
|
+
"""Raised when an ingestion job reaches failed status."""
|
|
24
|
+
|
|
25
|
+
def __init__(self, job_id: str, detail: str = ""):
|
|
26
|
+
self.job_id = job_id
|
|
27
|
+
super().__init__(f"Ingestion job {job_id} failed: {detail}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ConnectionError(KeiroError):
|
|
31
|
+
"""Raised when the gateway cannot be reached."""
|
|
32
|
+
pass
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from enum import IntEnum
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class RetrievalType(IntEnum):
|
|
6
|
+
UNSPECIFIED = 0
|
|
7
|
+
HYBRID = 1 # simple tier — top-2, no reranking
|
|
8
|
+
SELF_QUERYING = 2 # multi-hop tier — iterative, max 3 hops
|
|
9
|
+
MULTI_VECTOR = 3 # complex tier — top-8, MMR + cross-encoder
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class JobStatus(IntEnum):
|
|
13
|
+
PENDING = 0
|
|
14
|
+
PROCESSING = 1
|
|
15
|
+
COMPLETE = 2
|
|
16
|
+
FAILED = 3
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class RetrievalDetails(BaseModel):
|
|
20
|
+
retrieval_type: RetrievalType
|
|
21
|
+
top_k: int
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def tier_name(self) -> str:
|
|
25
|
+
return {
|
|
26
|
+
RetrievalType.HYBRID: "simple",
|
|
27
|
+
RetrievalType.SELF_QUERYING: "multi_hop",
|
|
28
|
+
RetrievalType.MULTI_VECTOR: "complex",
|
|
29
|
+
}.get(self.retrieval_type, "unspecified")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class QueryResponse(BaseModel):
|
|
33
|
+
response: str
|
|
34
|
+
prompt_tokens: int
|
|
35
|
+
completion_tokens: int = Field(alias="completion_token")
|
|
36
|
+
response_model: str
|
|
37
|
+
cache_hit: bool
|
|
38
|
+
retrieval_details: RetrievalDetails
|
|
39
|
+
|
|
40
|
+
model_config = {"populate_by_name": True}
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def total_tokens(self) -> int:
|
|
44
|
+
return self.prompt_tokens + self.completion_tokens
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class IngestResponse(BaseModel):
|
|
48
|
+
job_id: str
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class JobStatusResponse(BaseModel):
|
|
52
|
+
job_id: str
|
|
53
|
+
job_status: JobStatus
|
|
54
|
+
error: str = ""
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def is_terminal(self) -> bool:
|
|
58
|
+
return self.job_status in (JobStatus.COMPLETE, JobStatus.FAILED)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def is_complete(self) -> bool:
|
|
62
|
+
return self.job_status == JobStatus.COMPLETE
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def is_failed(self) -> bool:
|
|
66
|
+
return self.job_status == JobStatus.FAILED
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keiro-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client SDK for Keiro — self-hostable adaptive RAG infrastructure
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2025 Manas Ranjan Jena
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Project-URL: Repository, https://github.com/ManasRanjanJena253/Keiro
|
|
28
|
+
Requires-Python: >=3.11
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE.md
|
|
31
|
+
Requires-Dist: httpx>=0.27.0
|
|
32
|
+
Requires-Dist: pydantic>=2.7.0
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# keiro-client
|
|
36
|
+
|
|
37
|
+
Python client SDK for [Keiro](https://github.com/yourusername/keiro) — a self-hostable adaptive RAG infrastructure.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install keiro-client
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quickstart
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from keiro import KeiroClient
|
|
49
|
+
|
|
50
|
+
client = KeiroClient(
|
|
51
|
+
base_url="http://localhost:8080",
|
|
52
|
+
secret="your-shared-secret",
|
|
53
|
+
namespace="my-docs"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Ingest a document
|
|
57
|
+
job_id = client.ingest("document.pdf")
|
|
58
|
+
|
|
59
|
+
# Poll until complete
|
|
60
|
+
while True:
|
|
61
|
+
status = client.job_status(job_id)
|
|
62
|
+
if status.is_terminal:
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
# Query
|
|
66
|
+
response = client.query("What are the main compliance obligations?")
|
|
67
|
+
print(response.response)
|
|
68
|
+
print(f"Strategy used: {response.retrieval_details.tier_name}")
|
|
69
|
+
print(f"Cache hit: {response.cache_hit}")
|
|
70
|
+
print(f"Total tokens: {response.total_tokens}")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
| Parameter | Description |
|
|
76
|
+
|-----------|-------------|
|
|
77
|
+
| `base_url` | URL of your Keiro gateway, e.g. `http://localhost:8080` |
|
|
78
|
+
| `secret` | Shared secret set in `KEIRO_SECRET` env var |
|
|
79
|
+
| `namespace` | Namespace identifier scoping all operations |
|
|
80
|
+
| `timeout` | Request timeout in seconds (default 120) |
|
|
81
|
+
|
|
82
|
+
## Exception Handling
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from keiro import (
|
|
86
|
+
KeiroClient,
|
|
87
|
+
AuthenticationError,
|
|
88
|
+
RateLimitError,
|
|
89
|
+
IngestionError,
|
|
90
|
+
ConnectionError,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
response = client.query("What is the refund policy?")
|
|
95
|
+
except AuthenticationError:
|
|
96
|
+
print("Invalid secret")
|
|
97
|
+
except RateLimitError as e:
|
|
98
|
+
print(f"Rate limited — retry after {e.retry_after}s")
|
|
99
|
+
except ConnectionError:
|
|
100
|
+
print("Gateway unreachable")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Links
|
|
104
|
+
|
|
105
|
+
- [Keiro repository](https://github.com/ManasRanjanJena253/Keiro)
|
|
106
|
+
- [Report issues](https://github.com/ManasRanjanJena253/Keiro/issues)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE.md
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
keiro/__init__.py
|
|
5
|
+
keiro/client.py
|
|
6
|
+
keiro/exceptions.py
|
|
7
|
+
keiro/models.py
|
|
8
|
+
keiro_client.egg-info/PKG-INFO
|
|
9
|
+
keiro_client.egg-info/SOURCES.txt
|
|
10
|
+
keiro_client.egg-info/dependency_links.txt
|
|
11
|
+
keiro_client.egg-info/requires.txt
|
|
12
|
+
keiro_client.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
keiro
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "keiro-client"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python client SDK for Keiro — self-hostable adaptive RAG infrastructure"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE.md" }
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"httpx>=0.27.0",
|
|
14
|
+
"pydantic>=2.7.0",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Repository = "https://github.com/ManasRanjanJena253/Keiro"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools.packages.find]
|
|
21
|
+
where = ["."]
|
|
22
|
+
include = ["keiro*"]
|