docs/en/api/99-api-doc-writing-guide.md
This document defines the unified structure and writing conventions for API module documentation in the docs/en/api/ directory.
API documentation is organized by module, with one file per module, using a two-digit numerical prefix.
Each API module documentation should follow the structure below:
# Module Name
Brief introduction explaining the main features and purpose of this module.
## Optional Concepts/Introduction Section
(If needed, explain core concepts, workflows, etc., related to this module)
## API Reference
### API Method Name 1
#### 1. API Implementation Introduction
Explain the purpose of this API, point to the corresponding code entry, and briefly describe the principles and workflow.
**Code Entry**:
- `openviking/<module>/<file>.py:<ClassName>.<MethodName>` - Core implementation
- `openviking/server/routers/<router-file>.py` - HTTP router
- `openviking_cli/commands/<command-file>.py` - CLI command
#### 2. Interface and Parameter Description
**Parameters**
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| <param-name> | <type> | <yes/no> | <default> | <detailed description> |
| ... | ... | ... | ... | ... |
**Optional Supplementary Section**
(If needed, explain special behaviors, considerations, usage scenarios, etc.)
#### 3. Usage Examples
**Python SDK**
```python
<SDK call example>
```
**TypeScript SDK**
```typescript
<SDK call example>
```
**Go SDK**
```go
<SDK call example>
```
**HTTP API**
```
<HTTP Method> <Path>
```
```bash
<curl example>
```
**CLI**
```bash
<CLI command example>
```
**Response Example**
```json
<JSON response example>
```
#### 4. Response Example, Error Handling, and Exception Handling (Optional)
---
### API Method Name 2
(Repeat the above structure)
---
## Optional Additional Sections
## Related Documentation
- [Document Title](<relative-path>) - <brief description>
Each API is organized in the following three parts:
Code Entry Notes:
When an operation presents all transports together, prefer this order:
For an existing operation with a workflow-specific structure, keep the local structure stable and place TypeScript next to the other SDK examples.
Keep API documentation organized around API modules and individual operations, not around client languages. SDK snippets should be short call examples inside the relevant operation's Usage Examples. Put language-specific quick references, walkthroughs, and combined workflows in that SDK's own documentation instead of adding language-owned sections to API module pages.
### add_resource()
#### 1. API Implementation Introduction
Add resources to the knowledge base, supporting various sources such as local files, directories, URLs, etc.
**Processing Workflow**:
1. Identify resource type (local file/directory/URL)
2. Call corresponding parser to parse content
3. Build directory tree and write to AGFS
4. Asynchronously generate L0/L1 semantic abstracts
5. Build vector index
**Code Entry**:
- `openviking/core/client.py:OpenViking.add_resource()` - SDK entry
- `openviking/resource/importer.py:ResourceImporter.import_resource()` - Core implementation
- `openviking/server/routers/resources.py` - HTTP router
- `openviking_cli/commands/resources.py` - CLI command
#### 2. Interface and Parameter Description
**Parameters**
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| path | str | Yes | - | Local path, directory path, or URL |
| to | str | No | None | Target Viking URI (must be within the resources scope) |
| reason | str | No | "" | Reason for adding this resource |
| wait | bool | No | False | Whether to wait for semantic processing completion |
**Notes**
- SDK/CLI can directly pass local paths; raw HTTP requires `temp_upload` first
- When `to` is specified and the target already exists, an incremental update process is used
#### 3. Usage Examples
**HTTP API**
```
POST /api/v1/resources
```
```bash
curl -X POST http://localhost:1933/api/v1/resources \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"path": "https://example.com/guide.md",
"reason": "User guide documentation",
"wait": true
}'
```
**Python SDK**
```python
import openviking as ov
client = ov.OpenViking(path="./data")
client.initialize()
result = client.add_resource(
"./documents/guide.md",
reason="User guide documentation"
)
print(f"Added: {result['root_uri']}")
client.wait_processed()
```
**CLI**
```bash
openviking add-resource ./documents/guide.md --reason "User guide documentation" --wait
```
**Response Example**
```json
{
"status": "ok",
"result": {
"status": "success",
"root_uri": "viking://resources/documents/guide.md",
"source_path": "./documents/guide.md",
"errors": []
},
"time": 0.123
}
```
---
When adding or modifying API documentation, please check: