See Ash Code logo See Ash Code

Adding local embeddings changed more than the API endpoint

Ashlynn Antrobus
• • 3 min read

I added an Ollama embedding initializer to rag-mcp, my tool for ingesting and searching documents, in December. It takes a model name and a base URL, which makes the change sound like choosing a different endpoint.

The merged implementation also changes settings, dependencies, and chunking. Those parts need to agree before the rest of the ingestion pipeline can treat the result as an embedding service.

The local initializer

The Ollama path builds its client from the selected settings:

return OllamaEmbeddings(
    model=settings.OLLAMA_MODEL, base_url=settings.OLLAMA_HOST
)

The recorded defaults are http://localhost:11434 and mxbai-embed-large.

The Google initializer keeps the hosted client’s token counter and rate-limiting wrapper. The Ollama initializer returns its client directly. It doesn’t route local work through the Google quota calculation I described in the rate-limit post.

The selected engine is an explicit configuration choice. The program has Google and Ollama enum values and dispatches to the corresponding initializer. It isn’t measuring the two services and automatically selecting the faster one.

The model changes the ingestion setup

The refactor exposes chunk size and overlap as constructor inputs to the RAG object. Provider-specific settings supply defaults: 2000 for the Google chunk size and 500 for Ollama, with a shared overlap setting of 50.

Those chunk sizes configure the text splitter. They aren’t promises about token counts, and they aren’t benchmark results. Changing them changes which text pieces get embedded, so retrieval comparisons would need to account for that change as well as the embedding model.

I also need to keep indexed document vectors and query vectors compatible. Changing an endpoint while continuing to query vectors produced by another model isn’t enough to establish a usable index. A model switch needs an explicit decision about the existing stored embeddings.

A conceptual word embedding diagram shows arrows from France to Paris and Germany to Berlin.

Word embedding illustration by Fschwarzentruber, CC BY-SA 4.0; unmodified. This is a conceptual example, not a plot of my document vectors.

Optional dependencies need an import check

The package metadata now separates the clients into extras:

[project.optional-dependencies]
google = [
    "langchain-google-genai>=4.1.1",
]
ollama = [
    "langchain-ollama>=1.0.1",
]

The initializer dispatcher delays its provider imports until the selected initializer runs. That helps keep the choice local.

But the shared embeddings.py module still imports the Google embedding class at the top level in this snapshot. Declaring an optional extra doesn’t make every import of that package optional. A clean installation with just the local extra is an important check; my development environment may already contain both clients.

What the change doesn’t measure

The implementation adds the local path. It doesn’t provide a timing comparison, retrieval-quality evaluation, or a measurement of how much memory the local model needs on my machine.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.