|
1 | | -# bitloops-embeddings |
| 1 | +# bitloops-embeddings |
| 2 | + |
| 3 | +`bitloops-embeddings` is a managed local embeddings runtime for Bitloops. It provides: |
| 4 | + |
| 5 | +- a one-shot CLI for simple embedding requests |
| 6 | +- a long-lived local HTTP server for repeated requests |
| 7 | +- release packaging for major desktop and server operating systems |
| 8 | + |
| 9 | +The first release is intentionally operational rather than retrieval-quality-complete. It focuses on a stable interface, model bootstrapping, hello-world inference, and releasable artefacts. |
| 10 | + |
| 11 | +## Runtime model |
| 12 | + |
| 13 | +The initial public model identifier is `bge-m3`. |
| 14 | + |
| 15 | +- Public model id: `bge-m3` |
| 16 | +- Upstream model id: `BAAI/bge-m3` |
| 17 | +- Backend: `sentence-transformers` |
| 18 | +- Device: CPU |
| 19 | +- Provisioning: first-run download into a local cache directory |
| 20 | + |
| 21 | +The command and HTTP layers are written against an internal backend registry so additional models or inference backends can be added later without changing the user-facing contracts. |
| 22 | + |
| 23 | +## Requirements |
| 24 | + |
| 25 | +- Python `3.11` or `3.12` |
| 26 | +- `pip` |
| 27 | + |
| 28 | +## Local development |
| 29 | + |
| 30 | +Create an environment and install the project with development dependencies: |
| 31 | + |
| 32 | +```bash |
| 33 | +python3.12 -m venv .venv |
| 34 | +source .venv/bin/activate |
| 35 | +python -m pip install --upgrade pip |
| 36 | +python -m pip install -e ".[dev]" |
| 37 | +``` |
| 38 | + |
| 39 | +Run the test suite: |
| 40 | + |
| 41 | +```bash |
| 42 | +pytest |
| 43 | +``` |
| 44 | + |
| 45 | +## CLI usage |
| 46 | + |
| 47 | +Show the available commands: |
| 48 | + |
| 49 | +```bash |
| 50 | +bitloops-embeddings --help |
| 51 | +``` |
| 52 | + |
| 53 | +Generate a single embedding: |
| 54 | + |
| 55 | +```bash |
| 56 | +bitloops-embeddings embed --model bge-m3 --input "Hello World" |
| 57 | +``` |
| 58 | + |
| 59 | +Example response: |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "model_id": "bge-m3", |
| 64 | + "dimensions": 1024, |
| 65 | + "embeddings": [[0.123, -0.456, 0.789]], |
| 66 | + "runtime": { |
| 67 | + "name": "bitloops-embeddings", |
| 68 | + "version": "0.1.0" |
| 69 | + } |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +Write the same JSON response to a file as well: |
| 74 | + |
| 75 | +```bash |
| 76 | +bitloops-embeddings embed \ |
| 77 | + --model bge-m3 \ |
| 78 | + --input "Hello World" \ |
| 79 | + --output ./embedding.json |
| 80 | +``` |
| 81 | + |
| 82 | +Inspect model metadata without loading the model: |
| 83 | + |
| 84 | +```bash |
| 85 | +bitloops-embeddings describe --model bge-m3 |
| 86 | +``` |
| 87 | + |
| 88 | +## Server usage |
| 89 | + |
| 90 | +Start the local server: |
| 91 | + |
| 92 | +```bash |
| 93 | +bitloops-embeddings serve --model bge-m3 |
| 94 | +``` |
| 95 | + |
| 96 | +Defaults: |
| 97 | + |
| 98 | +- host: `127.0.0.1` |
| 99 | +- port: `7719` |
| 100 | +- max batch size: `32` |
| 101 | + |
| 102 | +Override the bind target: |
| 103 | + |
| 104 | +```bash |
| 105 | +bitloops-embeddings serve --model bge-m3 --host 127.0.0.1 --port 7719 |
| 106 | +``` |
| 107 | + |
| 108 | +### HTTP API |
| 109 | + |
| 110 | +Health: |
| 111 | + |
| 112 | +```bash |
| 113 | +curl http://127.0.0.1:7719/health |
| 114 | +``` |
| 115 | + |
| 116 | +Embed: |
| 117 | + |
| 118 | +```bash |
| 119 | +curl -X POST http://127.0.0.1:7719/embed \ |
| 120 | + -H "content-type: application/json" \ |
| 121 | + -d '{"texts":["Hello World"]}' |
| 122 | +``` |
| 123 | + |
| 124 | +Response shape: |
| 125 | + |
| 126 | +```json |
| 127 | +{ |
| 128 | + "model_id": "bge-m3", |
| 129 | + "dimensions": 1024, |
| 130 | + "embeddings": [[0.123, -0.456, 0.789]], |
| 131 | + "runtime": { |
| 132 | + "name": "bitloops-embeddings", |
| 133 | + "version": "0.1.0" |
| 134 | + } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +Error shape: |
| 139 | + |
| 140 | +```json |
| 141 | +{ |
| 142 | + "error": { |
| 143 | + "code": "runtime_error", |
| 144 | + "message": "..." |
| 145 | + } |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +## Cache directory resolution |
| 150 | + |
| 151 | +Model cache resolution order: |
| 152 | + |
| 153 | +1. `--cache-dir` |
| 154 | +2. `BITLOOPS_EMBEDDINGS_CACHE_DIR` |
| 155 | +3. platform default cache directory via `platformdirs` |
| 156 | + |
| 157 | +Examples: |
| 158 | + |
| 159 | +- macOS: `~/Library/Caches/bitloops-embeddings` |
| 160 | +- Linux: `~/.cache/bitloops-embeddings` |
| 161 | +- Windows: `%LOCALAPPDATA%/bitloops-embeddings/Cache` |
| 162 | + |
| 163 | +## Packaging |
| 164 | + |
| 165 | +Release packaging uses PyInstaller `--onedir` bundles. Each archive contains: |
| 166 | + |
| 167 | +- the launchable runtime bundle |
| 168 | +- `README.md` |
| 169 | +- `LICENSE` |
| 170 | + |
| 171 | +Create a local packaged artefact: |
| 172 | + |
| 173 | +```bash |
| 174 | +python scripts/package_release.py --target x86_64-apple-darwin |
| 175 | +``` |
| 176 | + |
| 177 | +Run the real-model smoke test against an installed console script or packaged executable: |
| 178 | + |
| 179 | +```bash |
| 180 | +python scripts/real_backend_smoke.py --binary bitloops-embeddings |
| 181 | +``` |
| 182 | + |
| 183 | +## GitHub Actions |
| 184 | + |
| 185 | +The repository includes two workflows: |
| 186 | + |
| 187 | +- `ci.yml` |
| 188 | + - installs dependencies |
| 189 | + - runs unit and integration tests |
| 190 | + - runs compile checks |
| 191 | + - validates the CLI help output |
| 192 | +- `release.yml` |
| 193 | + - builds native bundles for the target matrix |
| 194 | + - packages archives |
| 195 | + - uploads artefacts |
| 196 | + - creates a GitHub Release for `v*.*.*` tags |
| 197 | + |
| 198 | +## Troubleshooting |
| 199 | + |
| 200 | +- The first `embed` or `serve` invocation downloads model files into the local cache. This can take a while on a cold machine. |
| 201 | +- If model loading fails, check network access to Hugging Face and confirm the cache directory is writable. |
| 202 | +- The runtime does not log input texts by default. |
0 commit comments