$npx -y skills add QinghongLin/data2story-skill --skill openrouter-embeddingsGenerate text embeddings via OpenRouter using Qwen3-Embedding-8B.
| 1 | # openrouter-embeddings |
| 2 | |
| 3 | Text → embedding vector via OpenRouter. Default model: `qwen/qwen3-embedding-8b`. |
| 4 | |
| 5 | ## Usage |
| 6 | |
| 7 | Resolve `TOOL_DIR` = the directory containing this `SKILL.md`. Commands below use `TOOL_DIR` as a symbolic placeholder; replace it with the resolved, quoted path before running Bash. |
| 8 | |
| 9 | ### Single text |
| 10 | |
| 11 | ```bash |
| 12 | export OPENROUTER_API_KEY=sk-or-v1-... |
| 13 | |
| 14 | python3 TOOL_DIR/scripts/embed.py \ |
| 15 | --text "The quick brown fox jumps over the lazy dog" \ |
| 16 | --output vec.json |
| 17 | ``` |
| 18 | |
| 19 | ### Batch from JSONL |
| 20 | |
| 21 | Input `records.jsonl` (one JSON per line): |
| 22 | ``` |
| 23 | {"id": "row_0", "text": "Every place name in the United States."} |
| 24 | {"id": "row_1", "text": "Nearby stars and potential exoplanets."} |
| 25 | ``` |
| 26 | |
| 27 | Run: |
| 28 | ```bash |
| 29 | python3 TOOL_DIR/scripts/embed.py \ |
| 30 | --jsonl records.jsonl \ |
| 31 | --output records_with_embeddings.jsonl \ |
| 32 | --batch-size 32 |
| 33 | ``` |
| 34 | |
| 35 | Output is the same JSONL with an added `embedding` field per line. |
| 36 | |
| 37 | ## Flags |
| 38 | |
| 39 | | Flag | Default | Description | |
| 40 | |---|---|---| |
| 41 | | `--text` | — | Embed one string (mutually exclusive with `--jsonl`) | |
| 42 | | `--jsonl` | — | Embed many; each line must have a `text` field | |
| 43 | | `--output` | required | Output path | |
| 44 | | `--model` | `qwen/qwen3-embedding-8b` | Any embedding model on OpenRouter | |
| 45 | | `--batch-size` | `32` | Records per API call (jsonl mode) | |
| 46 | | `--dimensions` | — | Optional: truncate to N dims if supported | |
| 47 | |
| 48 | ## Endpoint |
| 49 | |
| 50 | `POST /api/v1/embeddings` — OpenAI-compatible schema. |
| 51 | |
| 52 | Request: |
| 53 | ```json |
| 54 | { "model": "qwen/qwen3-embedding-8b", "input": ["text1", "text2", ...] } |
| 55 | ``` |
| 56 | |
| 57 | Response: |
| 58 | ```json |
| 59 | { "data": [ { "embedding": [0.01, -0.02, ...], "index": 0 }, ... ], "model": "...", "usage": {...} } |
| 60 | ``` |
| 61 | |
| 62 | ## Notes |
| 63 | |
| 64 | - `qwen3-embedding-8b` outputs high-dimensional dense vectors suitable for semantic similarity, clustering, RAG. |
| 65 | - For cheaper batches, consider `qwen/qwen3-embedding-4b` or other listed embedding models (`GET /api/v1/embeddings/models`). |