From 72dc6a6f59dd0e97b07f928de70dac56395b4b51 Mon Sep 17 00:00:00 2001 From: Tommy-alto-FYygU Date: Fri, 20 Mar 2026 11:46:08 +0800 Subject: [PATCH] feat(ollama): support repeatable embed inputs --- ollama/agent-harness/OLLAMA.md | 2 +- ollama/agent-harness/cli_anything/ollama/README.md | 1 + .../agent-harness/cli_anything/ollama/ollama_cli.py | 11 ++++++++--- .../cli_anything/ollama/skills/SKILL.md | 1 + .../cli_anything/ollama/tests/test_core.py | 13 +++++++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ollama/agent-harness/OLLAMA.md b/ollama/agent-harness/OLLAMA.md index a023b2669..6cb5b02c4 100644 --- a/ollama/agent-harness/OLLAMA.md +++ b/ollama/agent-harness/OLLAMA.md @@ -65,7 +65,7 @@ Ollama already provides a clean REST API. Our CLI wraps it with: | `ollama ps` | `model ps` | | `ollama run ` | `generate text --model --prompt "..."` | | (no equivalent) | `generate chat --model --message "..."` | -| (no equivalent) | `embed text --model --input "..."` | +| (no equivalent) | `embed text --model --input "..." [--input "..."]` | | `ollama serve` | (external — must be running) | ## Model Parameters (options) diff --git a/ollama/agent-harness/cli_anything/ollama/README.md b/ollama/agent-harness/cli_anything/ollama/README.md index 8a093d6fa..5862b5050 100644 --- a/ollama/agent-harness/cli_anything/ollama/README.md +++ b/ollama/agent-harness/cli_anything/ollama/README.md @@ -81,6 +81,7 @@ generate chat --model --message "user:Hello" [--message "assistant:Hi"] ```bash embed text --model --input "Text to embed" +embed text --model --input "First text" --input "Second text" ``` ### Server diff --git a/ollama/agent-harness/cli_anything/ollama/ollama_cli.py b/ollama/agent-harness/cli_anything/ollama/ollama_cli.py index 1fb22a6f7..3512dd683 100644 --- a/ollama/agent-harness/cli_anything/ollama/ollama_cli.py +++ b/ollama/agent-harness/cli_anything/ollama/ollama_cli.py @@ -340,11 +340,16 @@ def embed(): @embed.command("text") @click.option("--model", "-m", "model_name", required=True, help="Model name") -@click.option("--input", "-i", "input_text", required=True, help="Text to embed") +@click.option( + "--input", "-i", "input_texts", + multiple=True, required=True, + help="Text to embed. Repeat for batch embeddings.", +) @handle_error -def embed_text(model_name, input_text): +def embed_text(model_name, input_texts): """Generate embeddings for text.""" - result = embed_mod.embed(_host, model_name, input_text) + payload = list(input_texts) + result = embed_mod.embed(_host, model_name, payload[0] if len(payload) == 1 else payload) if _json_output: output(result) else: diff --git a/ollama/agent-harness/cli_anything/ollama/skills/SKILL.md b/ollama/agent-harness/cli_anything/ollama/skills/SKILL.md index c48943321..3281161ce 100644 --- a/ollama/agent-harness/cli_anything/ollama/skills/SKILL.md +++ b/ollama/agent-harness/cli_anything/ollama/skills/SKILL.md @@ -155,6 +155,7 @@ cli-anything-ollama generate chat --model llama3.2 --file messages.json ```bash cli-anything-ollama embed text --model nomic-embed-text --input "Hello world" +cli-anything-ollama embed text --model nomic-embed-text --input "Hello" --input "World" ``` diff --git a/ollama/agent-harness/cli_anything/ollama/tests/test_core.py b/ollama/agent-harness/cli_anything/ollama/tests/test_core.py index 62f285946..2941afb4b 100644 --- a/ollama/agent-harness/cli_anything/ollama/tests/test_core.py +++ b/ollama/agent-harness/cli_anything/ollama/tests/test_core.py @@ -315,6 +315,19 @@ class TestEmbedCommands: data = json.loads(result.output) assert "embeddings" in data + @patch("cli_anything.ollama.core.embeddings.api_post") + def test_embed_text_multiple_inputs_json(self, mock_api, runner): + mock_api.return_value = {"embeddings": [[0.1, 0.2], [0.3, 0.4]]} + result = runner.invoke(cli, ["--json", "embed", "text", + "--model", "nomic-embed-text", + "--input", "Hello", + "--input", "World"]) + assert result.exit_code == 0 + data = json.loads(result.output) + assert len(data["embeddings"]) == 2 + call_data = mock_api.call_args[0][2] + assert call_data["input"] == ["Hello", "World"] + @patch("cli_anything.ollama.core.embeddings.api_post") def test_embed_text_human(self, mock_api, runner): mock_api.return_value = {"embeddings": [[0.1, 0.2, 0.3, 0.4, 0.5, 0.6]]}