[GH-ISSUE #651] Ability to configure embeddings dimension size #62327

Closed
opened 2026-05-03 08:14:17 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @jamesbraza on GitHub (Sep 29, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/651

Moving from OllamaEmbeddings(model="llama2:13b") to OllamaEmbeddings(model="llama2:7b"), I am now getting a shape mismatch in my embeddings:

ValueError: shapes (4096,) and (5120,) not aligned: 4096 (dim 0) != 5120 (dim 0)

So the 7b embeddings is slightly smaller (4096) than 13b embeddings (5120). Is there an argument or parameter I can use to control the embedding size?

I would like to artificially switch 7b to use 5120, so I can not rebuild my vector store.

Originally created by @jamesbraza on GitHub (Sep 29, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/651 Moving from `OllamaEmbeddings(model="llama2:13b")` to `OllamaEmbeddings(model="llama2:7b")`, I am now getting a shape mismatch in my embeddings: ```none ValueError: shapes (4096,) and (5120,) not aligned: 4096 (dim 0) != 5120 (dim 0) ``` So the `7b` embeddings is slightly smaller (4096) than `13b` embeddings (5120). Is there an argument or parameter I can use to control the embedding size? I would like to artificially switch `7b` to use 5120, so I can not rebuild my vector store.
GiteaMirror added the embeddingsfeature request labels 2026-05-03 08:14:17 -05:00
Author
Owner

@kittycattoys commented on GitHub (Feb 22, 2024):

This functionality from Nomic is nice. I am using TinyLlama / Llama2 for embeddings but would like the option to change dimensionality like Nomic has: from nomic import embed response = embed.text(
texts=[prompt],
model='nomic-embed-text-v1.5',
task_type='search_document',
dimensionality=768
) Is this enhancement possible?

<!-- gh-comment-id:1960501880 --> @kittycattoys commented on GitHub (Feb 22, 2024): This functionality from Nomic is nice. I am using TinyLlama / Llama2 for embeddings but would like the option to change dimensionality like Nomic has: from nomic import embed response = embed.text( texts=[prompt], model='nomic-embed-text-v1.5', task_type='search_document', dimensionality=768 ) Is this enhancement possible?
Author
Owner

@bilunsun commented on GitHub (Mar 6, 2024):

I second this.

This functionality from Nomic is nice. I am using TinyLlama / Llama2 for embeddings but would like the option to change dimensionality like Nomic has: from nomic import embed response = embed.text( texts=[prompt], model='nomic-embed-text-v1.5', task_type='search_document', dimensionality=768 ) Is this enhancement possible?

In their latest v1.5 HuggingFace page, the user should be able to configure both the task_type and dimensionality. However, I have not been able to set these arguments with Ollama.

<!-- gh-comment-id:1981286906 --> @bilunsun commented on GitHub (Mar 6, 2024): I second this. > This functionality from Nomic is nice. I am using TinyLlama / Llama2 for embeddings but would like the option to change dimensionality like Nomic has: from nomic import embed response = embed.text( texts=[prompt], model='nomic-embed-text-v1.5', task_type='search_document', dimensionality=768 ) Is this enhancement possible? In their latest v1.5 [HuggingFace page](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5), the user should be able to configure both the `task_type` and `dimensionality`. However, I have not been able to set these arguments with Ollama.
Author
Owner

@kenneth-liao commented on GitHub (Jul 25, 2024):

Agree, this type of functionality is critical for optimizing the embedding process and database size when storing embeddings.

<!-- gh-comment-id:2250975996 --> @kenneth-liao commented on GitHub (Jul 25, 2024): Agree, this type of functionality is critical for optimizing the embedding process and database size when storing embeddings.
Author
Owner

@raffaeler commented on GitHub (Nov 19, 2024):

FYI if the model has Matryoshka capabilities, cutting the vector to the desired size is straightforward. You just keep the most significant portion:

  1. take the [0:length] part
  2. normalize the result vector
<!-- gh-comment-id:2486161758 --> @raffaeler commented on GitHub (Nov 19, 2024): FYI if the model has Matryoshka capabilities, cutting the vector to the desired size is straightforward. You just keep the most significant portion: 1. take the [0:length] part 2. normalize the result vector
Author
Owner

@saadshaikh3 commented on GitHub (Jan 17, 2025):

Any update on this feature ?

<!-- gh-comment-id:2598560856 --> @saadshaikh3 commented on GitHub (Jan 17, 2025): Any update on this feature ?
Author
Owner

@noahfraiture commented on GitHub (Mar 8, 2025):

Still nothing ?

<!-- gh-comment-id:2708354011 --> @noahfraiture commented on GitHub (Mar 8, 2025): Still nothing ?
Author
Owner

@PhilippeCalvez commented on GitHub (Mar 17, 2025):

On my side the problem was due to a rate limited litellm proxy that I'm using. I've installed the model nomic-embed-text on a local ollama server. It works but I had to specify the embedding dimension.

# Define the Crew crew = Crew( agents=agents, tasks=tasks, process=Process.sequential, verbose=True, memory=True, embedder={ "provider": "ollama", "config": { "model": 'nomic-embed-text', "api_base": "http://localhost:11434/api/embed" } }, embedding_dimension=768 )

<!-- gh-comment-id:2729449070 --> @PhilippeCalvez commented on GitHub (Mar 17, 2025): On my side the problem was due to a rate limited litellm proxy that I'm using. I've installed the model nomic-embed-text on a local ollama server. It works but I had to specify the embedding dimension. `# Define the Crew crew = Crew( agents=agents, tasks=tasks, process=Process.sequential, verbose=True, memory=True, embedder={ "provider": "ollama", "config": { "model": 'nomic-embed-text', "api_base": "http://localhost:11434/api/embed" } }, embedding_dimension=768 ) `
Author
Owner

@rick-github commented on GitHub (Sep 16, 2025):

https://github.com/ollama/ollama/pull/12242

<!-- gh-comment-id:3298009014 --> @rick-github commented on GitHub (Sep 16, 2025): https://github.com/ollama/ollama/pull/12242
Author
Owner

@jamesbraza commented on GitHub (Sep 16, 2025):

@rick-github feel free to close this issue if you think that PR resolves it. I made this request two years ago, I don't really have the code to test this any more

<!-- gh-comment-id:3299672921 --> @jamesbraza commented on GitHub (Sep 16, 2025): @rick-github feel free to close this issue if you think that PR resolves it. I made this request two years ago, I don't really have the code to test this any more
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#62327