[GH-ISSUE #1114] Reduce Embedding size #560

Closed
opened 2026-04-12 10:15:15 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Mohit0928 on GitHub (Nov 13, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/1114

I'm trying to replicate this example of langchain. I'm using ElasticSearch as the database to store the embedding. In the given example I have replaced embeddings = OpenAIEmbeddings() with oembed = OllamaEmbeddings(model="llama2") which one can import from langchain.embeddings import OllamaEmbeddings. I'm running Ollama locally. But, I'm running into below error:

raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'The number of dimensions for field [vector] should be in the range [1, 2048] but was [4096]')

The Ollama model always create the embedding of size 4096 even when I sat the chunk size of 500. Is there any way to reduce the size of embedding?

Originally created by @Mohit0928 on GitHub (Nov 13, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/1114 I'm trying to replicate [this example](https://python.langchain.com/docs/integrations/vectorstores/elasticsearch#basic-example) of langchain. I'm using ElasticSearch as the database to store the embedding. In the given example I have replaced `embeddings = OpenAIEmbeddings()` with `oembed = OllamaEmbeddings(model="llama2")` which one can import `from langchain.embeddings import OllamaEmbeddings`. I'm running `Ollama` locally. But, I'm running into below error: ``` raise HTTP_EXCEPTIONS.get(status_code, TransportError)( elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'The number of dimensions for field [vector] should be in the range [1, 2048] but was [4096]') ``` The Ollama model always create the embedding of size `4096` even when I sat the chunk size of `500`. Is there any way to reduce the size of embedding?
Author
Owner

@BruceMacD commented on GitHub (Nov 13, 2023):

Hi @Mohit0928 the output size of the embedding is determined based on how the model was trained rather than the size of the input, it is a constant. The way to deal with this normally is to use a different model. Ollama doesn't have any embedding specific models in its library at the moment though, so I can't make a great recommendation on a good one to use.

<!-- gh-comment-id:1809158510 --> @BruceMacD commented on GitHub (Nov 13, 2023): Hi @Mohit0928 the output size of the embedding is determined based on how the model was trained rather than the size of the input, it is a constant. The way to deal with this normally is to use a different model. Ollama doesn't have any embedding specific models in its library at the moment though, so I can't make a great recommendation on a good one to use.
Author
Owner

@technovangelist commented on GitHub (Dec 4, 2023):

It looks like this question was answered by Bruce so I will go ahead and close it now. If you think there is anything we left out, reopen and we can address. Thanks for being part of this great community.

<!-- gh-comment-id:1839440089 --> @technovangelist commented on GitHub (Dec 4, 2023): It looks like this question was answered by Bruce so I will go ahead and close it now. If you think there is anything we left out, reopen and we can address. Thanks for being part of this great community.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#560