datacoder 0.2.1__tar.gz → 0.3.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.
- {datacoder-0.2.1 → datacoder-0.3.0}/PKG-INFO +73 -24
- {datacoder-0.2.1 → datacoder-0.3.0}/README.md +72 -23
- datacoder-0.3.0/datacoder/__init__.py +6 -0
- {datacoder-0.2.1 → datacoder-0.3.0}/datacoder/client.py +92 -12
- {datacoder-0.2.1 → datacoder-0.3.0}/datacoder.egg-info/PKG-INFO +73 -24
- {datacoder-0.2.1 → datacoder-0.3.0}/pyproject.toml +1 -1
- datacoder-0.2.1/datacoder/__init__.py +0 -6
- {datacoder-0.2.1 → datacoder-0.3.0}/datacoder.egg-info/SOURCES.txt +0 -0
- {datacoder-0.2.1 → datacoder-0.3.0}/datacoder.egg-info/dependency_links.txt +0 -0
- {datacoder-0.2.1 → datacoder-0.3.0}/datacoder.egg-info/requires.txt +0 -0
- {datacoder-0.2.1 → datacoder-0.3.0}/datacoder.egg-info/top_level.txt +0 -0
- {datacoder-0.2.1 → datacoder-0.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datacoder
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python SDK for DataCoder — AI Data Analyst Platform (RAG API)
|
|
5
5
|
Author-email: Clouditia <contact@clouditia.com>
|
|
6
6
|
License: MIT
|
|
@@ -36,37 +36,51 @@ pip install datacoder
|
|
|
36
36
|
## Quick Start
|
|
37
37
|
|
|
38
38
|
```python
|
|
39
|
-
from datacoder import
|
|
39
|
+
from datacoder import DataCoderClient
|
|
40
40
|
|
|
41
41
|
# Initialize with your SDK key and server URL
|
|
42
|
-
|
|
42
|
+
client = DataCoderClient(
|
|
43
43
|
api_key="dc_sk_your_key_here",
|
|
44
44
|
base_url="https://datacoder.clouditia.com",
|
|
45
45
|
)
|
|
46
46
|
|
|
47
47
|
# Test connectivity
|
|
48
|
-
if
|
|
48
|
+
if client.ping():
|
|
49
49
|
print("Connected!")
|
|
50
50
|
|
|
51
|
-
#
|
|
52
|
-
|
|
51
|
+
# Search a knowledge base
|
|
52
|
+
results = client.search("Quels sont les risques de credit ?")
|
|
53
|
+
for r in results:
|
|
54
|
+
print(r.content, r.source, r.score)
|
|
55
|
+
|
|
56
|
+
# Search in a specific folder
|
|
57
|
+
results = client.search(
|
|
58
|
+
"Clause de resiliation",
|
|
53
59
|
folder_id="your-folder-uuid",
|
|
54
|
-
query="Quels sont les risques de crédit dans Bâle III ?",
|
|
55
60
|
)
|
|
56
61
|
|
|
62
|
+
# Full query with RAGResult
|
|
63
|
+
result = client.query(
|
|
64
|
+
folder_id="your-folder-uuid",
|
|
65
|
+
query="Quels sont les risques de credit dans Bale III ?",
|
|
66
|
+
)
|
|
57
67
|
print(result.answer) # Combined text from all matching chunks
|
|
58
68
|
print(result.sources) # List of source document names
|
|
59
|
-
print(result.count) # Number of results
|
|
60
69
|
|
|
61
70
|
# Check your quota
|
|
62
|
-
quota =
|
|
71
|
+
quota = client.quota()
|
|
63
72
|
print(f"Plan: {quota.plan}")
|
|
64
73
|
print(f"SDK remaining today: {quota.sdk_remaining}")
|
|
74
|
+
|
|
75
|
+
# List accessible folders
|
|
76
|
+
folders = client.folders()
|
|
77
|
+
for f in folders:
|
|
78
|
+
print(f["name"], f["id"])
|
|
65
79
|
```
|
|
66
80
|
|
|
67
81
|
## API Reference
|
|
68
82
|
|
|
69
|
-
### `
|
|
83
|
+
### `DataCoderClient(api_key, base_url, timeout=30)`
|
|
70
84
|
|
|
71
85
|
Initialize the SDK client.
|
|
72
86
|
|
|
@@ -76,9 +90,28 @@ Initialize the SDK client.
|
|
|
76
90
|
| `base_url` | `str` | `https://datacoder.clouditia.com` | DataCoder server URL |
|
|
77
91
|
| `timeout` | `int` | `30` | Request timeout in seconds |
|
|
78
92
|
|
|
79
|
-
### `
|
|
93
|
+
### `client.search(query, folder_id=None, top_k=10) → list[SearchResult]`
|
|
80
94
|
|
|
81
|
-
|
|
95
|
+
Search a RAG knowledge base. Returns a list of results.
|
|
96
|
+
|
|
97
|
+
| Parameter | Type | Default | Description |
|
|
98
|
+
|-----------|------|---------|-------------|
|
|
99
|
+
| `query` | `str` | — | Natural language question |
|
|
100
|
+
| `folder_id` | `str` | `None` | UUID of the knowledge folder (None = all folders) |
|
|
101
|
+
| `top_k` | `int` | `10` | Max results (1-20) |
|
|
102
|
+
|
|
103
|
+
**Returns:** `list[SearchResult]`
|
|
104
|
+
|
|
105
|
+
| Property | Type | Description |
|
|
106
|
+
|----------|------|-------------|
|
|
107
|
+
| `r.content` | `str` | Matching text chunk |
|
|
108
|
+
| `r.source` | `str` | Source document name |
|
|
109
|
+
| `r.score` | `float` | Similarity score (0-1) |
|
|
110
|
+
| `r.page` | `int \| None` | Page number in source document |
|
|
111
|
+
|
|
112
|
+
### `client.query(folder_id, query, top_k=10) → RAGResult`
|
|
113
|
+
|
|
114
|
+
Full RAG query with aggregated results.
|
|
82
115
|
|
|
83
116
|
| Parameter | Type | Default | Description |
|
|
84
117
|
|-----------|------|---------|-------------|
|
|
@@ -92,12 +125,14 @@ Query a RAG knowledge base.
|
|
|
92
125
|
|----------|------|-------------|
|
|
93
126
|
| `result.answer` | `str` | Concatenated content from all matching chunks |
|
|
94
127
|
| `result.sources` | `list[str]` | Source document names |
|
|
128
|
+
| `result.items` | `list[SearchResult]` | Results as SearchResult objects |
|
|
95
129
|
| `result.count` | `int` | Number of results |
|
|
96
|
-
| `result.results` | `list[dict]` | Raw results with `content`, `source`, `page`, `score` |
|
|
97
|
-
| `result.query` | `str` | Original query |
|
|
98
|
-
| `result.folder_id` | `str` | Folder queried |
|
|
99
130
|
|
|
100
|
-
### `
|
|
131
|
+
### `client.folders() → list[dict]`
|
|
132
|
+
|
|
133
|
+
List knowledge folders accessible by this API key.
|
|
134
|
+
|
|
135
|
+
### `client.quota() → QuotaInfo`
|
|
101
136
|
|
|
102
137
|
Check current usage and limits.
|
|
103
138
|
|
|
@@ -108,11 +143,8 @@ Check current usage and limits.
|
|
|
108
143
|
| `quota.sdk_limit` | `int` | Daily SDK limit (-1 = unlimited) |
|
|
109
144
|
| `quota.sdk_remaining` | `int` | Remaining SDK requests (-1 = unlimited) |
|
|
110
145
|
| `quota.sdk_rate_limit` | `int` | Max requests per minute |
|
|
111
|
-
| `quota.chat_used_today` | `int` | Chat messages used today |
|
|
112
|
-
| `quota.chat_limit` | `int` | Daily chat limit |
|
|
113
|
-
| `quota.chat_rate_limit` | `int` | Chat rate limit per minute |
|
|
114
146
|
|
|
115
|
-
### `
|
|
147
|
+
### `client.ping() → bool`
|
|
116
148
|
|
|
117
149
|
Test if the API is reachable and the key is valid. Returns `True` or `False`.
|
|
118
150
|
|
|
@@ -127,7 +159,7 @@ Test if the API is reachable and the key is valid. Returns `True` or `False`.
|
|
|
127
159
|
## Error Handling
|
|
128
160
|
|
|
129
161
|
```python
|
|
130
|
-
from datacoder import
|
|
162
|
+
from datacoder import DataCoderClient
|
|
131
163
|
from datacoder.client import (
|
|
132
164
|
AuthenticationError,
|
|
133
165
|
QuotaExceededError,
|
|
@@ -136,10 +168,10 @@ from datacoder.client import (
|
|
|
136
168
|
DataCoderError,
|
|
137
169
|
)
|
|
138
170
|
|
|
139
|
-
|
|
171
|
+
client = DataCoderClient(api_key="dc_sk_...", base_url="https://...")
|
|
140
172
|
|
|
141
173
|
try:
|
|
142
|
-
|
|
174
|
+
results = client.search("Ma question", folder_id="...")
|
|
143
175
|
except AuthenticationError:
|
|
144
176
|
print("Invalid or expired API key")
|
|
145
177
|
except QuotaExceededError as e:
|
|
@@ -152,6 +184,23 @@ except DataCoderError as e:
|
|
|
152
184
|
print(f"API error: {e} (HTTP {e.status_code})")
|
|
153
185
|
```
|
|
154
186
|
|
|
187
|
+
## Migration from 0.2.x
|
|
188
|
+
|
|
189
|
+
The class `DataCoder` has been renamed to `DataCoderClient` in 0.3.0.
|
|
190
|
+
The old name still works as an alias for backward compatibility.
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
# Old (still works)
|
|
194
|
+
from datacoder import DataCoder
|
|
195
|
+
sdk = DataCoder(api_key="...")
|
|
196
|
+
|
|
197
|
+
# New (recommended)
|
|
198
|
+
from datacoder import DataCoderClient
|
|
199
|
+
client = DataCoderClient(api_key="...")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
New in 0.3.0: `client.search()` returns a flat list of `SearchResult` objects — simpler for most use cases.
|
|
203
|
+
|
|
155
204
|
## Get your SDK Key
|
|
156
205
|
|
|
157
206
|
1. Log in to [DataCoder](https://datacoder.clouditia.com)
|
|
@@ -164,7 +213,7 @@ except DataCoderError as e:
|
|
|
164
213
|
DataCoder can be deployed on your own infrastructure. Point `base_url` to your self-hosted instance:
|
|
165
214
|
|
|
166
215
|
```python
|
|
167
|
-
|
|
216
|
+
client = DataCoderClient(
|
|
168
217
|
api_key="dc_sk_...",
|
|
169
218
|
base_url="https://datacoder.your-company.com",
|
|
170
219
|
)
|
|
@@ -13,37 +13,51 @@ pip install datacoder
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
15
|
```python
|
|
16
|
-
from datacoder import
|
|
16
|
+
from datacoder import DataCoderClient
|
|
17
17
|
|
|
18
18
|
# Initialize with your SDK key and server URL
|
|
19
|
-
|
|
19
|
+
client = DataCoderClient(
|
|
20
20
|
api_key="dc_sk_your_key_here",
|
|
21
21
|
base_url="https://datacoder.clouditia.com",
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
# Test connectivity
|
|
25
|
-
if
|
|
25
|
+
if client.ping():
|
|
26
26
|
print("Connected!")
|
|
27
27
|
|
|
28
|
-
#
|
|
29
|
-
|
|
28
|
+
# Search a knowledge base
|
|
29
|
+
results = client.search("Quels sont les risques de credit ?")
|
|
30
|
+
for r in results:
|
|
31
|
+
print(r.content, r.source, r.score)
|
|
32
|
+
|
|
33
|
+
# Search in a specific folder
|
|
34
|
+
results = client.search(
|
|
35
|
+
"Clause de resiliation",
|
|
30
36
|
folder_id="your-folder-uuid",
|
|
31
|
-
query="Quels sont les risques de crédit dans Bâle III ?",
|
|
32
37
|
)
|
|
33
38
|
|
|
39
|
+
# Full query with RAGResult
|
|
40
|
+
result = client.query(
|
|
41
|
+
folder_id="your-folder-uuid",
|
|
42
|
+
query="Quels sont les risques de credit dans Bale III ?",
|
|
43
|
+
)
|
|
34
44
|
print(result.answer) # Combined text from all matching chunks
|
|
35
45
|
print(result.sources) # List of source document names
|
|
36
|
-
print(result.count) # Number of results
|
|
37
46
|
|
|
38
47
|
# Check your quota
|
|
39
|
-
quota =
|
|
48
|
+
quota = client.quota()
|
|
40
49
|
print(f"Plan: {quota.plan}")
|
|
41
50
|
print(f"SDK remaining today: {quota.sdk_remaining}")
|
|
51
|
+
|
|
52
|
+
# List accessible folders
|
|
53
|
+
folders = client.folders()
|
|
54
|
+
for f in folders:
|
|
55
|
+
print(f["name"], f["id"])
|
|
42
56
|
```
|
|
43
57
|
|
|
44
58
|
## API Reference
|
|
45
59
|
|
|
46
|
-
### `
|
|
60
|
+
### `DataCoderClient(api_key, base_url, timeout=30)`
|
|
47
61
|
|
|
48
62
|
Initialize the SDK client.
|
|
49
63
|
|
|
@@ -53,9 +67,28 @@ Initialize the SDK client.
|
|
|
53
67
|
| `base_url` | `str` | `https://datacoder.clouditia.com` | DataCoder server URL |
|
|
54
68
|
| `timeout` | `int` | `30` | Request timeout in seconds |
|
|
55
69
|
|
|
56
|
-
### `
|
|
70
|
+
### `client.search(query, folder_id=None, top_k=10) → list[SearchResult]`
|
|
57
71
|
|
|
58
|
-
|
|
72
|
+
Search a RAG knowledge base. Returns a list of results.
|
|
73
|
+
|
|
74
|
+
| Parameter | Type | Default | Description |
|
|
75
|
+
|-----------|------|---------|-------------|
|
|
76
|
+
| `query` | `str` | — | Natural language question |
|
|
77
|
+
| `folder_id` | `str` | `None` | UUID of the knowledge folder (None = all folders) |
|
|
78
|
+
| `top_k` | `int` | `10` | Max results (1-20) |
|
|
79
|
+
|
|
80
|
+
**Returns:** `list[SearchResult]`
|
|
81
|
+
|
|
82
|
+
| Property | Type | Description |
|
|
83
|
+
|----------|------|-------------|
|
|
84
|
+
| `r.content` | `str` | Matching text chunk |
|
|
85
|
+
| `r.source` | `str` | Source document name |
|
|
86
|
+
| `r.score` | `float` | Similarity score (0-1) |
|
|
87
|
+
| `r.page` | `int \| None` | Page number in source document |
|
|
88
|
+
|
|
89
|
+
### `client.query(folder_id, query, top_k=10) → RAGResult`
|
|
90
|
+
|
|
91
|
+
Full RAG query with aggregated results.
|
|
59
92
|
|
|
60
93
|
| Parameter | Type | Default | Description |
|
|
61
94
|
|-----------|------|---------|-------------|
|
|
@@ -69,12 +102,14 @@ Query a RAG knowledge base.
|
|
|
69
102
|
|----------|------|-------------|
|
|
70
103
|
| `result.answer` | `str` | Concatenated content from all matching chunks |
|
|
71
104
|
| `result.sources` | `list[str]` | Source document names |
|
|
105
|
+
| `result.items` | `list[SearchResult]` | Results as SearchResult objects |
|
|
72
106
|
| `result.count` | `int` | Number of results |
|
|
73
|
-
| `result.results` | `list[dict]` | Raw results with `content`, `source`, `page`, `score` |
|
|
74
|
-
| `result.query` | `str` | Original query |
|
|
75
|
-
| `result.folder_id` | `str` | Folder queried |
|
|
76
107
|
|
|
77
|
-
### `
|
|
108
|
+
### `client.folders() → list[dict]`
|
|
109
|
+
|
|
110
|
+
List knowledge folders accessible by this API key.
|
|
111
|
+
|
|
112
|
+
### `client.quota() → QuotaInfo`
|
|
78
113
|
|
|
79
114
|
Check current usage and limits.
|
|
80
115
|
|
|
@@ -85,11 +120,8 @@ Check current usage and limits.
|
|
|
85
120
|
| `quota.sdk_limit` | `int` | Daily SDK limit (-1 = unlimited) |
|
|
86
121
|
| `quota.sdk_remaining` | `int` | Remaining SDK requests (-1 = unlimited) |
|
|
87
122
|
| `quota.sdk_rate_limit` | `int` | Max requests per minute |
|
|
88
|
-
| `quota.chat_used_today` | `int` | Chat messages used today |
|
|
89
|
-
| `quota.chat_limit` | `int` | Daily chat limit |
|
|
90
|
-
| `quota.chat_rate_limit` | `int` | Chat rate limit per minute |
|
|
91
123
|
|
|
92
|
-
### `
|
|
124
|
+
### `client.ping() → bool`
|
|
93
125
|
|
|
94
126
|
Test if the API is reachable and the key is valid. Returns `True` or `False`.
|
|
95
127
|
|
|
@@ -104,7 +136,7 @@ Test if the API is reachable and the key is valid. Returns `True` or `False`.
|
|
|
104
136
|
## Error Handling
|
|
105
137
|
|
|
106
138
|
```python
|
|
107
|
-
from datacoder import
|
|
139
|
+
from datacoder import DataCoderClient
|
|
108
140
|
from datacoder.client import (
|
|
109
141
|
AuthenticationError,
|
|
110
142
|
QuotaExceededError,
|
|
@@ -113,10 +145,10 @@ from datacoder.client import (
|
|
|
113
145
|
DataCoderError,
|
|
114
146
|
)
|
|
115
147
|
|
|
116
|
-
|
|
148
|
+
client = DataCoderClient(api_key="dc_sk_...", base_url="https://...")
|
|
117
149
|
|
|
118
150
|
try:
|
|
119
|
-
|
|
151
|
+
results = client.search("Ma question", folder_id="...")
|
|
120
152
|
except AuthenticationError:
|
|
121
153
|
print("Invalid or expired API key")
|
|
122
154
|
except QuotaExceededError as e:
|
|
@@ -129,6 +161,23 @@ except DataCoderError as e:
|
|
|
129
161
|
print(f"API error: {e} (HTTP {e.status_code})")
|
|
130
162
|
```
|
|
131
163
|
|
|
164
|
+
## Migration from 0.2.x
|
|
165
|
+
|
|
166
|
+
The class `DataCoder` has been renamed to `DataCoderClient` in 0.3.0.
|
|
167
|
+
The old name still works as an alias for backward compatibility.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
# Old (still works)
|
|
171
|
+
from datacoder import DataCoder
|
|
172
|
+
sdk = DataCoder(api_key="...")
|
|
173
|
+
|
|
174
|
+
# New (recommended)
|
|
175
|
+
from datacoder import DataCoderClient
|
|
176
|
+
client = DataCoderClient(api_key="...")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
New in 0.3.0: `client.search()` returns a flat list of `SearchResult` objects — simpler for most use cases.
|
|
180
|
+
|
|
132
181
|
## Get your SDK Key
|
|
133
182
|
|
|
134
183
|
1. Log in to [DataCoder](https://datacoder.clouditia.com)
|
|
@@ -141,7 +190,7 @@ except DataCoderError as e:
|
|
|
141
190
|
DataCoder can be deployed on your own infrastructure. Point `base_url` to your self-hosted instance:
|
|
142
191
|
|
|
143
192
|
```python
|
|
144
|
-
|
|
193
|
+
client = DataCoderClient(
|
|
145
194
|
api_key="dc_sk_...",
|
|
146
195
|
base_url="https://datacoder.your-company.com",
|
|
147
196
|
)
|
|
@@ -8,6 +8,21 @@ from typing import Any
|
|
|
8
8
|
import requests
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
@dataclass
|
|
12
|
+
class SearchResult:
|
|
13
|
+
"""A single search result from the RAG knowledge base."""
|
|
14
|
+
|
|
15
|
+
content: str
|
|
16
|
+
source: str
|
|
17
|
+
score: float
|
|
18
|
+
page: int | None = None
|
|
19
|
+
chunk_index: int | None = None
|
|
20
|
+
|
|
21
|
+
def __repr__(self) -> str:
|
|
22
|
+
page_str = f", p.{self.page}" if self.page else ""
|
|
23
|
+
return f"SearchResult(source='{self.source}'{page_str}, score={self.score:.3f})"
|
|
24
|
+
|
|
25
|
+
|
|
11
26
|
@dataclass
|
|
12
27
|
class RAGResult:
|
|
13
28
|
"""Result from a RAG query."""
|
|
@@ -27,6 +42,20 @@ class RAGResult:
|
|
|
27
42
|
"""List of source document names."""
|
|
28
43
|
return [r.get("source", "") for r in self.results if r.get("source")]
|
|
29
44
|
|
|
45
|
+
@property
|
|
46
|
+
def items(self) -> list[SearchResult]:
|
|
47
|
+
"""Results as SearchResult objects."""
|
|
48
|
+
return [
|
|
49
|
+
SearchResult(
|
|
50
|
+
content=r.get("content", ""),
|
|
51
|
+
source=r.get("source", ""),
|
|
52
|
+
score=r.get("score", r.get("similarity_score", 0.0)),
|
|
53
|
+
page=r.get("page_number"),
|
|
54
|
+
chunk_index=r.get("chunk_index"),
|
|
55
|
+
)
|
|
56
|
+
for r in self.results
|
|
57
|
+
]
|
|
58
|
+
|
|
30
59
|
def __repr__(self) -> str:
|
|
31
60
|
return f"RAGResult(count={self.count}, sources={self.sources[:3]})"
|
|
32
61
|
|
|
@@ -84,29 +113,34 @@ class ForbiddenError(DataCoderError):
|
|
|
84
113
|
|
|
85
114
|
|
|
86
115
|
@dataclass
|
|
87
|
-
class
|
|
116
|
+
class DataCoderClient:
|
|
88
117
|
"""DataCoder — programmatic access to RAG knowledge bases.
|
|
89
118
|
|
|
90
119
|
Usage::
|
|
91
120
|
|
|
92
|
-
from datacoder import
|
|
121
|
+
from datacoder import DataCoderClient
|
|
93
122
|
|
|
94
|
-
|
|
123
|
+
client = DataCoderClient(
|
|
95
124
|
api_key="dc_sk_...",
|
|
96
125
|
base_url="https://datacoder.clouditia.com",
|
|
97
126
|
)
|
|
98
127
|
|
|
99
|
-
#
|
|
100
|
-
|
|
128
|
+
# Search a knowledge base
|
|
129
|
+
results = client.search("What are the risks?", folder_id="xxx-xxx")
|
|
130
|
+
for r in results:
|
|
131
|
+
print(r.content, r.source, r.score)
|
|
132
|
+
|
|
133
|
+
# Full query with RAGResult
|
|
134
|
+
result = client.query(folder_id="xxx-xxx", query="What are the risks?")
|
|
101
135
|
print(result.answer)
|
|
102
136
|
print(result.sources)
|
|
103
137
|
|
|
104
138
|
# Check quota
|
|
105
|
-
quota =
|
|
139
|
+
quota = client.quota()
|
|
106
140
|
print(f"Remaining: {quota.sdk_remaining}")
|
|
107
141
|
|
|
108
142
|
# List accessible folders
|
|
109
|
-
folders =
|
|
143
|
+
folders = client.folders()
|
|
110
144
|
"""
|
|
111
145
|
|
|
112
146
|
api_key: str
|
|
@@ -119,7 +153,7 @@ class DataCoder:
|
|
|
119
153
|
self._session.headers.update({
|
|
120
154
|
"Authorization": f"Bearer {self.api_key}",
|
|
121
155
|
"Content-Type": "application/json",
|
|
122
|
-
"User-Agent":
|
|
156
|
+
"User-Agent": "datacoder-python/0.3.0",
|
|
123
157
|
})
|
|
124
158
|
|
|
125
159
|
def _request(self, method: str, path: str, **kwargs) -> dict:
|
|
@@ -170,16 +204,19 @@ class DataCoder:
|
|
|
170
204
|
|
|
171
205
|
return resp.json()
|
|
172
206
|
|
|
173
|
-
def
|
|
174
|
-
|
|
207
|
+
def search(
|
|
208
|
+
self, query: str, folder_id: str | None = None, top_k: int = 10
|
|
209
|
+
) -> list[SearchResult]:
|
|
210
|
+
"""Search a RAG knowledge base.
|
|
175
211
|
|
|
176
212
|
Args:
|
|
177
|
-
folder_id: UUID of the knowledge folder to search.
|
|
178
213
|
query: Natural language question.
|
|
214
|
+
folder_id: UUID of the knowledge folder to search.
|
|
215
|
+
If None, searches all folders accessible by the API key.
|
|
179
216
|
top_k: Maximum number of results (1-20, default 10).
|
|
180
217
|
|
|
181
218
|
Returns:
|
|
182
|
-
|
|
219
|
+
List of SearchResult with content, source, score and page number.
|
|
183
220
|
|
|
184
221
|
Raises:
|
|
185
222
|
AuthenticationError: Invalid API key.
|
|
@@ -187,6 +224,36 @@ class DataCoder:
|
|
|
187
224
|
ForbiddenError: API key doesn't have access to this folder.
|
|
188
225
|
NotFoundError: Folder not found.
|
|
189
226
|
"""
|
|
227
|
+
payload: dict[str, Any] = {
|
|
228
|
+
"query": query,
|
|
229
|
+
"top_k": min(max(1, top_k), 20),
|
|
230
|
+
}
|
|
231
|
+
if folder_id:
|
|
232
|
+
payload["folder_id"] = str(folder_id)
|
|
233
|
+
|
|
234
|
+
data = self._request("POST", "/sdk/rag/query/", json=payload)
|
|
235
|
+
return [
|
|
236
|
+
SearchResult(
|
|
237
|
+
content=r.get("content", ""),
|
|
238
|
+
source=r.get("source", ""),
|
|
239
|
+
score=r.get("score", r.get("similarity_score", 0.0)),
|
|
240
|
+
page=r.get("page_number"),
|
|
241
|
+
chunk_index=r.get("chunk_index"),
|
|
242
|
+
)
|
|
243
|
+
for r in data.get("results", [])
|
|
244
|
+
]
|
|
245
|
+
|
|
246
|
+
def query(self, folder_id: str, query: str, top_k: int = 10) -> RAGResult:
|
|
247
|
+
"""Query a RAG knowledge base (returns full RAGResult).
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
folder_id: UUID of the knowledge folder to search.
|
|
251
|
+
query: Natural language question.
|
|
252
|
+
top_k: Maximum number of results (1-20, default 10).
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
RAGResult with matching chunks, sources and scores.
|
|
256
|
+
"""
|
|
190
257
|
data = self._request("POST", "/sdk/rag/query/", json={
|
|
191
258
|
"folder_id": str(folder_id),
|
|
192
259
|
"query": query,
|
|
@@ -199,6 +266,15 @@ class DataCoder:
|
|
|
199
266
|
count=data.get("count", 0),
|
|
200
267
|
)
|
|
201
268
|
|
|
269
|
+
def folders(self) -> list[dict[str, Any]]:
|
|
270
|
+
"""List knowledge folders accessible by this API key.
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
List of folder dicts with id, name, document_count.
|
|
274
|
+
"""
|
|
275
|
+
data = self._request("GET", "/sdk/folders/")
|
|
276
|
+
return data if isinstance(data, list) else data.get("results", [])
|
|
277
|
+
|
|
202
278
|
def quota(self) -> QuotaInfo:
|
|
203
279
|
"""Check current quota usage.
|
|
204
280
|
|
|
@@ -229,3 +305,7 @@ class DataCoder:
|
|
|
229
305
|
return True
|
|
230
306
|
except DataCoderError:
|
|
231
307
|
return False
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
# Backward compatibility
|
|
311
|
+
DataCoder = DataCoderClient
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datacoder
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python SDK for DataCoder — AI Data Analyst Platform (RAG API)
|
|
5
5
|
Author-email: Clouditia <contact@clouditia.com>
|
|
6
6
|
License: MIT
|
|
@@ -36,37 +36,51 @@ pip install datacoder
|
|
|
36
36
|
## Quick Start
|
|
37
37
|
|
|
38
38
|
```python
|
|
39
|
-
from datacoder import
|
|
39
|
+
from datacoder import DataCoderClient
|
|
40
40
|
|
|
41
41
|
# Initialize with your SDK key and server URL
|
|
42
|
-
|
|
42
|
+
client = DataCoderClient(
|
|
43
43
|
api_key="dc_sk_your_key_here",
|
|
44
44
|
base_url="https://datacoder.clouditia.com",
|
|
45
45
|
)
|
|
46
46
|
|
|
47
47
|
# Test connectivity
|
|
48
|
-
if
|
|
48
|
+
if client.ping():
|
|
49
49
|
print("Connected!")
|
|
50
50
|
|
|
51
|
-
#
|
|
52
|
-
|
|
51
|
+
# Search a knowledge base
|
|
52
|
+
results = client.search("Quels sont les risques de credit ?")
|
|
53
|
+
for r in results:
|
|
54
|
+
print(r.content, r.source, r.score)
|
|
55
|
+
|
|
56
|
+
# Search in a specific folder
|
|
57
|
+
results = client.search(
|
|
58
|
+
"Clause de resiliation",
|
|
53
59
|
folder_id="your-folder-uuid",
|
|
54
|
-
query="Quels sont les risques de crédit dans Bâle III ?",
|
|
55
60
|
)
|
|
56
61
|
|
|
62
|
+
# Full query with RAGResult
|
|
63
|
+
result = client.query(
|
|
64
|
+
folder_id="your-folder-uuid",
|
|
65
|
+
query="Quels sont les risques de credit dans Bale III ?",
|
|
66
|
+
)
|
|
57
67
|
print(result.answer) # Combined text from all matching chunks
|
|
58
68
|
print(result.sources) # List of source document names
|
|
59
|
-
print(result.count) # Number of results
|
|
60
69
|
|
|
61
70
|
# Check your quota
|
|
62
|
-
quota =
|
|
71
|
+
quota = client.quota()
|
|
63
72
|
print(f"Plan: {quota.plan}")
|
|
64
73
|
print(f"SDK remaining today: {quota.sdk_remaining}")
|
|
74
|
+
|
|
75
|
+
# List accessible folders
|
|
76
|
+
folders = client.folders()
|
|
77
|
+
for f in folders:
|
|
78
|
+
print(f["name"], f["id"])
|
|
65
79
|
```
|
|
66
80
|
|
|
67
81
|
## API Reference
|
|
68
82
|
|
|
69
|
-
### `
|
|
83
|
+
### `DataCoderClient(api_key, base_url, timeout=30)`
|
|
70
84
|
|
|
71
85
|
Initialize the SDK client.
|
|
72
86
|
|
|
@@ -76,9 +90,28 @@ Initialize the SDK client.
|
|
|
76
90
|
| `base_url` | `str` | `https://datacoder.clouditia.com` | DataCoder server URL |
|
|
77
91
|
| `timeout` | `int` | `30` | Request timeout in seconds |
|
|
78
92
|
|
|
79
|
-
### `
|
|
93
|
+
### `client.search(query, folder_id=None, top_k=10) → list[SearchResult]`
|
|
80
94
|
|
|
81
|
-
|
|
95
|
+
Search a RAG knowledge base. Returns a list of results.
|
|
96
|
+
|
|
97
|
+
| Parameter | Type | Default | Description |
|
|
98
|
+
|-----------|------|---------|-------------|
|
|
99
|
+
| `query` | `str` | — | Natural language question |
|
|
100
|
+
| `folder_id` | `str` | `None` | UUID of the knowledge folder (None = all folders) |
|
|
101
|
+
| `top_k` | `int` | `10` | Max results (1-20) |
|
|
102
|
+
|
|
103
|
+
**Returns:** `list[SearchResult]`
|
|
104
|
+
|
|
105
|
+
| Property | Type | Description |
|
|
106
|
+
|----------|------|-------------|
|
|
107
|
+
| `r.content` | `str` | Matching text chunk |
|
|
108
|
+
| `r.source` | `str` | Source document name |
|
|
109
|
+
| `r.score` | `float` | Similarity score (0-1) |
|
|
110
|
+
| `r.page` | `int \| None` | Page number in source document |
|
|
111
|
+
|
|
112
|
+
### `client.query(folder_id, query, top_k=10) → RAGResult`
|
|
113
|
+
|
|
114
|
+
Full RAG query with aggregated results.
|
|
82
115
|
|
|
83
116
|
| Parameter | Type | Default | Description |
|
|
84
117
|
|-----------|------|---------|-------------|
|
|
@@ -92,12 +125,14 @@ Query a RAG knowledge base.
|
|
|
92
125
|
|----------|------|-------------|
|
|
93
126
|
| `result.answer` | `str` | Concatenated content from all matching chunks |
|
|
94
127
|
| `result.sources` | `list[str]` | Source document names |
|
|
128
|
+
| `result.items` | `list[SearchResult]` | Results as SearchResult objects |
|
|
95
129
|
| `result.count` | `int` | Number of results |
|
|
96
|
-
| `result.results` | `list[dict]` | Raw results with `content`, `source`, `page`, `score` |
|
|
97
|
-
| `result.query` | `str` | Original query |
|
|
98
|
-
| `result.folder_id` | `str` | Folder queried |
|
|
99
130
|
|
|
100
|
-
### `
|
|
131
|
+
### `client.folders() → list[dict]`
|
|
132
|
+
|
|
133
|
+
List knowledge folders accessible by this API key.
|
|
134
|
+
|
|
135
|
+
### `client.quota() → QuotaInfo`
|
|
101
136
|
|
|
102
137
|
Check current usage and limits.
|
|
103
138
|
|
|
@@ -108,11 +143,8 @@ Check current usage and limits.
|
|
|
108
143
|
| `quota.sdk_limit` | `int` | Daily SDK limit (-1 = unlimited) |
|
|
109
144
|
| `quota.sdk_remaining` | `int` | Remaining SDK requests (-1 = unlimited) |
|
|
110
145
|
| `quota.sdk_rate_limit` | `int` | Max requests per minute |
|
|
111
|
-
| `quota.chat_used_today` | `int` | Chat messages used today |
|
|
112
|
-
| `quota.chat_limit` | `int` | Daily chat limit |
|
|
113
|
-
| `quota.chat_rate_limit` | `int` | Chat rate limit per minute |
|
|
114
146
|
|
|
115
|
-
### `
|
|
147
|
+
### `client.ping() → bool`
|
|
116
148
|
|
|
117
149
|
Test if the API is reachable and the key is valid. Returns `True` or `False`.
|
|
118
150
|
|
|
@@ -127,7 +159,7 @@ Test if the API is reachable and the key is valid. Returns `True` or `False`.
|
|
|
127
159
|
## Error Handling
|
|
128
160
|
|
|
129
161
|
```python
|
|
130
|
-
from datacoder import
|
|
162
|
+
from datacoder import DataCoderClient
|
|
131
163
|
from datacoder.client import (
|
|
132
164
|
AuthenticationError,
|
|
133
165
|
QuotaExceededError,
|
|
@@ -136,10 +168,10 @@ from datacoder.client import (
|
|
|
136
168
|
DataCoderError,
|
|
137
169
|
)
|
|
138
170
|
|
|
139
|
-
|
|
171
|
+
client = DataCoderClient(api_key="dc_sk_...", base_url="https://...")
|
|
140
172
|
|
|
141
173
|
try:
|
|
142
|
-
|
|
174
|
+
results = client.search("Ma question", folder_id="...")
|
|
143
175
|
except AuthenticationError:
|
|
144
176
|
print("Invalid or expired API key")
|
|
145
177
|
except QuotaExceededError as e:
|
|
@@ -152,6 +184,23 @@ except DataCoderError as e:
|
|
|
152
184
|
print(f"API error: {e} (HTTP {e.status_code})")
|
|
153
185
|
```
|
|
154
186
|
|
|
187
|
+
## Migration from 0.2.x
|
|
188
|
+
|
|
189
|
+
The class `DataCoder` has been renamed to `DataCoderClient` in 0.3.0.
|
|
190
|
+
The old name still works as an alias for backward compatibility.
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
# Old (still works)
|
|
194
|
+
from datacoder import DataCoder
|
|
195
|
+
sdk = DataCoder(api_key="...")
|
|
196
|
+
|
|
197
|
+
# New (recommended)
|
|
198
|
+
from datacoder import DataCoderClient
|
|
199
|
+
client = DataCoderClient(api_key="...")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
New in 0.3.0: `client.search()` returns a flat list of `SearchResult` objects — simpler for most use cases.
|
|
203
|
+
|
|
155
204
|
## Get your SDK Key
|
|
156
205
|
|
|
157
206
|
1. Log in to [DataCoder](https://datacoder.clouditia.com)
|
|
@@ -164,7 +213,7 @@ except DataCoderError as e:
|
|
|
164
213
|
DataCoder can be deployed on your own infrastructure. Point `base_url` to your self-hosted instance:
|
|
165
214
|
|
|
166
215
|
```python
|
|
167
|
-
|
|
216
|
+
client = DataCoderClient(
|
|
168
217
|
api_key="dc_sk_...",
|
|
169
218
|
base_url="https://datacoder.your-company.com",
|
|
170
219
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|