[GH-ISSUE #10489] Embeddings examples not working properly (ollama.com/blog/embedding-models) #53411

Closed
opened 2026-04-29 03:02:06 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @vntzero on GitHub (Apr 29, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/10489

What is the issue?

Hey all, gm.
The example code provided on the website (https://ollama.com/blog/embedding-models) is not executing properly on a Mac/Apple Silicon.

Here is the corrected code (I've commented what is currently on the website and it was causing problems). Problems were some wrong variable attribution and type mismatch errors when using response['embeddings'] instead of response.embeddings

import ollama
import chromadb

documents = [
  "Llamas are members of the camelid family meaning they're pretty closely related to vicuñas and camels",
  "Llamas were first domesticated and used as pack animals 4,000 to 5,000 years ago in the Peruvian highlands",
  "Llamas can grow as much as 6 feet tall though the average llama between 5 feet 6 inches and 5 feet 9 inches tall",
  "Llamas weigh between 280 and 450 pounds and can carry 25 to 30 percent of their body weight",
  "Llamas are vegetarians and have very efficient digestive systems",
  "Llamas live to be about 20 years old, though some only live for 15 years and others live to be 30 years old",
]

client = chromadb.Client()
collection = client.create_collection(name="docs")

# store each document in a vector embedding database
for i, d in enumerate(documents):
  response = ollama.embed(model="mxbai-embed-large", input=d)
  #embeddings = response['embeddings']
  embeddings = response.embeddings
  collection.add(
    ids=[str(i)],
    embeddings=embeddings,
    documents=[d]
  )

print("Done embeddings -> DB")
# an example input
# input = "What animals are llamas related to?"
prompt = "What animals are llamas related to?"

# generate an embedding for the input and retrieve the most relevant doc
response = ollama.embed(
  model="mxbai-embed-large",
  input=prompt
)
results = collection.query(
  #   query_embeddings=[response["embeddings"]],
  query_embeddings=response.embeddings,
  n_results=1
)

data = results['documents'][0][0]

output = ollama.generate(
  model="llama3.2:latest",
  # prompt=f"Using this data: {data}. Respond to this prompt: {input}"
  prompt=f"Using this data: {data}. Respond to this prompt: {prompt}"
)

print(output['response'])

Relevant log output

(env) dalmoverasneto@DALMOs-MacBook-Pro searchv3 % python example.py
Traceback (most recent call last):
  File "/Users/dalmoverasneto/Documents/RAG/searchv3/example.py", line 32, in <module>
    input=prompt
          ^^^^^^
NameError: name 'prompt' is not defined


============Type Mismatch (after fixing the var above)

(env) dalmoverasneto@DALMOs-MacBook-Pro searchv3 % python example.py
Traceback (most recent call last):
  File "/Users/dalmoverasneto/Documents/RAG/searchv3/example.py", line 34, in <module>
    results = collection.query(
      query_embeddings=[response["embeddings"]],
      n_results=1
    )
  File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/models/Collection.py", line 207, in query
    query_request = self._validate_and_prepare_query_request(
        query_embeddings=query_embeddings,
    ...<6 lines>...
        include=include,
    )
  File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/models/CollectionCommon.py", line 95, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/models/CollectionCommon.py", line 303, in _validate_and_prepare_query_request
    query_records = normalize_base_record_set(
        embeddings=query_embeddings,
    ...<2 lines>...
        uris=query_uris,
    )
  File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/types.py", line 184, in normalize_base_record_set
    embeddings=normalize_embeddings(embeddings),
               ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/types.py", line 108, in normalize_embeddings
    raise ValueError(
        f"Expected embeddings to be a list of floats or ints, a list of lists, a numpy array, or a list of numpy arrays, got {target}"
    )
ValueError: Expected embeddings to be a list of floats or ints, a list of lists, a numpy array, or a list of numpy arrays, got [[[0.017878633, 0.06340349, ...

OS

macOS

GPU

No response

CPU

Apple

Ollama version

0.6.6

Originally created by @vntzero on GitHub (Apr 29, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/10489 ### What is the issue? Hey all, gm. The example code provided on the website (https://ollama.com/blog/embedding-models) is not executing properly on a Mac/Apple Silicon. Here is the corrected code (I've commented what is currently on the website and it was causing problems). Problems were some wrong variable attribution and type mismatch errors when using `response['embeddings']` instead of `response.embeddings` ```python import ollama import chromadb documents = [ "Llamas are members of the camelid family meaning they're pretty closely related to vicuñas and camels", "Llamas were first domesticated and used as pack animals 4,000 to 5,000 years ago in the Peruvian highlands", "Llamas can grow as much as 6 feet tall though the average llama between 5 feet 6 inches and 5 feet 9 inches tall", "Llamas weigh between 280 and 450 pounds and can carry 25 to 30 percent of their body weight", "Llamas are vegetarians and have very efficient digestive systems", "Llamas live to be about 20 years old, though some only live for 15 years and others live to be 30 years old", ] client = chromadb.Client() collection = client.create_collection(name="docs") # store each document in a vector embedding database for i, d in enumerate(documents): response = ollama.embed(model="mxbai-embed-large", input=d) #embeddings = response['embeddings'] embeddings = response.embeddings collection.add( ids=[str(i)], embeddings=embeddings, documents=[d] ) print("Done embeddings -> DB") # an example input # input = "What animals are llamas related to?" prompt = "What animals are llamas related to?" # generate an embedding for the input and retrieve the most relevant doc response = ollama.embed( model="mxbai-embed-large", input=prompt ) results = collection.query( # query_embeddings=[response["embeddings"]], query_embeddings=response.embeddings, n_results=1 ) data = results['documents'][0][0] output = ollama.generate( model="llama3.2:latest", # prompt=f"Using this data: {data}. Respond to this prompt: {input}" prompt=f"Using this data: {data}. Respond to this prompt: {prompt}" ) print(output['response']) ``` ### Relevant log output ```shell (env) dalmoverasneto@DALMOs-MacBook-Pro searchv3 % python example.py Traceback (most recent call last): File "/Users/dalmoverasneto/Documents/RAG/searchv3/example.py", line 32, in <module> input=prompt ^^^^^^ NameError: name 'prompt' is not defined ============Type Mismatch (after fixing the var above) (env) dalmoverasneto@DALMOs-MacBook-Pro searchv3 % python example.py Traceback (most recent call last): File "/Users/dalmoverasneto/Documents/RAG/searchv3/example.py", line 34, in <module> results = collection.query( query_embeddings=[response["embeddings"]], n_results=1 ) File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/models/Collection.py", line 207, in query query_request = self._validate_and_prepare_query_request( query_embeddings=query_embeddings, ...<6 lines>... include=include, ) File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/models/CollectionCommon.py", line 95, in wrapper return func(self, *args, **kwargs) File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/models/CollectionCommon.py", line 303, in _validate_and_prepare_query_request query_records = normalize_base_record_set( embeddings=query_embeddings, ...<2 lines>... uris=query_uris, ) File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/types.py", line 184, in normalize_base_record_set embeddings=normalize_embeddings(embeddings), ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/Users/dalmoverasneto/Documents/RAG/searchv3/env/lib/python3.13/site-packages/chromadb/api/types.py", line 108, in normalize_embeddings raise ValueError( f"Expected embeddings to be a list of floats or ints, a list of lists, a numpy array, or a list of numpy arrays, got {target}" ) ValueError: Expected embeddings to be a list of floats or ints, a list of lists, a numpy array, or a list of numpy arrays, got [[[0.017878633, 0.06340349, ... ``` ### OS macOS ### GPU _No response_ ### CPU Apple ### Ollama version 0.6.6
GiteaMirror added the bugollama.com labels 2026-04-29 03:02:06 -05:00
Author
Owner

@rick-github commented on GitHub (Apr 29, 2025):

The script works fine for me.

$ python3 10489.py
Done embeddings -> DB
Based on the information provided, it appears that llamas are closely related to:

1. Vicuñas
2. Camels (as part of the camelid family)

This indicates a strong familial connection among these three species within the camelid family.

What version of ollama and chromadb do you have installed?

$ pip show ollama chromadb
Name: ollama
Version: 0.4.7
Summary: The official Python client for Ollama.
Home-page: 
Author: Ollama
Author-email: hello@ollama.com
License: MIT
Location: /home/rick/miniconda3/lib/python3.12/site-packages
Requires: httpx, pydantic
Required-by: langchain-ollama, oterm
---
Name: chromadb
Version: 0.5.5
Summary: Chroma.
Home-page: 
Author: 
Author-email: Jeff Huber <jeff@trychroma.com>, Anton Troynikov <anton@trychroma.com>
License: 
Location: /home/rick/miniconda3/lib/python3.12/site-packages
Requires: bcrypt, build, chroma-hnswlib, fastapi, grpcio, httpx, importlib-resources, kubernetes, mmh3, numpy, onnxruntime, opentelemetry-api, opentelemetry-exporter-otlp-proto-grpc, opentelemetry-instrumentation-fastapi, opentelemetry-sdk, orjson, overrides, posthog, pydantic, pypika, PyYAML, tenacity, tokenizers, tqdm, typer, typing-extensions, uvicorn
Required-by: 

<!-- gh-comment-id:2840445051 --> @rick-github commented on GitHub (Apr 29, 2025): The script works fine for me. ```console $ python3 10489.py Done embeddings -> DB Based on the information provided, it appears that llamas are closely related to: 1. Vicuñas 2. Camels (as part of the camelid family) This indicates a strong familial connection among these three species within the camelid family. ``` What version of `ollama` and `chromadb` do you have installed? ```console $ pip show ollama chromadb Name: ollama Version: 0.4.7 Summary: The official Python client for Ollama. Home-page: Author: Ollama Author-email: hello@ollama.com License: MIT Location: /home/rick/miniconda3/lib/python3.12/site-packages Requires: httpx, pydantic Required-by: langchain-ollama, oterm --- Name: chromadb Version: 0.5.5 Summary: Chroma. Home-page: Author: Author-email: Jeff Huber <jeff@trychroma.com>, Anton Troynikov <anton@trychroma.com> License: Location: /home/rick/miniconda3/lib/python3.12/site-packages Requires: bcrypt, build, chroma-hnswlib, fastapi, grpcio, httpx, importlib-resources, kubernetes, mmh3, numpy, onnxruntime, opentelemetry-api, opentelemetry-exporter-otlp-proto-grpc, opentelemetry-instrumentation-fastapi, opentelemetry-sdk, orjson, overrides, posthog, pydantic, pypika, PyYAML, tenacity, tokenizers, tqdm, typer, typing-extensions, uvicorn Required-by: ```
Author
Owner

@jmorganca commented on GitHub (Apr 30, 2025):

Hi @vntzero it seems like prompt may not be defined in your original script. If you're still having trouble let us know (and thanks @rick-github!)

<!-- gh-comment-id:2840497752 --> @jmorganca commented on GitHub (Apr 30, 2025): Hi @vntzero it seems like `prompt` may not be defined in your original script. If you're still having trouble let us know (and thanks @rick-github!)
Author
Owner

@rick-github commented on GitHub (Apr 30, 2025):

@jmorganca Note that Step 2: Retrieve in the blog post is actually wrong: it defines input but uses prompt:

# an example input
input = "What animals are llamas related to?"

# generate an embedding for the input and retrieve the most relevant doc
response = ollama.embed(
  model="mxbai-embed-large",
  input=prompt
)
results = collection.query(
  query_embeddings=[response["embeddings"]],
  n_results=1
)
data = results['documents'][0][0]
<!-- gh-comment-id:2840502416 --> @rick-github commented on GitHub (Apr 30, 2025): @jmorganca Note that `Step 2: Retrieve` in the blog post is actually wrong: it defines `input` but uses `prompt`: ```python # an example input input = "What animals are llamas related to?" # generate an embedding for the input and retrieve the most relevant doc response = ollama.embed( model="mxbai-embed-large", input=prompt ) results = collection.query( query_embeddings=[response["embeddings"]], n_results=1 ) data = results['documents'][0][0] ```
Author
Owner

@rmoff commented on GitHub (Sep 12, 2025):

This caught me out too - can we update the blog post?

<!-- gh-comment-id:3284850327 --> @rmoff commented on GitHub (Sep 12, 2025): This caught me out too - can we update the blog post?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#53411