[GH-ISSUE #2173] Issues with OllamaEmbedding #47756

Closed
opened 2026-04-28 05:12:46 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @RonHein on GitHub (Jan 24, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2173

Hi, I am having trouble using OllamaEmbedding. I am unable to retrieve the correct vectors and the the similarity score is really high. I was able to get the correct vectors with OpenAIEmbedding but I am hoping to get OllamaEmbedding working. Is there something that I am missing?

Below is a simple loader with chromadb using OllamaEmbedding.

`from langchain.document_loaders import PyPDFLoader, UnstructuredExcelLoader, Docx2TxtLoader, BSHTMLLoader, TextLoader
from langchain.embeddings import OllamaEmbeddings
from langchain.vectorstores import Chroma
from langchain.text_splitter import RecursiveCharacterTextSplitter

def chunk():
loader = TextLoader('./samples/facts.txt')

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=128
    chunk_overlap = 20
)

docs = loader.load_and_split(
    text_splitter=text_splitter
)

return docs

def create_embedding():
docs = chunk()

embeddings = OllamaEmbeddings()

db = Chroma.from_documents(
    docs,
    embedding=embeddings,
    persist_directory="./samples/docs/chroma",
)

results = db.similarity_search_with_score("What is an interesting fact about the English language?")

print("~~~~similarity_search_with_score~~~~"
for result in results:
    print("\n")
    print(result[1])
    print(result[0].page_content)

`

This is the output:
8292.622553378074
16. Queen Elizabeth II is the longest-reigning current monarch.
17. The Leaning Tower of Pisa took 200 years to construct.

8386.487814338176
6. The elephant is the only mammal that can't jump.
7. The letter 'Q' is the only letter not appearing in any U.S. state name.

8529.430614665867
34. The shortest war in history was between Britain and Zanzibar on August 27, 1896. Zanzibar surrendered after 38 minutes.

8711.880867153133
50. Canada has more lakes than the rest of the world combined.
51. 10% of the world's population is left-handed.

Originally created by @RonHein on GitHub (Jan 24, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2173 Hi, I am having trouble using OllamaEmbedding. I am unable to retrieve the correct vectors and the the similarity score is really high. I was able to get the correct vectors with OpenAIEmbedding but I am hoping to get OllamaEmbedding working. Is there something that I am missing? Below is a simple loader with chromadb using OllamaEmbedding. `from langchain.document_loaders import PyPDFLoader, UnstructuredExcelLoader, Docx2TxtLoader, BSHTMLLoader, TextLoader from langchain.embeddings import OllamaEmbeddings from langchain.vectorstores import Chroma from langchain.text_splitter import RecursiveCharacterTextSplitter def chunk(): loader = TextLoader('./samples/facts.txt') text_splitter = RecursiveCharacterTextSplitter( chunk_size=128 chunk_overlap = 20 ) docs = loader.load_and_split( text_splitter=text_splitter ) return docs def create_embedding(): docs = chunk() embeddings = OllamaEmbeddings() db = Chroma.from_documents( docs, embedding=embeddings, persist_directory="./samples/docs/chroma", ) results = db.similarity_search_with_score("What is an interesting fact about the English language?") print("~~~~similarity_search_with_score~~~~" for result in results: print("\n") print(result[1]) print(result[0].page_content) ` This is the output: 8292.622553378074 16. Queen Elizabeth II is the longest-reigning current monarch. 17. The Leaning Tower of Pisa took 200 years to construct. 8386.487814338176 6. The elephant is the only mammal that can't jump. 7. The letter 'Q' is the only letter not appearing in any U.S. state name. 8529.430614665867 34. The shortest war in history was between Britain and Zanzibar on August 27, 1896. Zanzibar surrendered after 38 minutes. 8711.880867153133 50. Canada has more lakes than the rest of the world combined. 51. 10% of the world's population is left-handed.
Author
Owner

@fbcorrea commented on GitHub (Feb 13, 2024):

@RonHein any updates?
I am having the same issue.

<!-- gh-comment-id:1941266610 --> @fbcorrea commented on GitHub (Feb 13, 2024): @RonHein any updates? I am having the same issue.
Author
Owner

@mxyng commented on GitHub (Mar 11, 2024):

This seems like an issue for LangChain since that's the main interface here. Ollama is only providing the embeddings API

<!-- gh-comment-id:1989219761 --> @mxyng commented on GitHub (Mar 11, 2024): This seems like an issue for LangChain since that's the main interface here. Ollama is only providing the embeddings API
Author
Owner

@jmorganca commented on GitHub (May 10, 2024):

Thanks for the issue @RonHein. This should be far more improved now with embedding models such as https://ollama.com/library/nomic-embed-text

<!-- gh-comment-id:2105381363 --> @jmorganca commented on GitHub (May 10, 2024): Thanks for the issue @RonHein. This should be far more improved now with embedding models such as https://ollama.com/library/nomic-embed-text
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#47756