2025-08-07 13:52:33 +08:00
# API Endpoints
This document describes the HTTP endpoints provided by the XControl server. Each entry lists the request method and path, required parameters, and a sample curl command for verification.
## GET /api/users
- **Description:** Return all users.
- **Parameters:** None.
- **Test:**
```bash
curl -s http://localhost:8080/api/users
```
## GET /api/nodes
- **Description:** Return all nodes.
- **Parameters:** None.
- **Test:**
```bash
curl -s http://localhost:8080/api/nodes
```
## POST /api/sync
- **Description:** Clone or update a knowledge repository.
- **Body Parameters (JSON):**
- `repo_url` – Git repository URL.
- `local_path` – Destination directory on the server.
- **Test:**
```bash
curl -X POST http://localhost:8080/api/sync \
-H "Content-Type: application/json" \
-d '{"repo_url": "https://github.com/example/repo.git", "local_path": "/tmp/repo"}'
```
## POST /api/rag/sync
2025-08-09 14:55:22 +08:00
- **Description:** Trigger RAG background synchronization. The endpoint streams
plain-text progress logs during the sync.
2025-08-07 13:52:33 +08:00
- **Parameters:** None.
- **Test:**
```bash
2025-08-09 14:55:22 +08:00
curl -N -X POST http://localhost:8080/api/rag/sync
2025-08-07 13:52:33 +08:00
```
2025-08-09 14:55:22 +08:00
- **Notes:** A future evolution could expose this operation via a gRPC
streaming RPC. That approach would allow high-speed synchronization, rate
limiting, and resumable transfers over long-lived connections while
supporting dynamic, lossless queues for weak networks.
2025-08-07 13:52:33 +08:00
2025-08-09 22:28:25 +08:00
## POST /api/rag/upsert
- **Description:** Upsert pre-embedded document chunks into the RAG database.
- **Body Parameters (JSON):**
- `docs` – Array of documents each containing `repo` , `path` , `chunk_id` , `content` , `embedding` , `metadata` , and `content_sha` .
- **Test:**
2025-08-10 13:18:51 +08:00
curl -X POST http://localhost:8080/api/rag/upsert \
-H "Content-Type: application/json" --data-binary @/Users/shenlan/workspaces/XControl/docs/upsert_1024 .json
2025-08-09 22:28:25 +08:00
```bash
2025-08-10 13:18:51 +08:00
Expected response on success: `{"rows":1}` . If the vector database is unavailable, the endpoint returns `{"rows":0,"error":"..."}` .
2025-08-07 13:52:33 +08:00
## POST /api/rag/query
- **Description:** Query the RAG service.
- **Body Parameters (JSON):**
- `question` – Query text.
- **Test:**
```bash
curl -X POST http://localhost:8080/api/rag/query \
-H "Content-Type: application/json" \
-d '{"question": "What is XControl?"}'
```
2025-08-09 13:47:19 +08:00
When copying the multi-line example above, ensure your shell treats the trailing
`\` characters as line continuations. Copying literal `\n` sequences will cause
`curl: (3) URL rejected: Bad hostname` errors. You can also run the command on a
single line without the backslashes:
```bash
curl -X POST http://localhost:8080/api/rag/query -H "Content-Type: application/json" -d '{"question": "What is XControl?"}'
```
2025-08-07 13:52:33 +08:00
## POST /api/askai
2025-08-12 22:32:45 +08:00
- **Description:** Ask the AI service for an answer. The endpoint uses [LangChainGo ](https://github.com/tmc/langchaingo ) to communicate with the configured model provider (e.g., OpenAI-compatible services or a local Ollama instance). Ensure the server configuration includes the proper token or local server URL.
2025-08-07 13:52:33 +08:00
- **Body Parameters (JSON):**
- `question` – Question text.
2025-08-12 22:32:45 +08:00
**Configuration:** In `server/config/server.yaml` the `models` section selects the LLM and embedding providers.
For local debugging with HuggingFace and Ollama:
```yaml
models:
embedder:
models: "bge-m3"
2025-08-14 19:36:29 +08:00
endpoint: "http://127.0.0.1:9000/v1/embeddings"
2025-08-12 22:32:45 +08:00
generator:
models:
- 'llama2:13b'
2025-08-14 19:36:29 +08:00
endpoint: "http://127.0.0.1:11434"
2025-08-12 22:32:45 +08:00
```
2025-08-14 19:36:29 +08:00
For online services using Chutes:
2025-08-12 22:32:45 +08:00
```yaml
2025-08-14 19:36:29 +08:00
#models:
# embedder:
# models: "bge-m3"
# endpoint: "https://chutes-baai-bge-m3.chutes.ai/embed"
# token: "cpk_xxxx"
# generator:
# models:
# - 'moonshotai/Kimi-K2-Instruct'
# endpoint: "https://llm.chutes.ai/v1"
# token: "cpk_xxxx"
2025-08-12 22:32:45 +08:00
```
The `api.askai` section controls request behaviour:
```yaml
api:
askai:
timeout: 60 # seconds
retries: 3 # retry attempts
```
2025-08-07 13:52:33 +08:00
- **Test:**
```bash
curl -X POST http://localhost:8080/api/askai \
-H "Content-Type: application/json" \
-d '{"question": "Hello"}'
```
2025-08-11 09:03:05 +08:00
## GET Localhost embeddings API
1. 运行(首次会自动下载模型)
python offline_embed_server.py
2. 测试接口
1) 健康检查(端口就绪即返回 ok) curl -v http://127.0.0.1:9000/healthz
2) 就绪检查(模型加载完成后返回 ready) curl -v http://127.0.0.1:9000/readyz
3) 调用 embeddings
curl http://127.0.0.1:9000/v1/embeddings \
-H "Content-Type: application/json" \
-d '{"model":"BAAI/bge-m3","input":["你好","PGVector 怎么建 HNSW? "]}'
如果你要把 DEVICE 固定为 mps 并行内核,保留默认即可;如需落回 CPU: DEVICE=cpu python docs/offline_embed_server.py。
## GET Localhost Ollama API
用流式接收(推荐):
curl http://127.0.0.1:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-oss:20b",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me three tips for optimizing HNSW in PostgreSQL."}
],
"max_tokens": 512,
"stream": true
}'
这样会实时输出分块数据
curl http://127.0.0.1:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "llama3:latest",
"messages": [{"role":"user","content":"你好,简要介绍一下自己"}],
"max_tokens": 200,
"temperature": 0.7
}'