Mac tip: search your notes by meaning with Ollama embeddings

MacBook Pro with M5 running a local coding model in LM Studio next to a Safari dashboard

Spotlight finds a note by the words in it. It does not find the note that says the same thing in other words. An embedding model does. It turns each text into a list of numbers, and texts with close meaning get close numbers. Ollama runs one on the Mac, on localhost, so the notes are not sent to a cloud service.

This tip assumes Ollama is already installed on an Apple silicon Mac. If not, start with our Ollama setup guide for Apple silicon.

Pull embeddinggemma and test it in Terminal

Ollama's Embeddings page uses embeddinggemma in every example. On the embeddinggemma library page it is listed as a 300M parameter model from Google, 622MB, 2K context, text input. It was trained on data in 100+ spoken languages. So Chinese or Japanese notes are fine too.

ollama pull embeddinggemma
ollama run embeddinggemma "Hello world"

The second line does not chat. It prints a JSON array of numbers. That array is the embedding. Piping text in with echo works the same way.

Batch a folder of notes with /api/embed

For more than one text, the /api/embed reference takes an array in input. One request, one vector back per string. Install the Python library first with pip3 install ollama, ideally inside a venv. Then save this as index.py. It reads every .txt file in a folder called Notes-export in your home folder and writes the vectors to index.json.

import json, pathlib, ollama

files = sorted((pathlib.Path.home() / "Notes-export").glob("*.txt"))
texts = [f.read_text() for f in files]
res = ollama.embed(model="embeddinggemma", input=texts)
index = [{"file": str(f), "vec": v} for f, v in zip(files, res["embeddings"])]
pathlib.Path("index.json").write_text(json.dumps(index))
print(len(index), "notes indexed")

The folder name is only an example. Point it at any folder of plain text or Markdown.

MacBook Pro with M5 showing Apple Intelligence Writing Tools over a Mail draft
Photo: Apple (MacBook Pro with M5, Writing Tools on screen)

Search by meaning with a dot product

The docs note that /api/embed returns L2-normalized, unit-length vectors. For unit vectors the dot product equals cosine similarity, which is what the docs suggest for most semantic search. No vector database is needed for a few hundred notes. Save this as search.py:

import json, sys, pathlib, ollama

index = json.loads(pathlib.Path("index.json").read_text())
q = ollama.embed(model="embeddinggemma", input=sys.argv[1])["embeddings"][0]
score = lambda v: sum(a * b for a, b in zip(q, v))
for item in sorted(index, key=lambda i: score(i["vec"]), reverse=True)[:5]:
    print(round(score(item["vec"]), 3), item["file"])

Run python3 search.py "router password for the office". The top five files print with a score, highest first. Higher means closer in meaning.

One rule from the docs. Use the same embedding model for indexing and for querying. If you switch models later, run index.py again.

2K context, truncate and dimensions

embeddinggemma reads 2K tokens per input. In the API, truncate is true by default. A long note gets cut to fit, with no error. Only the start of it is searchable. Set truncate to false and Ollama returns an error instead. The practical fix is to split long notes into paragraphs and embed each one.

The API also has a dimensions field. The reference example asks embeddinggemma for 128. Shorter vectors make a smaller index.json. Again, index and query need the same setting.

Privacy check. All of this talks to localhost:11434. If you also want Ollama cloud models switched off, follow our note on keeping Ollama prompts on the Mac. For getting clean JSON out of a chat model instead, see Ollama structured outputs.

Photo: Apple (MacBook Pro with M5)
Source: Ollama docs (Embeddings, /api/embed reference); Ollama library (embeddinggemma); Apple Newsroom (M5, October 15, 2025)

Previous Article iPhone fix: SOS, No Service or Searching in the status bar