[PR #2229] [CLOSED] ollama: Switch from parallel to sequential chunk embedding #3929

Closed
opened 2026-02-22 18:34:47 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/2229
Author: @fstp
Created: 9/6/2024
Status: Closed

Base: masterHead: master


📝 Commits (2)

  • 7e67dc6 ollama: Switch from parallel to sequential chunk embedding
  • a645b33 Merge branch 'master' into master

📊 Changes

1 file changed (+18 additions, -48 deletions)

View changed files

📝 server/utils/EmbeddingEngines/ollama/index.js (+18 -48)

📄 Description

Pull Request Type

  • feat
  • [ X ] 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

What is in this change?

The previous implementation used Promise.all to start fetch operations for multiple chunks concurrently. This approach, however, had a drawback. If the entire embedding process took longer than the fetch timeout (5 minutes), the embedding operations would start to fail in ollama due to "context canceled".

Example from ollama/anythingllm logs:
anythingllm | [backend] info: [OllamaEmbedder] Embedding 79 chunks of text with nomic-embed-text:latest.
...
ollama | [GIN] 2024/09/05 - 16:25:35 | 200 | 3m51s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:25:43 | 200 | 3m59s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:25:50 | 200 | 4m6s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:25:57 | 200 | 4m12s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:26:04 | 200 | 4m19s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:26:12 | 200 | 4m28s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:26:19 | 200 | 4m35s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:26:27 | 200 | 4m43s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:26:36 | 200 | 4m51s | 172.30.0.3 | POST "/api/embeddings"
ollama | [GIN] 2024/09/05 - 16:26:43 | 200 | 4m59s | 172.30.0.3 | POST "/api/embeddings"
ollama | time=2024-09-05T16:26:45.449Z level=ERROR source=server.go:894 msg="Failed to acquire semaphore" error="context canceled"
ollama | time=2024-09-05T16:26:45.449Z level=INFO source=routes.go:450 msg="embedding generation failed: context canceled"
ollama | [GIN] 2024/09/05 - 16:26:45 | 500 | 5m1s | 172.30.0.3 | POST "/api/embeddings"
ollama | time=2024-09-05T16:26:45.449Z level=ERROR source=server.go:894 msg="Failed to acquire semaphore" error="context canceled"
ollama | time=2024-09-05T16:26:45.449Z level=INFO source=routes.go:450 msg="embedding generation failed: context canceled"
...
anythingllm | [backend] error: addDocumentToNamespace Ollama Failed to embed: [undefined]: undefined
anythingllm | [backend] error: Failed to vectorize emails_part_10.txt

Even though the error messages looks like they might have to do with multithreading in the ollama backend.. it's just a side effect of the fact the embedding handler tries to aquire the sempahore before attempting to do anything else and then it discovers that the request was terminated/timed out and the context had been canceled (from anythingllm side)

Additional Information

Code snippet from ollama server.go that handles embedding:
https://github.com/ollama/ollama/blob/cf48603943ba2678349ba0dadd06a50099ae5eec/llm/server.go#L892

Developer Validations

  • [ X ] I ran yarn lint from the root of the repo & committed changes
  • [ X ] Relevant documentation has been updated
  • [ X ] I have tested my code functionality
  • [ X ] Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/2229 **Author:** [@fstp](https://github.com/fstp) **Created:** 9/6/2024 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (2) - [`7e67dc6`](https://github.com/Mintplex-Labs/anything-llm/commit/7e67dc6c8017ac65fc858c992833c347f16b91e0) ollama: Switch from parallel to sequential chunk embedding - [`a645b33`](https://github.com/Mintplex-Labs/anything-llm/commit/a645b33ceb946a3e4ef88e32af373ff01bcda9f1) Merge branch 'master' into master ### 📊 Changes **1 file changed** (+18 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `server/utils/EmbeddingEngines/ollama/index.js` (+18 -48) </details> ### 📄 Description ### Pull Request Type <!-- For change type, change [ ] to [x]. --> - [ ] ✨ feat - [ X ] 🐛 fix - [ ] ♻️ refactor - [ ] 💄 style - [ ] 🔨 chore - [ ] 📝 docs ### Relevant Issues ### What is in this change? The previous implementation used Promise.all to start fetch operations for multiple chunks concurrently. This approach, however, had a drawback. If the entire embedding process took longer than the fetch timeout (5 minutes), the embedding operations would start to fail in ollama due to "context canceled". Example from ollama/anythingllm logs: anythingllm | [backend] info: [OllamaEmbedder] Embedding 79 chunks of text with nomic-embed-text:latest. ... ollama | [GIN] 2024/09/05 - 16:25:35 | 200 | 3m51s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:25:43 | 200 | 3m59s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:25:50 | 200 | 4m6s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:25:57 | 200 | 4m12s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:26:04 | 200 | 4m19s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:26:12 | 200 | 4m28s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:26:19 | 200 | 4m35s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:26:27 | 200 | 4m43s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:26:36 | 200 | 4m51s | 172.30.0.3 | POST "/api/embeddings" ollama | [GIN] 2024/09/05 - 16:26:43 | 200 | 4m59s | 172.30.0.3 | POST "/api/embeddings" ollama | time=2024-09-05T16:26:45.449Z level=ERROR source=server.go:894 msg="Failed to acquire semaphore" error="context canceled" ollama | time=2024-09-05T16:26:45.449Z level=INFO source=routes.go:450 msg="embedding generation failed: context canceled" ollama | [GIN] 2024/09/05 - 16:26:45 | 500 | 5m1s | 172.30.0.3 | POST "/api/embeddings" ollama | time=2024-09-05T16:26:45.449Z level=ERROR source=server.go:894 msg="Failed to acquire semaphore" error="context canceled" ollama | time=2024-09-05T16:26:45.449Z level=INFO source=routes.go:450 msg="embedding generation failed: context canceled" ... anythingllm | [backend] error: addDocumentToNamespace Ollama Failed to embed: [undefined]: undefined anythingllm | [backend] error: Failed to vectorize emails_part_10.txt Even though the error messages looks like they might have to do with multithreading in the ollama backend.. it's just a side effect of the fact the embedding handler tries to aquire the sempahore before attempting to do anything else and then it discovers that the request was terminated/timed out and the context had been canceled (from anythingllm side) ### Additional Information Code snippet from ollama server.go that handles embedding: https://github.com/ollama/ollama/blob/cf48603943ba2678349ba0dadd06a50099ae5eec/llm/server.go#L892 ### Developer Validations <!-- All of the applicable items should be checked. --> - [ X ] I ran `yarn lint` from the root of the repo & committed changes - [ X ] Relevant documentation has been updated - [ X ] I have tested my code functionality - [ X ] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:34:47 -05:00
yindo closed this issue 2026-02-22 18:34:47 -05:00
yindo changed title from [PR #2229] ollama: Switch from parallel to sequential chunk embedding to [PR #2229] [CLOSED] ollama: Switch from parallel to sequential chunk embedding 2026-06-05 15:15:56 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#3929