Skip to content

Commit 9829252

Browse files
authored
xet protocol files (#1963)
* xet protocol file and CI setup * xet-protocol -> xet
1 parent 3301e27 commit 9829252

16 files changed

+2387
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build Xet documentation
2+
3+
on:
4+
push:
5+
paths:
6+
- "docs/xet/**"
7+
branches:
8+
- main
9+
10+
jobs:
11+
build:
12+
uses: huggingface/doc-builder/.github/workflows/build_main_documentation.yml@main
13+
with:
14+
commit_sha: ${{ github.sha }}
15+
package: hub-docs
16+
package_name: xet
17+
path_to_docs: hub-docs/docs/xet/
18+
additional_args: --not_python_module
19+
secrets:
20+
hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build Xet PR Documentation
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "docs/xet/**"
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
build:
14+
uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml@main
15+
with:
16+
commit_sha: ${{ github.event.pull_request.head.sha }}
17+
pr_number: ${{ github.event.number }}
18+
package: hub-docs
19+
package_name: xet
20+
path_to_docs: hub-docs/docs/xet/
21+
additional_args: --not_python_module
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Upload Xet PR Documentation
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build Xet PR Documentation"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
build:
11+
uses: huggingface/doc-builder/.github/workflows/upload_pr_documentation.yml@main
12+
with:
13+
package_name: xet
14+
secrets:
15+
hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }}
16+
comment_bot_token: ${{ secrets.COMMENT_BOT_TOKEN }}

docs/xet/_toctree.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- local: index
2+
title: Xet Protocol Specification
3+
4+
- title: Building a client library for xet storage
5+
sections:
6+
- local: upload-protocol
7+
title: Upload Protocol
8+
- local: download-protocol
9+
title: Download Protocol
10+
- local: api
11+
title: CAS API
12+
- local: auth
13+
title: Authentication and Authorization
14+
- local: file-id
15+
title: Hugging Face Hub Files Conversion to Xet File ID's
16+
17+
- title: Overall Xet architecture
18+
sections:
19+
- local: chunking
20+
title: Content-Defined Chunking
21+
- local: hashing
22+
title: Hashing Methods
23+
- local: file-reconstruction
24+
title: File Reconstruction
25+
- local: xorb
26+
title: Xorb Format
27+
- local: shard
28+
title: Shard Format
29+
- local: deduplication
30+
title: Deduplication

docs/xet/api.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# CAS API Documentation
2+
3+
This document describes the HTTP API endpoints used by the Content Addressable Storage (CAS) client to interact with the remote CAS server.
4+
5+
## Authentication
6+
7+
To authenticate, authorize, and obtain the API base URL, follow the instructions in [Authentication](./auth).
8+
9+
## Converting Hashes to Strings
10+
11+
Sometimes hashes are used in API paths as hexadecimal strings (reconstruction, xorb upload, global dedupe API).
12+
13+
To convert a 32 hash to a 64 hexadecimal character string to be used as part of an API path there is a specific procedure, MUST NOT directly convert each byte.
14+
15+
### Procedure
16+
17+
For every 8 bytes in the hash (indices 0-7, 8-15, 16-23, 24-31) reverse the order of each byte in those regions then concatenate the regions back in order.
18+
19+
Otherwise stated, consider each 8 byte part of a hash as a little endian 64 bit unsigned integer, then concatenate the hexadecimal representation of the 4 numbers in order (each padded with 0's to 16 characters).
20+
21+
> [!NOTE]
22+
> In all cases that a hash is represented as a string it is converted from a byte array to a string using this procedure.
23+
24+
### Example
25+
26+
Suppose a hash value is:
27+
`[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]`
28+
29+
Then before converting to a string it will first have its bytes reordered to:
30+
`[7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24]`
31+
32+
So the string value of the the provided hash [0..32] is **NOT** `000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f`.
33+
It is: `07060504030201000f0e0d0c0b0a0908171615141312111f1e1d1c1b1a1918`.
34+
35+
## Endpoints
36+
37+
### 1. Get File Reconstruction
38+
39+
- **Description**: Retrieves reconstruction information for a specific file, includes byte range support when `Range` header is set.
40+
- **Path**: `/v1/reconstructions/{file_id}`
41+
- **Method**: `GET`
42+
- **Parameters**:
43+
- `file_id`: File hash in hex format (64 lowercase hexadecimal characters).
44+
See [file hashes](./hashing#file-hashes) for computing the file hash and [converting hashes to strings](./api#converting-hashes-to-strings).
45+
- **Headers**:
46+
- `Range`: OPTIONAL. Format: `bytes={start}-{end}` (end is inclusive).
47+
- **Minimum Token Scope**: `read`
48+
- **Body**: None.
49+
- **Response**: JSON (`QueryReconstructionResponse`)
50+
51+
```json
52+
{
53+
"offset_into_first_range": 0,
54+
"terms": [...],
55+
"fetch_info": {...}
56+
}
57+
```
58+
59+
- **Error Responses**: See [Error Cases](./api#error-cases)
60+
- `400 Bad Request`: Malformed `file_id` in the path. Fix the path before retrying.
61+
- `401 Unauthorized`: Refresh the token to continue making requests, or provide a token in the `Authorization` header.
62+
- `404 Not Found`: The file does not exist. Not retryable.
63+
- `416 Range Not Satisfiable`: The requested byte range start exceeds the end of the file. Not retryable.
64+
65+
```txt
66+
GET /v1/reconstructions/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
67+
-H "Authorization: Bearer <token>"
68+
OPTIONAL: -H Range: "bytes=0-100000"
69+
```
70+
71+
### Example File Reconstruction Response Body
72+
73+
See [QueryReconstructionResponse](./download-protocol#queryreconstructionresponse-structure) for more details in the download protocol specification.
74+
75+
### 2. Query Chunk Deduplication (Global Deduplication)
76+
77+
- **Description**: Checks if a chunk exists in the CAS for deduplication purposes.
78+
- **Path**: `/v1/chunks/{prefix}/{hash}`
79+
- **Method**: `GET`
80+
- **Parameters**:
81+
- `prefix`: The only acceptable prefix for the Global Deduplication API is `default-merkledb`.
82+
- `hash`: Chunk hash in hex format (64 lowercase hexadecimal characters).
83+
See [Chunk Hashes](./hashing#chunk-hashes) to compute the chunk hash and [converting hashes to strings](./api#converting-hashes-to-strings).
84+
- **Minimum Token Scope**: `read`
85+
- **Body**: None.
86+
- **Response**: Shard format bytes (`application/octet-stream`), deserialize as a [shard](./shard#global-deduplication).
87+
- **Error Responses**: See [Error Cases](./api#error-cases)
88+
- `400 Bad Request`: Malformed hash in the path. Fix the path before retrying.
89+
- `401 Unauthorized`: Refresh the token to continue making requests, or provide a token in the `Authorization` header.
90+
- `404 Not Found`: Chunk not already tracked by global deduplication. Not retryable.
91+
92+
```txt
93+
GET /v1/chunks/default-merkledb/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
94+
-H "Authorization: Bearer <token>"
95+
```
96+
97+
#### Example Shard Response Body
98+
99+
An example shard response body can be found in [Xet reference files](https://huggingface.co/datasets/xet-team/xet-spec-reference-files/blob/main/Electric_Vehicle_Population_Data_20250917.csv.shard.dedupe).
100+
101+
### 3. Upload Xorb
102+
103+
- **Description**: Uploads a serialized Xorb to the server; uploading real data in serialized format.
104+
- **Path**: `/v1/xorbs/{prefix}/{hash}`
105+
- **Method**: `POST`
106+
- **Parameters**:
107+
- `prefix`: The only acceptable prefix for the Xorb upload API is `default`.
108+
- `hash`: Xorb hash in hex format (64 lowercase hexadecimal characters).
109+
See [Xorb Hashes](./hashing#xorb-hashes) to compute the hash, and [converting hashes to strings](./api#converting-hashes-to-strings).
110+
- **Minimum Token Scope**: `write`
111+
- **Body**: Serialized Xorb bytes (`application/octet-stream`).
112+
See [xorb format serialization](./xorb).
113+
- **Response**: JSON (`UploadXorbResponse`)
114+
115+
```json
116+
{
117+
"was_inserted": true
118+
}
119+
```
120+
121+
- Note: `was_inserted` is `false` if the Xorb already exists; this is not an error.
122+
123+
- **Error Responses**: See [Error Cases](./api#error-cases)
124+
- `400 Bad Request`: Malformed hash in the path, Xorb hash does not match the body, or body is incorrectly serialized.
125+
- `401 Unauthorized`: Refresh the token to continue making requests, or provide a token in the `Authorization` header.
126+
- `403 Forbidden`: Token provided but does not have a wide enough scope (for example, a `read` token was provided). Clients MUST retry with a `write` scope token.
127+
128+
```txt
129+
POST /v1/xorbs/default/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
130+
-H "Authorization: Bearer <token>"
131+
```
132+
133+
#### Example Xorb Request Body
134+
135+
An example xorb request body can be found in [Xet reference files](https://huggingface.co/datasets/xet-team/xet-spec-reference-files/blob/main/eea25d6ee393ccae385820daed127b96ef0ea034dfb7cf6da3a950ce334b7632.xorb).
136+
137+
### 4. Upload Shard
138+
139+
- **Description**: Uploads a Shard to the CAS.
140+
Uploads file reconstructions and new xorb listing, serialized into the shard format; marks the files as uploaded.
141+
- **Path**: `/v1/shards`
142+
- **Method**: `POST`
143+
- **Minimum Token Scope**: `write`
144+
- **Body**: Serialized Shard data as bytes (`application/octet-stream`).
145+
See [Shard format guide](./shard#shard-upload).
146+
- **Response**: JSON (`UploadShardResponse`)
147+
148+
```json
149+
{
150+
"result": 0
151+
}
152+
```
153+
154+
- Where `result` is:
155+
- `0`: The Shard already exists.
156+
- `1`: `SyncPerformed` — the Shard was registered.
157+
158+
The value of `result` does not carry any meaning, if the upload shard API returns a `200 OK` status code, the upload was successful and the files listed are considered uploaded.
159+
160+
- **Error Responses**: See [Error Cases](./api#error-cases)
161+
- `400 Bad Request`: Shard is incorrectly serialized or Shard contents failed verification.
162+
- Can mean that a referenced Xorb doesn't exist or the shard is too large
163+
- `401 Unauthorized`: Refresh the token to continue making requests, or provide a token in the `Authorization` header.
164+
- `403 Forbidden`: Token provided but does not have a wide enough scope (for example, a `read` token was provided).
165+
166+
```txt
167+
POST /v1/shards
168+
-H "Authorization: Bearer <token>"
169+
```
170+
171+
#### Example Shard Request Body
172+
173+
An example shard request body can be found in [Xet reference files](https://huggingface.co/datasets/xet-team/xet-spec-reference-files/blob/main/Electric_Vehicle_Population_Data_20250917.csv.shard.verification-no-footer).
174+
175+
## Error Cases
176+
177+
### Non-Retryable Errors
178+
179+
- **400 Bad Request**: Returned when the request parameters are invalid (for example, invalid Xorb/Shard on upload APIs).
180+
- **401 Unauthorized**: Refresh the token to continue making requests, or provide a token in the `Authorization` header.
181+
- **403 Forbidden**: Token provided but does not have a wide enough scope (for example, a `read` token was provided for an API requiring `write` scope).
182+
- **404 Not Found**: Occurs on `GET` APIs where the resource (Xorb, file) does not exist.
183+
- **416 Range Not Satisfiable**: Reconstruction API only; returned when byte range requests are invalid. Specifically, the requested start range is greater than or equal to the length of the file.
184+
185+
### Retryable Errors
186+
187+
- **Connection Errors**: Often caused by network issues. Retry if intermittent.
188+
Clients SHOULD ensure no firewall blocks requests and SHOULD NOT use DNS overrides.
189+
- **429 Rate Limiting**: Lower your request rate using a backoff strategy, then wait and retry.
190+
Assume all APIs are rate limited.
191+
- **500 Internal Server Error**: The server experienced an intermittent issue; clients SHOULD retry their requests.
192+
- **503 Service Unavailable**: Service is temporarily unable to process requests; wait and retry.
193+
- **504 Gateway Timeout**: Service took too long to respond; wait and retry.

0 commit comments

Comments
 (0)