[GH-ISSUE #6233] Strange! Each request consumes an additional 2 seconds when I used /api/embed #81578

Closed
opened 2026-05-09 11:28:34 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @AlbertXu233 on GitHub (Aug 7, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6233

What is the issue?

image OS: win11 device: intel i5 1335U with only iGPU embedding model: shaw/dmeta-embedding-zh-q4 I test with very simple input: ["你好"]

OS

Windows

GPU

Intel

CPU

Intel

Ollama version

0.3.4

Originally created by @AlbertXu233 on GitHub (Aug 7, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6233 ### What is the issue? <img width="809" alt="image" src="https://github.com/user-attachments/assets/d649cc9e-7b95-4146-aeef-4eb564be7047"> OS: win11 device: intel i5 1335U with only iGPU embedding model: shaw/dmeta-embedding-zh-q4 I test with very simple input: ["你好"] ### OS Windows ### GPU Intel ### CPU Intel ### Ollama version 0.3.4
GiteaMirror added the networkingperformance labels 2026-05-09 11:28:34 -05:00
Author
Owner

@rick-github commented on GitHub (Aug 7, 2024):

What's making the API call? Making a direct API call in linux doesn't show any delays:

$ curl -s localhost:11434/api/version
{"version":"0.3.4"}

$ for i in {1..5} ; do curl -s localhost:11434/api/embed -d '{"model":"shaw/dmeta-embedding-zh-q4","input":"你好"}' | jq -c 'del(.embeddings[0][])' ; done
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":138950724,"load_duration":1587447,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":142275262,"load_duration":1525043,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145625093,"load_duration":1402358,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":148817738,"load_duration":1032026,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145985135,"load_duration":1396395,"prompt_eval_count":4}

$ docker compose logs ollama | grep /api/embed
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  139.237667ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  142.622972ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  145.953288ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  149.176403ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  146.312404ms |   192.168.192.1 | POST     "/api/embed"

<!-- gh-comment-id:2273987726 --> @rick-github commented on GitHub (Aug 7, 2024): What's making the API call? Making a direct API call in linux doesn't show any delays: ``` $ curl -s localhost:11434/api/version {"version":"0.3.4"} $ for i in {1..5} ; do curl -s localhost:11434/api/embed -d '{"model":"shaw/dmeta-embedding-zh-q4","input":"你好"}' | jq -c 'del(.embeddings[0][])' ; done {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":138950724,"load_duration":1587447,"prompt_eval_count":4} {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":142275262,"load_duration":1525043,"prompt_eval_count":4} {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145625093,"load_duration":1402358,"prompt_eval_count":4} {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":148817738,"load_duration":1032026,"prompt_eval_count":4} {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145985135,"load_duration":1396395,"prompt_eval_count":4} $ docker compose logs ollama | grep /api/embed ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 139.237667ms | 192.168.192.1 | POST "/api/embed" ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 142.622972ms | 192.168.192.1 | POST "/api/embed" ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 145.953288ms | 192.168.192.1 | POST "/api/embed" ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 149.176403ms | 192.168.192.1 | POST "/api/embed" ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 146.312404ms | 192.168.192.1 | POST "/api/embed" ```
Author
Owner

@AlbertXu233 commented on GitHub (Aug 8, 2024):

What's making the API call? Making a direct API call in linux doesn't show any delays:

$ curl -s localhost:11434/api/version
{"version":"0.3.4"}

$ for i in {1..5} ; do curl -s localhost:11434/api/embed -d '{"model":"shaw/dmeta-embedding-zh-q4","input":"你好"}' | jq -c 'del(.embeddings[0][])' ; done
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":138950724,"load_duration":1587447,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":142275262,"load_duration":1525043,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145625093,"load_duration":1402358,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":148817738,"load_duration":1032026,"prompt_eval_count":4}
{"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145985135,"load_duration":1396395,"prompt_eval_count":4}

$ docker compose logs ollama | grep /api/embed
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  139.237667ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  142.622972ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  145.953288ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  149.176403ms |   192.168.192.1 | POST     "/api/embed"
ollama  | [GIN] 2024/08/07 - 17:34:32 | 200 |  146.312404ms |   192.168.192.1 | POST     "/api/embed"

I used python requests in windows
Here is the code:

    def request_ollama(query, host="localhost:11434", ollama_model_name="shaw/dmeta-embedding-zh"):
        """
        使用ollama的embedding策略
        """
        url = f"http://{host}/api/embeddings"

        payload = json.dumps(
                {
                    "model": ollama_model_name,
                    "prompt": query,
                }
            )
        headers = {"Content-Type": "application/json"}

        response = requests.request(
                "POST", url, headers=headers, data=payload, stream=False
            )
        embeddings = json.loads(response.text)
        return [embeddings["embedding"]]
    for i in range(10):
        print(i)
        print(request_ollama("你好"))
<!-- gh-comment-id:2274814845 --> @AlbertXu233 commented on GitHub (Aug 8, 2024): > What's making the API call? Making a direct API call in linux doesn't show any delays: > > ``` > $ curl -s localhost:11434/api/version > {"version":"0.3.4"} > > $ for i in {1..5} ; do curl -s localhost:11434/api/embed -d '{"model":"shaw/dmeta-embedding-zh-q4","input":"你好"}' | jq -c 'del(.embeddings[0][])' ; done > {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":138950724,"load_duration":1587447,"prompt_eval_count":4} > {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":142275262,"load_duration":1525043,"prompt_eval_count":4} > {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145625093,"load_duration":1402358,"prompt_eval_count":4} > {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":148817738,"load_duration":1032026,"prompt_eval_count":4} > {"model":"shaw/dmeta-embedding-zh-q4","embeddings":[[]],"total_duration":145985135,"load_duration":1396395,"prompt_eval_count":4} > > $ docker compose logs ollama | grep /api/embed > ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 139.237667ms | 192.168.192.1 | POST "/api/embed" > ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 142.622972ms | 192.168.192.1 | POST "/api/embed" > ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 145.953288ms | 192.168.192.1 | POST "/api/embed" > ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 149.176403ms | 192.168.192.1 | POST "/api/embed" > ollama | [GIN] 2024/08/07 - 17:34:32 | 200 | 146.312404ms | 192.168.192.1 | POST "/api/embed" > ``` I used python requests in windows Here is the code: ```python def request_ollama(query, host="localhost:11434", ollama_model_name="shaw/dmeta-embedding-zh"): """ 使用ollama的embedding策略 """ url = f"http://{host}/api/embeddings" payload = json.dumps( { "model": ollama_model_name, "prompt": query, } ) headers = {"Content-Type": "application/json"} response = requests.request( "POST", url, headers=headers, data=payload, stream=False ) embeddings = json.loads(response.text) return [embeddings["embedding"]] for i in range(10): print(i) print(request_ollama("你好")) ```
Author
Owner

@rick-github commented on GitHub (Aug 8, 2024):

If you change localhost to 127.0.0.1 does it run faster?

<!-- gh-comment-id:2275535009 --> @rick-github commented on GitHub (Aug 8, 2024): If you change `localhost` to `127.0.0.1` does it run faster?
Author
Owner

@AlbertXu233 commented on GitHub (Aug 13, 2024):

If you change localhost to 127.0.0.1 does it run faster?

Amazing! It works! Thanks!

<!-- gh-comment-id:2285710883 --> @AlbertXu233 commented on GitHub (Aug 13, 2024): > If you change `localhost` to `127.0.0.1` does it run faster? Amazing! It works! Thanks!
Author
Owner

@royjhan commented on GitHub (Aug 13, 2024):

@AlbertXu233 does the issue persist when using localhost? I'm unable to recreate it with your script.

<!-- gh-comment-id:2286838016 --> @royjhan commented on GitHub (Aug 13, 2024): @AlbertXu233 does the issue persist when using localhost? I'm unable to recreate it with your script.
Author
Owner

@dhiltgen commented on GitHub (Sep 5, 2024):

By switching to the IP you're likely bypassing hostname resolution and/or proxy configurations which are likely what is adding the latency.

<!-- gh-comment-id:2332423643 --> @dhiltgen commented on GitHub (Sep 5, 2024): By switching to the IP you're likely bypassing hostname resolution and/or proxy configurations which are likely what is adding the latency.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#81578