Add embed endpoint (POST /api/embed)

Implement the Ollama POST /api/embed endpoint for generating vector
embeddings from text input.

- Add EmbedInput, EmbedRequest, EmbedResponse types in src/types/embed.rs
- Add OllamaClient::embed() async method in src/lib.rs
- Register embed module in src/types/mod.rs
- Add usage example in examples/embed.rs
- Update README with embed endpoint documentation
This commit is contained in:
2026-02-01 21:26:44 +00:00
parent b885ca3c1c
commit 0f796f1a2f
5 changed files with 379 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ An async Rust client library for the [Ollama](https://ollama.com/) API. Provides
- Structured JSON output with schema validation
- Tool calling / function calling support
- Model management (list, pull, delete, inspect running models)
- Text embeddings generation
- Builder pattern for constructing requests
- Configurable generation parameters (temperature, top-k, top-p, and more)
- Thinking / reasoning mode support
@@ -161,6 +162,7 @@ When the model decides to call a tool, the response `message.tool_calls` field w
| `chat(request)` | Chat conversation (streaming) |
| `pull(request)` | Pull/download a model (streaming) |
| `delete(request)` | Delete a model from the server |
| `embed(request)` | Generate vector embeddings |
**`OllamaClient::builder(server_address)`** -- `.connection_timeout(Duration)`, `.build()`
@@ -181,6 +183,8 @@ let client = OllamaClient::builder("http://localhost:11434")
**`PullRequest::builder(model)`** -- `.stream()`
**`EmbedRequest::builder(model)`** -- `.input()`, `.inputs()`, `.truncate()`, `.dimensions()`, `.keep_alive()`, `.options()`
### Generation Options
Configure sampling parameters via `Options::builder()`:
@@ -208,6 +212,7 @@ The `examples/` directory contains runnable programs:
| `tool_call` | Function calling / tool use |
| `pull` | Download a model |
| `delete` | Delete a model |
| `embed` | Generate text embeddings |
| `tags` | List available models |
| `ps` | List running models |
| `version` | Query server version |